<?php

namespace App\Notifications;

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

class PesanNotifikasi extends Notification
{
    use Queueable;

    protected $data;

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

    public function via($notifiable)
    {
        return ['database', 'mail']; // Tambahkan 'mail' di sini
    }

    public function toDatabase($notifiable)
    {
        return [
            'judul'     => $this->data['judul'],
            'isi_pesan' => $this->data['isi_pesan'],
            'foto'      => $this->data['foto'] ?? null,
            'icon'      => $this->data['icon'] ?? '📢',
            'warna'     => $this->data['warna'] ?? 'gray',
        ];
    }

    public function toMail($notifiable)

    {
    return (new MailMessage)
        ->subject($this->data['judul'] ?? 'Notifikasi')
        ->greeting('Halo!')
        ->line($this->data['isi_pesan'] ?? '-')
        ->action('Lihat Sistem', url('/'))
        ->line('Terima kasih atas perhatiannya.');

    }
}
