<?php

namespace App\Notifications;

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

class KegiatanDikirimNotification extends Notification
{
    use Queueable;

    protected $kegiatan;

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

    public function via($notifiable)
{
    // Aktifkan mail lagi nanti kalau sudah production
    return ['database'];
}

    public function toDatabase($notifiable)
    {
        return [
            'judul'       => 'Laporan Kegiatan Baru',
            'pesan'       => 'Ada laporan kegiatan baru: ' . $this->kegiatan->nama_kegiatan,
            'kegiatan_id' => $this->kegiatan->id,
            'pengirim'    => $this->kegiatan->user->name,
            'url'         => '/kegiatan/' . $this->kegiatan->id,
            'warna'       => '#0033a0',
            'icon'        => 'fas fa-file-alt',
            'role'        => 'admin',
            'instansi_id' => $this->kegiatan->instansi_id,
        ];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('📋 Laporan Kegiatan Baru - SILAPORR')
            ->greeting('Halo, ' . $notifiable->name . '!')
            ->line('Ada laporan kegiatan baru yang masuk ke sistem.')
            ->line('**Judul:** ' . $this->kegiatan->nama_kegiatan)
            ->line('**Pengirim:** ' . $this->kegiatan->user->name)
            ->line('**Tanggal:** ' . \Carbon\Carbon::parse($this->kegiatan->tanggal)->translatedFormat('d F Y'))
            ->action('Lihat Detail Kegiatan', url('/kegiatan/' . $this->kegiatan->id))
            ->line('Terima kasih telah menggunakan SILAPORR.')
            ->salutation('Salam, Tim SILAPORR');
    }
}