<?php

namespace App\Notifications;

use App\Kegiatan;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class KegiatanDiteruskanNotification extends Notification
{
    use Queueable;

    protected $kegiatan;
    protected $pengirim;
    protected $catatan;

    public function __construct(Kegiatan $kegiatan, User $pengirim, $catatan = null)
    {
        $this->kegiatan = $kegiatan;
        $this->pengirim = $pengirim;
        $this->catatan  = $catatan;
    }

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

    public function toDatabase($notifiable)
    {
        return [
            'judul'       => '📨 Kegiatan Diteruskan',
            'pengirim'    => $this->pengirim->name,
            'email'       => $this->pengirim->email,
            'pesan'       => 'Meneruskan kegiatan: ' . $this->kegiatan->nama_kegiatan,
            'catatan'     => $this->catatan,
            'role'        => 'admin',
            'instansi_id' => $this->kegiatan->instansi_id,
            'kegiatan_id' => $this->kegiatan->id,
            'url'         => route('kegiatan.show', $this->kegiatan->id),
            'icon'        => 'fas fa-forward',
            'warna'       => '#17a2b8',
        ];
    }

    public function toMail($notifiable)
    {
        $mail = (new MailMessage)
            ->subject('📨 Kegiatan Diteruskan ke Anda - SILAPORR')
            ->greeting('Halo, ' . $notifiable->name . '!')
            ->line('Ada kegiatan yang diteruskan ke Anda.')
            ->line('**Judul:** ' . $this->kegiatan->nama_kegiatan)
            ->line('**Diteruskan oleh:** ' . $this->pengirim->name);

        if ($this->catatan) {
            $mail->line('**Catatan:** ' . $this->catatan);
        }

        return $mail
            ->action('Lihat Detail Kegiatan', route('kegiatan.show', $this->kegiatan->id))
            ->line('Terima kasih telah menggunakan SILAPORR.')
            ->salutation('Salam, Tim SILAPORR');
    }
}