import type { PlayerState } from "@deadhead/schema"; import { formatLocalTime } from "../screens/DispatchSheet"; import { errorMessage, useGameAction, useLoadedPlayer } from "../state/actions"; import { Button, Icon, Panel } from "../ui"; /** A sleep threshold in words: "12 h", "24 h", "48 h", "3 days" (CR-024 §2). */ export function sleepLabel(hours: number): string { return hours > 48 && hours % 24 === 0 ? `${hours / 24} days` : `${hours} h`; } /** The sleep time on the device, e.g. "Mar 4, 14:05". */ export function formatSleepTime(time: number): string { const date = new Date(time).toLocaleDateString(undefined, { month: "short", day: "numeric" }); return `${date}, ${formatLocalTime(time)}`; } /** * The fleet has gone quiet (decision 0.5.137) and it matters: some pilot is * Independent, so there is work waiting on the player's orders. */ export function fleetQuiet(state: PlayerState): boolean { return state.fleetSleep.asleep && state.pilots.some((p) => p.mode === "independent"); } /** "Back to work": a manual decision that wakes the fleet (decision 0.5.138). */ function BackToWork() { const wake = useGameAction("backToWork"); return ( <> {wake.isError && (
{errorMessage(wake.error)}
)} > ); } /** The "while you were away" banner: when the fleet went quiet, and why. */ export function SleepBanner() { const state = useLoadedPlayer(); if (!fleetQuiet(state)) return null; const { sleepsAt, afterHours } = state.fleetSleep; return (
Independent pilots start no new jobs after {sleepLabel(state.fleetSleep.afterHours)} without orders. Any decision wakes them.