<?php

namespace App\Livewire\Auth;

use App\Traits\Components\WithToast;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('components.layouts.auth', [
    'title' => 'Verifikasi Email',
])]
class VerifyEmail extends Component
{
    use WithToast;

    /**
     * Send email verification notification to the user.
     */
    public function resend(): void
    {
        if (Auth::user()->hasVerifiedEmail()) {
            $this->redirectIntended(route('member.overview'), navigate: true);

            return;
        }

        Auth::user()->sendEmailVerificationNotification();

        $this->toast('Tautan verifikasi baru telah dikirim ke alamat email Anda.');
    }

    /**
     * Log the user out of the application.
     */
    public function logout(): void
    {
        Auth::logout();

        $this->redirect(route('login'), navigate: true);
    }

    public function render(): View
    {
        return view('livewire.auth.verify-email');
    }
}
