<?php

namespace App\Livewire\Search;

use App\Models\Doi_date;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\On;
use Livewire\Component;
use Spatie\Permission\Models\Role;

class PassportModal extends Component
{

    protected $listeners = ['openPassportModal'];
    public $passport=[];
    public $hasRole = false;
    public $role;
    public $isOpen = false;

    public function mount()
    {
        /** @var Auth $user current logged-in user */
        $user = Auth::user();

        /** @var User $contract_id  user contract ID */
        $contractId = $user['contract_rid'];

        try {
            $this->role = Role::findByName('CID-'.$user->contract_rid);
        } catch (Exception $e)
        {
            //abort(403, "You don't have permission to perform basic search.");
        }
    }

    public function render()
    {
        return view('livewire.search.passport-modal');
    }

    #[On('openPassportModal')]
    public function openPassportModal($data): void
    {

        $this->passport= Doi_date::where('passport_no', $data['pass_no'])->where('identity_card_no', $data['id'])->get();
        $this->isOpen = true;
    }

    public function placeholder()
    {
        return view('livewire.search.skeleton.resultsmodal');
    }

    public function closeModal()
    {
        // $this->isOpen = false;
    }



}
