<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailables\Attachment;

use Illuminate\Support\Facades\File; 
use Carbon\Carbon;
use PDF;

class JP_confirmationMail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
        
    }

    /**
     * Get the message envelope.
     *
     * @return \Illuminate\Mail\Mailables\Envelope
     */

    public function build()
    {

        $medical_date = date("l, F d, Y", strtotime($this->data['sched_date']));
        $medical_time = $this->data['sched_time'];
        $medical_branch = $this->data['branch'];

        $medical_date_reschedule = date('F d, Y', strtotime($this->data['sched_date']. ' - 2 day'));

        $PayCode = $this->data['paycode'];
        $applicant_name = strtoupper($this->data['name']);

        $path = public_path('/img/slec-email-logo.png');
        $type = pathinfo($path, PATHINFO_EXTENSION);
        $data = file_get_contents($path);
        $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

        $html ="
                <html>
                <head>
                    <title>$PayCode</title>
                </head>
                <style>
                    @import url(\'https://fonts.googleapis.com/css?family=Consolas\');
                    @font-face {
                        font-family: C39T36L;
                        src: url(https://slec.ph/font/C39T36L.woff);
                    }
                    @font-face {
                        font-family: consola;
                        src: url(https://slec.ph/font/consola.ttf);
                    }
                    body {
                        padding: 0;
                        margin: 0;
                    }
                    p {
                        font-size: 11pt
                    }
                    li {
                        font-size: 11pt
                    }
                </style>
                <body>";
            $html .= "   
                    <table align='center' border='0' width='100%'>
                        <tr><td><center><img src='$base64'/></center><br></td></tr>
                        <tr>
                            <td align='center'><span style='font-size: 8pt; font-family: Arial, Verdana;'> 1177 JORGE BOCOBO ST. ERMITA, MANILA 1000 &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;(02) 8521-0020&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;https://slec.ph<hr/></td>
                        </tr>
                        <tr>
                    </table>
                    <table  border='0'>
                    <tr>
                        <td align='center' class=''>
                        <h1 style='font-family: Arial, Sans Serif; margin: 0;'>$medical_date</h1>
                        <h2 style='margin: 5px 0px 20px;'>
                            <u style='font-family:Arial, Sans Serif;'>Time: $medical_time</u>
                        </h2>
                        </td>
                    </tr>
                    <tr>
                        <td align='center' style='padding:0; margin:0;'>
                        <p style='font-family: consola; font-size: 25pt; padding:0; margin:0;'>$PayCode</p>
                        <p style='font-family: C39T36L; font-size: 70pt; padding:0; margin:0;'>*$PayCode*</p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p style='font-size: 14px'>Dear Maam/Sir:</p>
                    
                            <p style='font-size: 14px'>
                                This confirms the Japan Pre-entry TB Screening (JPETS) appointment of visa applicant
                                <strong> $applicant_name </strong> at St. Luke's Medical Center Extension Clinic
                                (SLEC) - <strong>$medical_branch</strong>, on <strong>$medical_date</strong> at
                                <strong> $medical_time </strong>. 
                                Please be at the clinic at least 30 minutes before your scheduled appointment.
                            </p>
                            <p style='font-size: 14px'>
                                SLEC strictly observes the schedule for the screening. 
                                <strong>Visa applicants who arrive on time shall be given priority over those who arrive late and miss their appointment.</strong>
                            </p>

                            <p>Inclement weather conditions or local holidays may affect clinic schedules. <strong>Visit our website regularly for important announcements.</strong></p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p style='font-size: 14px; text-align:center;'><b><u>IMPORTANT REMINDERS:</u></b></p>

                            <p>Prepare the following required documents inside a short brown envelope in this exact order:</p>

                            <ul>
                                <li>JPETS Confirmation Email from SLEC (printed or digital copy)</li>
                                <li>Passport (must be valid for at least 6 months) – original and one (1) photocopy of the biographic data page (actual size)</li>
                                <li>Request for JPETS <strong>(if available)</strong></li>
                                <li>Chest x-ray films/images older than 3 months for comparison <strong>(if available)</strong></li>
                                <li>Certificates or records of previous TB treatment <strong>(if available)</strong></li>
                            </ul>
                        </td>
                    </tr>
                    <tr>
                    <td>
                        <p>Minors (i.e., ages 17 years and below) who will not be accompanied by their parents during the medical examination must also present the following:</p>
                        <ul>
                            <li>Letter of Authorization stating that the companion is authorized to sign on behalf of the parent (companion must be knowledgeable of the minor's medical history)</li>
                            <li>Copy of parent's valid government signature bearing ID - one (1) photocopy</li>
                            <li>Authorized companion's valid government signature bearing ID – original and one (1) photocopy</li>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p>Only visa applicants will be allowed to enter clinic premises. Only one (1) companion will be allowed in the case of
                        senior citizens, PWDs, or minors (i.e., ages 17 years and below), provided that the minor is not accompanied by an
                        adult visa applicant. Agents are strictly not allowed inside the clinic premises.</p>

                        <p>Wearing of facemasks is recommended inside the clinic premises but is not a requirement.</p>

                        <p>Applicants who wear contact lenses should bring their container and soaking liquid in case they are asked to remove
                        the lenses during the screening.</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <strong style='font-size: 16px'><u>RESCHEDULING</u></strong>
                        <p>You may reschedule your appointment for JPETS not later than <strong>$medical_date_reschedule</strong> by visiting on <strong>https://account.slec.ph/</strong>. 
                        Rescheduling is subject to availability, and may affect the medical fee in case your age changes.  Any difference in amount shall be settled at the Clinic 
                        on the day of your screening..</p>
                    </td>
                </tr>
                <tr>
                    <td><hr /></td>
                </tr>
                <tr>		
				    <td><center><h3>Clinic Contact Details</h3></center></td>
				</tr>
		        <tr>
		            <td>
			            <table border='0' cellpadding='0' cellspacing='0' width='100%' align='center'>
				            <tr>
				                    <td colspan='2' valign='top' align='center'>
				 	                    <table align='left' border='0' cellpadding='10' cellspacing='0' width='95%'>
					                        <tr>
                                                <td valign='top' align='center' style='font-size: 10pt; font-family: Arial, Tahoma;' >
                                                    <strong>ST. LUKE'S MEDICAL CENTER EXTENSION CLINIC - MANILA</strong>
                                                    <br />
                                                    1177 Jorge Bocobo St.,<br /> Ermita, Manila<br />
                                					<br />
                                					Telephone Numbers:<br />
                                					(02) 8521-0020<br />
                                					<br />
                                					<br />Clinic Schedule:<br />
                                					<strong>Mondays to Fridays from 7:00AM to 4:30PM</strong>
                                                </td>
                                            </tr>
                                        </table>
			                        </td>
			                    </tr>
		                    </table>
		                </td>
		            </tr>
		            <tr>
				        <td colspan='4' valign='top'>
        				   <p align='center'><strong>We are closed on declared Philippine holidays.</strong></p>
        				   <p align='center'><strong>For more information on your visa medical exam, please visit</strong> 
        				   <strong><a href='https://www.slec.ph'>https://www.slec.ph</a></strong></p>
				        </td>
		            </tr>
                <tr>
                <td>
                    <hr />
                </td>
                </tr>";

                $html .="
                    <h2>Mode of Payment:</h2>
                    <p>We accept cash payment (in Philippine Peso) at the Clinic's cashier. We also offer the convenience of accepting credit card (Visa and Mastercard) payments onsite.</p>
                    ";
                
                $html .="
                    <div class='col-12 pt-3'>
                    <p style='font-size: 13px; font-style: italic'>
                        Confidentiality Notice: The contents of this email and any attachments are
                        confidential and/or legally privileged and are intended solely for the addressee.
                        If you received this email message in error, please immediately notify the sender
                        by reply email and delete this message and its attachments. Any use, reproduction,
                        or dissemination of this transmission by persons or entities other than the
                        intended recipient is strictly prohibited.
                    </p>
                    </div>
                </body>
                </html>
                ";
                
            $link=resource_path('views/confirmation/attachments/letter/SLEC Online Registration Confirmation - '.$this->data['paycode'].'.pdf');
            $pdf = PDF::loadHTML($html)->setPaper('a4', 'portrait')->save($link);


            $email = $this->view('emails.confirmationMail')
                            ->subject('SLEC Online Registration Confirmation - '.$this->data['paycode'])
                            ->bcc('slmcec2021@gmail.com')
                            ->with(['message' => $this])
                            ->attach(resource_path('views/confirmation/attachments/letter/SLEC Online Registration Confirmation - '.$this->data["paycode"].'.pdf'));
            
            return $email;

    }

    // public function envelope()
    // {

    // }

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    // public function content()
    // {

    // }

    /**
     * Get the attachments for the message.
     *
     * @return array
     */
    // public function attachments($data)
    // {

    // }
}