<?php
require_once '../config.php';
require_once '../../../vendor/autoload.php';

date_default_timezone_set('Asia/Kolkata');

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


function pipMail($data)
{
    list($to, $name, $until) = $data;

    // convert until date to 31st August this formate
    $until = date('dS F', strtotime($until));

    $mail = new PHPMailer(true);
    try {
        $mail->SMTPDebug = 0;
        $mail->isSMTP();

        include __DIR__ . "/../../mail_send_credential.php";

        $mail->addAddress(trim($to));
        // Cc- hr@jobaaj.com, finance@nishtyainfotech.com
        $mail->addCC('hr@jobaaj.com');
        $mail->addCC('finance@nishtyainfotech.com');

        $mail->isHTML(true);
        $mail->Subject = "Notification of Performance Improvement Plan (PIP)- Extended || Jobaaj Group";


        $mail->Body    = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
            <html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>
            
            <head>
                <meta http-equiv='Content-type' content='text/html; charset=utf8' />
                <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1' />
                <meta http-equiv='X-UA-Compatible' content='IE=edge' />
                <meta name='format-detection' content='date=no' />
                <meta name='format-detection' content='address=no' />
                <meta name='format-detection' content='telephone=no' />
                <meta name='x-apple-disable-message-reformatting' />
                <link href='https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700,700i&display=swap' rel='stylesheet' />
                <title>Email Template</title>
            </head>
            <style>
                body{
                    font-family: Arial, Helvetica, sans-serif;
                }
            </style>
            <body style='background:#f3f7f5;'>
                <table width='100%' style='margin-left:auto; margin-right:auto; width:100%; max-width:680px;' align='center' border='0' cellspacing='0' cellpadding='0'>
                    <tr>
                        <td style='margin: 0; padding: 0; width: 100%; height: 100%;' align='center' valign='top'>
                            <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                <tr>
                                    <td>
                                        <!-- Container -->
                                        <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                            <tr>
                                                <td>
                                                    <table width='100%' border='0' cellspacing='0' cellpadding='0'>
                                                    <tr>
                                                        <td style='padding-top:20px; padding-bottom:5px; text-align:center;'>
                                                            <a href='http://employee.nishtyainfotech.com'>
                                                                <img class='logo' src='https://cdn.nishtyainfotech.com/content/jobaaj/assets/svg/logos/jobaaj1.png' width='100'>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style='padding-top:5px; padding-bottom:20px; padding-left:20px; padding-right:20px;'>
                                                            <p>Dear $name,</p>
                                                            <p>I hope you’re doing well.</p>
                                                            <p>I’m writing to confirm the extension of your ongoing Performance Improvement Plan (PIP). This extension aims to support you in fully meeting the expectations of your role by offering clearer goals, actionable feedback, and the resources you may need to succeed.</p>
                                                            <p>Revised PIP timeline: Until $until</p>
                                                            <p>Please feel free to reach out with any questions or concerns in the meantime. We’re committed to working together to help you succeed.</p>
                                                            <p>Best regards,</p>
                                                            <p>HR Team</p>
                                                            <p>Jobaaj Group</p>

                                                        </td>
                                                    </tr>
                                                    

                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                        <!-- END Container -->
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </body>
            
            </html>   
        ";
        $mail->AltBody = 'Body in plain text for non-HTML mail clients';
        // echo $mail->Body;
        if ($mail->send()) {
            return 1;
        } else {
            return 2;
        }
        //echo "Mail has been sent successfully!";
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}
// pipMail(['iqbalshah9368@gmail.com', 'Iqbal Shah', '31st August']);