<?php

namespace App\Livewire\Admin;

use App\Models\Incident;
use LivewireUI\Modal\ModalComponent;

/**
 * "Really remove this incident?"
 *
 * In the product's own dialog, not the browser's (R23). The modal mutates
 * nothing itself: it dispatches, and Admin\Incidents — which already holds the
 * capability check — does the work. Duplicating the authorisation here would
 * mean two places to keep right.
 */
class ConfirmDeleteIncident extends ModalComponent
{
    public string $uuid = '';

    public string $title = '';

    public function mount(string $uuid): void
    {
        $incident = Incident::query()->where('uuid', $uuid)->firstOrFail();

        $this->uuid = $incident->uuid;
        $this->title = $incident->title;
    }

    public function confirm(): void
    {
        $this->dispatch('incident-delete-confirmed', uuid: $this->uuid);
        $this->closeModal();
    }

    public function render()
    {
        return view('livewire.admin.confirm-delete-incident');
    }
}
