<?php

namespace App\Mail;

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

class ProjectStarted extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;
    public $data;
    public $subject;
    public $ccRecipients;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
        $this->subject = $data["SUBJECT"];
        $this->ccRecipients = explode(',', $data["CC_EMAIL"]);
        foreach($this->ccRecipients as $index => $ce) {
            $this->ccRecipients[$index] = trim($ce);
        }
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $email = $this->markdown('emails.projectStarted')
            ->subject($this->subject)
            ->with('data', $this->data);

        if (!empty($this->ccRecipients)) {
            $email->cc($this->ccRecipients);
        }
        return $email;
    }
}
