<?php

namespace App\Http\Controllers\UserAuth;

use App\Http\Controllers\Controller;
use App\Http\Requests\User\RegistrationRequest;
use App\Mail\ConfirmationMail;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Monarobase\CountryList\CountryListFacade;

class RegisterController extends Controller
{
    
    public function __construct()
    {
        if(Auth::check()){
            return redirect('/');
        }
    }

    public function index(){
        $countries = CountryListFacade::getList('en');
        return view('Dashboard.User.user_registration' , compact('countries'));
    }

    public function store(RegistrationRequest $request){
        $generator =  substr(md5(uniqid(rand(), true)) , 0 , 4);
        $name = $request->name;
        $email = $request->email;
        $data = array_merge($request->all(), ['ip_address'=>$request->ip()]);

        session()->put('user_data' , $data);
        session()->put('verify' , $generator);
        Mail::send(new ConfirmationMail($name , $generator , $email));
        return redirect()->route('verify.email');
    }





}
