import type { Dispatch, Ship } from "@deadhead/schema"; import { dispatchProgress } from "@deadhead/sim"; import { useState } from "react"; import { Link } from "react-router"; import { useClock } from "../clock/clock"; import { Countdown } from "../components/Countdown"; import { locationName, shipModelName } from "../format"; import { errorMessage, useGameAction, useLoadedPlayer } from "../state/actions"; /** All ships, their pilots and flights; idle ships at a bay can reposition (Step 9.6). */ export function Fleet() { const state = useLoadedPlayer(); const [repositioning, setRepositioning] = useState(null); return (

Fleet

{state.ships.length === 0 ? (

No ships yet —{" "} visit the Market .

) : ( )} {repositioning && ( setRepositioning(null)} /> )}
); } function ShipRow(props: { ship: Ship; dispatch: Dispatch | undefined; pilotName: string | null; canReposition: boolean; onReposition: () => void; }) { const { ship, dispatch, pilotName } = props; const now = useClock((s) => s.now); const progress = dispatch ? Math.round(dispatchProgress(dispatch, now) * 100) : 0; return (
  • {ship.name} {shipModelName(ship.modelId)}
    {dispatch ? `${locationName(dispatch.originId)} → ${locationName(dispatch.destinationId)}` : `At ${locationName(ship.locationId ?? "")}`} {" · "} {pilotName ?? "No pilot"}
    {dispatch && (
    Arrives in
    )} {props.canReposition && ( )}
  • ); } /** Choose another bay to fly an idle ship to, empty (fuel only). */ function RepositionPicker({ ship, onClose }: { ship: Ship; onClose: () => void }) { const state = useLoadedPlayer(); const reposition = useGameAction("createDispatch"); const destinations = state.bays.filter((b) => b.locationId !== ship.locationId); return (

    Reposition {ship.name}

    Fly empty to another bay. You pay fuel only.

      {destinations.map((bay) => (
    • ))}
    {reposition.isError && (

    {errorMessage(reposition.error)}

    )}
    ); }