<?php
function generateLOIContent($data)
{
    list(
        $loi_reference_id,
        $doj,
        $name,
        $job_name,
        $ctc,
        $trial_period,
        $trial_pay_per_month,
        $company_name,
        $parent_company_name
    ) = $data;
    $dojFormatted = date('j F, Y', strtotime($doj));
    $currDate = date('j F, Y');
    $trial_period_note = '';
    if ($trial_period != '' && $trial_pay_per_month != '') {
        $trial_period_note = "<tr>
                                <td colspan='2' style='font-size: 13px; padding: 8px 0 0 0; color: #b85c00;'>
                                    <em style='font-weight: bold;'>Please note that the initial $trial_period-day trial period will be compensated at a rate equivalent to $trial_pay_per_month per month, calculated on a per-day basis. The trial period will not include any holidays or leaves.</em>
                                </td>
                            </tr>";
    }
    $ctcAmount = '';
    if (!empty($ctc['internship_amount']) && is_array($ctc['internship_amount'])) {
        if (count(array_unique($ctc['internship_amount'])) === 1) {
            $ctcAmount = $ctc['internship_amount'][0] . " per month";
        } else {
            $ctcAmount = '₹'.implode(', ₹', $ctc['internship_amount']) . " respectively";
        }
    }
    $content = "<table cellspacing='0' cellpadding='0' border='0' width='600' style='background-color: #ffffff; border: 1px solid #e9ecef; font-family: Arial, sans-serif; margin: 0 auto;'>
    
    <!-- Header Section -->
    <tr>
        <td style='background-color: #1a365d; padding: 40px 20px; text-align: center; color: #ffffff;'>
            <img src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj_white_logo.png' alt='Jobaaj Learnings Logo' style='width: 80px; margin-bottom: 25px;' />
            <p style='font-size: 26px; font-weight: 600; margin: 0; color: #ffffff;'>LETTER OF INTENT</p>
            <p style='font-size: 16px; margin: 8px 0 0 0; color: #ffffff;'>$job_name Position</p>
        </td>
    </tr>

    <!-- Date and Reference -->
    <tr>
        <td style='padding: 25px 20px; border-bottom: 1px solid #e9ecef;'>
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='width: 50%; vertical-align: top;'>
                        <p style='font-size: 14px; margin: 0; color: #495057;'>
                            <strong>Date:</strong> $currDate<br />
                            <strong>Reference:</strong> $loi_reference_id
                        </p>
                    </td>
                    <td style='width: 50%; text-align: right; vertical-align: top;'>
                        <p style='font-size: 14px; margin: 0; color: #495057;'>
                            <strong>$company_name</strong><br />
                            Human Resources Department
                        </p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    <!-- Greeting -->
    <tr>
        <td style='padding: 30px 20px;'>
            <p style='font-size: 18px; font-weight: 600; margin: 0 0 20px 0; color: #212529;'>Dear $name,</p>
            <p style='font-size: 15px; line-height: 1.7; margin: 0 0 20px 0; color: #495057;'>
                We are pleased to extend this formal Letter of Intent for the position of <strong>$job_name</strong> at <strong>$company_name</strong> ($parent_company_name). Following our comprehensive evaluation process, we are confident that your qualifications and professional attributes align excellently with our organizational requirements.
            </p>
            <p style='font-size: 15px; line-height: 1.7; margin: 0; color: #495057;'>
                This Letter of Intent outlines the terms and conditions of your proposed internship engagement with our organization.
            </p>
        </td>
    </tr>

    <!-- Content Sections -->
    <tr>
        <td style='padding: 0 20px;'>
            
            <!-- Section 1 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>1. COMMENCEMENT DATE</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            Your internship engagement is scheduled to commence on <strong>$dojFormatted</strong>. We kindly request your confirmation of availability for the aforementioned commencement date. Any scheduling conflicts should be communicated to the Human Resources Department immediately.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 2 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>2. BACKGROUND VERIFICATION</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            All requisite reference checks and background verification procedures have been successfully completed. Your academic credentials, professional references, and personal background have been thoroughly reviewed and found to be in complete accordance with our organizational standards and requirements.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 3 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>3. WORK ARRANGEMENT</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            This internship position requires working from our corporate office facilities. Specific operational guidelines, reporting protocols, and workspace allocation details will be communicated during the formal onboarding process.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 4 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>4. COMPENSATION STRUCTURE</p>
                        <table cellspacing='0' cellpadding='0' border='0' width='100%' style='margin-top: 10px;'>
                            <tr>
                                <td style='font-size: 14px; padding: 3px 0; color: #495057;'>Internship Stipend:</td>
                                <td style='font-size: 14px; padding: 3px 3px; font-weight: 600; color: #495057;'> $ctcAmount</td>
                            </tr>
                            <tr>
                                <td style='font-size: 14px; padding: 3px 0; color: #495057;'>Internship Period:</td>
                                <td style='font-size: 14px; padding: 3px 3px; font-weight: 600; color: #495057;'> $ctc[internship_period] months</td>
                            </tr>
                            <tr>
                                <td style='font-size: 14px; padding: 3px 0; color: #495057;'>Performance Incentives:</td>
                                <td style='font-size: 14px; padding: 3px 3px; color: #495057;'> Merit-based, subject to team policies</td>
                            </tr>
                            $trial_period_note
                        </table>
                    </td>
                </tr>
            </table>

            <!-- Section 5 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>5. NOTICE PERIOD REQUIREMENTS</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            This internship is offered on an at-will basis. Either party may terminate the internship at any time without the requirement of a notice period. However, we encourage providing reasonable prior notice to the Human Resources Department to ensure a smooth transition.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 6 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>6. COMPANY PROPERTY AND ASSETS</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            All company assets, proprietary documents, confidential materials, equipment, and intellectual property must be returned in their original condition upon completion or termination of the internship engagement. Failure to comply may result in appropriate legal action and financial liability.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 7 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0; border-bottom: 1px solid #dee2e6;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>7. WORKING HOURS AND SCHEDULE</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            Standard operational hours are <strong>9:30 AM to 6:30 PM, Monday through Saturday</strong>, excluding public holidays and company-designated non-working days. Flexible scheduling arrangements may be considered based on project requirements and supervisor approval, subject to organizational policies and operational needs.
                        </p>
                    </td>
                </tr>
            </table>

            <!-- Section 8 -->
            <table cellspacing='0' cellpadding='0' border='0' width='100%'>
                <tr>
                    <td style='padding: 20px 0;'>
                        <p style='font-size: 16px; font-weight: 600; margin: 0 0 12px 0; color: #1a365d;'>8. EMPLOYMENT EXCLUSIVITY AND CONFIDENTIALITY</p>
                        <p style='font-size: 14px; line-height: 1.6; margin: 0; color: #495057;'>
                            During your tenure with $company_name, you are required to maintain complete professional exclusivity. Engagement in any conflicting employment, business activities, or professional commitments that may compromise your obligations to the organization is strictly prohibited. All confidential information must be handled and protected in accordance with company policies.
                        </p>
                    </td>
                </tr>
            </table>

        </td>
    </tr>

    <!-- Acceptance Section -->
    <tr>
        <td style='padding: 30px 20px; background-color: #f8f9fa; border-top: 2px solid #1a365d; text-align: center;'>
            <p style='font-size: 15px; margin: 0 0 25px 0; font-weight: 500; color: #495057;'>
                Please confirm your formal acceptance of this Letter of Intent by responding through the designated communication channel below:
            </p>
            
            <table cellspacing='0' cellpadding='0' border='0' style='margin: 0 auto;'>
                <tr>
                    <td style='background-color: #1a365d; padding: 16px 35px;'>
                        <a href='https://www.jobaaj.com/loi_acceptance/" . base64_encode($loi_reference_id) . "' 
                           target='_blank'
                        style='color: #ffffff; text-decoration: none; font-size: 15px; font-weight: 600;'>
                            CONFIRM ACCEPTANCE
                        </a>
                    </td>
                </tr>
            </table>
            
            <p style='font-size: 13px; margin: 25px 0 0 0; color: #6c757d;'>
                Alternative contact: <a href='mailto:hr@nishtya.com' style='color: #1a365d;'>hr@jobaaj.com</a>
            </p>
        </td>
    </tr>

    <!-- Footer -->
    <tr>
        <td style='background-color: #212529; padding: 35px 20px; text-align: center;'>
            <p style='font-size: 16px; font-weight: 600; margin: 0 0 15px 0; color: #ffffff;'>HUMAN RESOURCES DEPARTMENT</p>
            <p style='font-size: 14px; margin: 0 0 15px 0; color: #adb5bd;'>
                <strong style='color: #ffffff;'>$company_name</strong><br />
                ($parent_company_name)<br />
            </p>
            <p style='font-size: 12px; margin: 0; color: #868e96; border-top: 1px solid #495057; padding-top: 15px;'>
                Corporate Website: <a href='https://jobaaj.com' style='color: #74c0fc;'>www.jobaaj.com</a><br />
                This communication is confidential and intended solely for the addressee.
            </p>
        </td>
    </tr>

</table>";
    return $content;
}
