<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class EmailNotification extends Mailable
{
     use Queueable, SerializesModels;

    public $subject;
    public $content;
    public $template;
    public $name; // Add name property

    public function __construct($subject, $content, $name, $template)
    {
        $this->subject = $subject;
        $this->content = $content;
        $this->template = $template;
        $this->name = $name;
    }

    public function build()
    {
        $view = 'template'; // Default view file
        
        // Check the template value and set the view file accordingly
        if ($this->template === 'template2') {
            $view = 'template1';
        }

        return $this->subject($this->subject)->view($view)->with([
            'subject' => $this->subject,
            'content' => $this->content,
            'name' => $this->name,
        ]);
    }
}