<?php

namespace App\Livewire\Documents;

use App\Domain\Document\DocumentSettings;
use App\Domain\Document\Services\DocumentService;
use App\Domain\Participant\Models\Participant;
use App\Domain\Shared\Models\SystemSetting;
use Livewire\Component;

class MedicalCertificateAlert extends Component
{
    public Participant $participant;
    public bool $show = false;
    public bool $isBlocking = false;
    public bool $hasValid = false;

    public function mount(Participant $participant): void
    {
        $this->participant = $participant;

        $requireMedical = SystemSetting::get(DocumentSettings::REQUIRE_MEDICAL_CERTIFICATE, false);
        if (!$requireMedical) {
            return;
        }

        $service = app(DocumentService::class);
        $this->hasValid = $service->participantHasValidMedical($participant);
        $this->isBlocking = (bool) SystemSetting::get(DocumentSettings::BLOCK_ATTENDANCE_WITHOUT_MEDICAL, false);
        $this->show = !$this->hasValid;
    }

    public function render()
    {
        return view('livewire.documents.medical-certificate-alert');
    }
}
