<?php

// namespace App\Notifications;

// use Illuminate\Bus\Queueable;
// use Illuminate\Contracts\Queue\ShouldQueue;
// use Illuminate\Notifications\Messages\MailMessage;
// use Illuminate\Notifications\Notification;
// use Illuminate\Support\Facades\Lang;

// class CustomResetPassword extends Notification
// {
//     use Queueable;

//     public $token;

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

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

    // public function toMail($notifiable)
    // {
    //     // Buat URL reset password yang mengarah ke frontend
    //     $url = "https://localhost:5173/reset-password?token={$this->token}&email={$notifiable->getEmailForPasswordReset()}";

    //     return (new MailMessage)
    //         ->subject(Lang::get('Reset Password Notification'))
    //         ->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
    //         ->action(Lang::get('Reset Password'), $url)
    //         ->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
    //         ->line(Lang::get('If you did not request a password reset, no further action is required.'));
    // }
//     public function toMail($notifiable)
// {
//     $url = "http://localhost:5173/reset-password?token={$this->token}&email={$notifiable->getEmailForPasswordReset()}";
//     // $frontendUrl = env('FRONTEND_URL', 'http://localhost:5173'); // Pastikan env sudah benar
//     // $url = "{$frontendUrl}/reset-password?token={$this->token}&email=" . urlencode($notifiable->getEmailForPasswordReset());
    
//     return (new MailMessage)
//         ->subject(Lang::get('Reset Password Notification'))
//         ->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
//         ->action(Lang::get('Reset Password'), $url)
//         ->line(Lang::get('This password reset link will expire in :count minutes.', [
//             'count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')
//         ]))
//         ->line(Lang::get('If you did not request a password reset, no further action is required.'));
// }


// }


namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Lang;

class CustomResetPassword extends Notification
{
    use Queueable;

    public $token; // Token reset password

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

    // Metode untuk menentukan channel notifikasi (email)
    public function via($notifiable)
    {
        return ['mail'];
    }

    // Metode untuk membuat email reset password
    public function toMail($notifiable)
    {
        // Buat URL reset password yang mengarah ke route 'password.reset'
        $url = url(route('password.reset', [
            'token' => $this->token,
            'email' => $notifiable->getEmailForPasswordReset(),
        ], false));
        // Link di email → arahkan ke halaman Next.js
        $frontendUrl = config('app.frontend_url') . '/reset-password?token=' . $this->token 
             . '&email=' . urlencode($notifiable->getEmailForPasswordReset());

        return (new MailMessage)
            ->subject('Waduh, Lupa Password? Tenang, Ada Solusinya!')
            ->greeting('Halo Sobat MidHouse! 👋')
            ->line('Kami dapet laporan kalau kamu lupa password akunmu. Tenang aja, nggak usah panik, tinggal klik tombol di bawah ini buat atur ulang password barumu:')
            ->action('Reset Password Sekarang', $url)
            ->line('Atau kalau kamu lebih nyaman lewat portal frontend kami, bisa klik link ini:')
            ->action('Reset via Portal', $frontendUrl)
            ->line('Inget ya, link ini cuma aktif selama 60 menit. Jadi buruan diganti sebelum kedaluwarsa!', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')])
            ->line('Kalau telanjur kelewat, kamu tinggal request ulang aja kok.')
            ->line('Bukan kamu yang minta ganti? Cuekin aja email ini, passwordmu bakal tetep aman.')
            ->salutation('Salam anget, Tim MidHouse Universe');
    }
}