<?php

namespace App\Mail;

use App\Models\VisitorContact;
use App\Models\Website;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ContactMail extends Mailable
{
    use Queueable, SerializesModels;

    public $content;
    public $visitorContact;
    public $website;

    /**
     * Create a new message instance.
     *
     * @param  VisitorContact  $visitorContact
     * @param  Website  $website
     *
     * @return void
     */
    public function __construct(VisitorContact $visitorContact, Website $website)
    {
        $this->visitorContact = $visitorContact;
        $this->website = $website;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $visitor = $this->visitorContact->visitor;
        $subject = $visitor->first_name.' '.$visitor->last_name.' from '.$visitor->company.' has contacted you from the South Pole Website';

        $content = "<p><strong> $visitor->first_name $visitor->last_name from $visitor->company has contacted you from the <a href=\"https://southpole.com\">South Pole Website</a>.";
        $content .= " You can contact $visitor->first_name here: <a href=\"mailto:$visitor->email\">$visitor->email</a></strong></p><p><strong>$visitor->first_name has sent the following message:</strong></p>";
        $content .= "<p>".nl2br($this->visitorContact->message).'</p>';
        $content .= "<p><br><br>-------------<br><br>This is an automatically generated email. If you have any questions please contact <a href=\"mailto:website@southpole.com\">website@southpole.com</a></p>";

        return $this->from(config('mail.addresses.no_reply.email'), 'South Pole Website Contact')
            ->replyTo($visitor->email, $visitor->first_name.' '.$visitor->last_name)
            ->subject($subject)
            ->view('emails.job_application_confirmation', ['content' => $content]);
    }
}
