<?php

namespace Portal\Mileage\Http\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;


class PpjMailer extends Notification implements ShouldQueue
{
    use Queueable;

    protected  $view = 'ecuti::emails.layouts.simple';
    public  $message;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($message , $view = FALSE)
    {

        $this->message = $message;
        $this->view = ($view) ? $view : $this->view;
        
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {

        $mailMessage = new MailMessage;

        if($this->view) $mailMessage->view = $this->view;

        $mailMessage->subject($this->message->get('title', 'Email From ' ));
        // $mailMessage->title($this->message->get('title', 'Email From ' ));
        $mailMessage->level($this->message->get('level'));
        // $mailMessage->greeting('Hi,' . ' ' .$notifiable->name. ', ');

        $content  = $this->message->get('content',[]);
        // dd($content);

        foreach($content as $cont){
            $mailMessage->line($cont);
        }

        $action = $this->message->get('action', FALSE);

        if($action):
        foreach($action as $title => $uri){
            $mailMessage->action($title,$uri);
        }
        endif;


        $footer  = $this->message->get('footer',[]);
        foreach($footer as $foot){
            $mailMessage->line($foot);
        }

        // dd($mailMessage);

        // $mailMessage->cc('portalppjadmin@ppj.gov.my');

        // $mailMessage->bcc('pss3frsb@gmail.com'); // bcc email ke pss3frsb

        return $mailMessage;
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        
    }
}
