import { useState } from 'react' import { api } from './api' import { Btn, Spinner } from './ui' // Header power control: a small button, a dialog that needs the hostname typed back. // `label` is what the user types (the machine name on a remote); `host` is what the node checks. export default function Power({ host, label, rebootNeeded }: { host: string; label: string; rebootNeeded?: boolean }) { const [open, setOpen] = useState(false) const [typed, setTyped] = useState('') const [sent, setSent] = useState<'' | 'reboot' | 'poweroff'>('') const [err, setErr] = useState('') const ok = typed.trim() === label async function go(action: 'reboot' | 'poweroff') { setErr('') try { await api.power(action, host); setSent(action) } catch (e) { setErr(e instanceof Error ? e.message : 'failed') } } return ( <> {open && (