<?php

namespace App\Http\Controllers\website;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;

class VerificationNotification extends Controller
{
    // public function index(Request $request)
    // {
    //     // print_r($request->all());
    //     $email = request()->query('email');
    //     // echo $email;
    //     $request->user()->sendEmailVerificationNotification();

    // }
    public function index(Request $request)
    {
        $email = $request->input('email');

        if (!$email) {
            return response()->json([
                'status' => false,
                'message' => 'Email is required.',
            ]);
        }

        // Find user by email
        $user = User::where('email', $email)->first();

        if (!$user) {
            return response()->json([
                'status' => false,
                'message' => 'User not found.',
            ]);
        }

        // If already verified
        // if ($user->hasVerifiedEmail()) {
        //     return response()->json([
        //         'status' => true,
        //         'message' => 'Email is already verified.',
        //     ]);
        // }

        // Send verification email
        $user->sendEmailVerificationNotification();

        return response()->json([
            'status' => true,
            'message' => 'Verification email sent successfully.',
        ]);
    }

    public function email_verify(Request $request)
    {
        $email = $request->query('email'); // or $request->get('email')
        $pageTitle = 'Verify Email';
        return view('auth.verify-email', compact('email', 'pageTitle'));

        // $email = request()->query('email');
        // echo $email;
        // die;
        // return view('auth.verify-email', compact('email'));
    }
}
