<?php

namespace App\Livewire\Admin;

use LivewireUI\Modal\ModalComponent;

/**
 * Confirmation before a NEW SSH identity replaces the one in force (R23).
 *
 * Not a formality. The public half of the current key sits in
 * `/root/.ssh/authorized_keys` on every host that has ever been onboarded, and
 * nothing pushes the new one there — EstablishSshTrust installs it once, with
 * the root password, during a takeover. Between generating and rolling the new
 * public half out by hand, this console reaches no machine at all.
 *
 * Mutates nothing itself: confirming dispatches back to Admin\Integrations,
 * whose generateSshKey() keeps its own guard (capability + recent password).
 */
class ConfirmGenerateSshKey extends ModalComponent
{
    public function mount(): void
    {
        $this->authorize('secrets.manage');
    }

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

    public function render()
    {
        return view('livewire.admin.confirm-generate-ssh-key');
    }
}
