<?php

namespace App\Livewire;
use App\Models\Setting;
use App\Models\Subscribe;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\URL;
use Livewire\Attributes\Rule;
use Livewire\Component;

class FooterNewsletter extends Component
{
    #[Rule('required|email|unique:subscribes')]
    public $email='';

    public function subscribe()
    {
        $url = URL::previous();
        $validated = $this->validate();
        Subscribe::create([

            'email' => $this->email,
           

        ]);
        //send email
        $settings = Setting::first();
        //Mail::to($this->email)->send(new \App\Mail\Enquiry($validated));
        //Mail::to($settings->email)->send(new \App\Mail\AdminEnquiry($validated));

        $url = URL::previous();
        $this->reset();
        flash()->addSuccess('Successful', ' Successfully subscribed to our newsletter');
        //session()->flash('register-message', 'You have booked property Successfully');
        $this->redirect($url);  
    }



    public function render()
    {
        return view('livewire.footer-newsletter');
    }
}
