<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\SiteSetting;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class EmailVerificationNotificationController extends Controller
{
    /**
     * Send a new email verification notification.
     */
    public function store(Request $request): RedirectResponse
    {
        if (! SiteSetting::emailVerificationEnabled() || $request->user()->hasVerifiedEmail()) {
            return redirect()->intended($this->redirectPathFor($request->user()));
        }

        $request->user()->sendEmailVerificationNotification();

        return back()->with('status', 'verification-link-sent');
    }

    private function redirectPathFor($user): string
    {
        if ($user->isAdmin()) {
            return route('admin.dashboard', absolute: false);
        }

        if ($user->isSupportTeam()) {
            return route('support-team.dashboard', absolute: false);
        }

        return route('dashboard', absolute: false);
    }
}
