<?php

namespace App\Livewire\Admin;

use App\Services\Secrets\SecretVault;
use LivewireUI\Modal\ModalComponent;

/**
 * Confirmation before a stored override is removed (R23), reverting the key
 * to whatever the server file provides. No mutation here — it dispatches
 * back to Secrets, whose forget() is unchanged.
 */
class ConfirmForgetSecret extends ModalComponent
{
    public string $key;

    public string $label = '';

    public function mount(string $key): void
    {
        $this->authorize('secrets.manage');
        abort_if(! array_key_exists($key, SecretVault::REGISTRY), 404);

        $this->key = $key;
        $this->label = __(SecretVault::REGISTRY[$key]['label']);
    }

    public function confirm(): void
    {
        $this->authorize('secrets.manage');
        $this->dispatch('secret-forget-confirmed', key: $this->key);
        $this->closeModal();
    }

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