<?php

namespace App\Mail;

use App\Models\Pegawai;
use Illuminate\Mail\Mailable;
use Illuminate\Support\Facades\URL;

class PendataanPegawaiSubmitted extends Mailable
{
    public function __construct(
        public Pegawai $pegawai,
        public string $mode = 'submitted',
        public ?array $loginAccount = null,
    )
    {
        $this->pegawai->loadMissing('jabatan');
    }

    public function build(): self
    {
        $subject = $this->loginAccount
            ? 'Akun Login Pegawai'
            : ($this->mode === 'status_updated'
                ? 'Update Status Pendataan Pegawai'
                : 'Konfirmasi Pendataan Pegawai');

        $correctionUrl = null;

        if ($this->pegawai->status_validasi === 'ditolak') {
            $correctionUrl = URL::temporarySignedRoute(
                'pegawai.correction.edit',
                now()->addDays(7),
                ['pegawai' => $this->pegawai->id]
            );
        }

        return $this->subject($subject)
            ->view('emails.pendataan-submitted')
            ->with([
                'correctionUrl' => $correctionUrl,
                'loginAccount' => $this->loginAccount,
            ]);
    }
}
