<?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 OT_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 medical examination 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 visa medical examination. 
                                <strong>Visa applicants who arrive on time shall be given priority over those who arrive late and miss their appointment.</strong>
                            </p>
                            <p>Sudden changes in quarantine restrictions may affect clinic schedules.  Please provide an email address and phone number that is working and accessible to you so we can contact you when needed. <b>Visit our website regularly for important announcements.</b></p>

                            <p>Please print this email and present it with the other required documents at the Reception area on the day of your medical examination.</p>

                            <p>For health and safety reasons, only visa applicants will be allowed to enter clinic premises. Only one 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.</p>
                            <p>Always wear your face mask within clinic premises on the day of your visa medical examination</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 medical exam. </p>
                            <p>Should you have any inquiries, you may send us an email at inquiry@slec.ph.</p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <strong style='font-size: 16px'><u>RESCHEDULING</u></strong>
                            <p>You may reschedule your appointment for visa medical examination not later than <strong>$medical_date_reschedule</strong> by clicking 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 medical examination.</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' 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>
			                        <td colspan='2' valign='top'>
					                    <table align='right' border='0' cellpadding='10' cellspacing='0' width='95%'>
                                            <tr>
                                                <td valign='top' style='font-size: 10pt; font-family: Arial, Tahoma;' >
                                                    <strong>BONIFACIO GLOBAL CITY</strong><br />
												    Room 1002 Medical Arts Bldg<br />
													St. Luke's Medical Center<br />
													Bonifacio Global City, Taguig<br />
													<br />
                                					Telephone Numbers:<br />
                                					(02) 8789-7700 loc 7002, 7003, 7005<br />
                                					<br />Clinic Schedule:<br />
													<strong>Mondays to Fridays from 8:00AM to 2: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>
                    <p>Please be reminded that St. Luke's Extension Clinic does not accept online credit card payments. Payments through Security Bank are also unavailable until further notice.</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)
    // {

    // }
}