<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class StatusKegiatanNotification extends Notification
{
    use Queueable;

    protected $kegiatan;

    public function __construct($kegiatan)
    {
        $this->kegiatan = $kegiatan;
    }

  public function via($notifiable)
{
    return ['database'];
}

    public function toDatabase($notifiable)
    {
        return [
            'judul'       => 'Status Kegiatan Diperbarui',
            'pengirim'    => 'Admin Instansi',
            'email'       => 'system@silaporr.app',
            'pesan'       => 'Kegiatan "' . $this->kegiatan->nama_kegiatan . '" sekarang: ' . $this->kegiatan->status,
            'role'        => 'user',
            'status'      => ($this->kegiatan->status == 'Diproses') ? 'proses' : 'selesai',
            'kegiatan_id' => $this->kegiatan->id,
            'url'         => route('kegiatan.index'),
        ];
    }

    public function toMail($notifiable)
    {
        $statusLabel = [
            'terkirim' => '📤 Terkirim',
            'sedang'   => '⚙️ Sedang Diproses',
            'selesai'  => '✅ Selesai',
        ][$this->kegiatan->status] ?? $this->kegiatan->status;

        return (new MailMessage)
            ->subject('🔔 Status Kegiatan Diperbarui - SILAPORR')
            ->greeting('Halo, ' . $notifiable->name . '!')
            ->line('Status laporan kegiatan Anda telah diperbarui.')
            ->line('**Judul:** ' . $this->kegiatan->nama_kegiatan)
            ->line('**Status Terbaru:** ' . $statusLabel)
            ->action('Lihat Status Kegiatan', route('kegiatan.index'))
            ->line('Terima kasih telah menggunakan SILAPORR.')
            ->salutation('Salam, Tim SILAPORR');
    }
}