<?phpnamespace App\Form;use App\Gui\IconBox;use JumPHP\Gui\Button;use JumPHP\Gui\Form;use JumPHP\Gui\Label;/** * "Are you sure you want to shut down VM 'web-01'?": Yes closes with ['confirm' => command, 'target' => ref] (MainForm runs it). * * @property IconBox $icon * @property Label $message * @property Button $ok * @property Button $cancel */final class ConfirmForm extends Form{ public function __construct(private \App\Model\Session $session) { parent::__construct(); } /** XAPI's answers, events and the console go on while this dialog is open. */ protected function tick(float $dt): void { $this->session->tick($dt); } private array $params = []; protected function loaded(array $params = []): void { $this->params = $params; $this->message->text = (string)($params['message'] ?? ''); $this->ok->text = (string)($params['ok'] ?? 'Yes'); $danger = in_array($this->ok->text, ['Delete', 'Remove'], true) || str_contains((string)($params['command'] ?? ''), 'force'); $this->ok->style = $danger ? 'danger' : 'primary'; $this->cancel->text = $this->ok->text === 'Yes' ? 'No' : 'Cancel'; $this->icon->kind = $danger ? 'alert' : 'warning'; } public function onOkClick(Button $sender): void { $this->close(['confirm' => $this->params['command'] ?? '', 'target' => $this->params['target'] ?? '']); } public function onCancelClick(Button $sender): void { $this->close(); }}