import { content } from "@deadhead/content";
import type { TutorialState } from "@deadhead/schema";
import { realToGame } from "@deadhead/sim";
import { useClock } from "../clock/clock";
import { formatGameTime } from "../clock/GameClock";
import { Countdown } from "../components/Countdown";
import { GoalsCard } from "../components/GoalsCard";
import { LoanCard } from "../components/LoanCard";
import { formatCredits, locationName } from "../format";
import { useLoadedPlayer } from "../state/actions";
/** What the player needs to do next to reach the deal (decision 0.5.30). */
export function tutorialHint(tutorial: TutorialState, runsBeforeDeal: number): string {
if (tutorial.dealAvailable) return "Halvorsen is waiting at Earth with an offer.";
if (tutorial.runsCompleted < runsBeforeDeal) {
return "Keep flying — the old man has an offer for you.";
}
// Enough runs, but the deal is made at Earth.
return tutorial.runInFlight
? "Halvorsen will talk once you land at Earth."
: "One more run: bring the ship back to Earth — Halvorsen is waiting there.";
}
export function HQ() {
const state = useLoadedPlayer();
const now = useClock((s) => s.now);
const idle = state.ships.filter((s) => s.status === "idle").length;
const flying = state.ships.filter((s) => s.status === "in-flight").length;
const runsBeforeDeal = content.config.tutorialRunsBeforeDeal;
const next = [...state.activeDispatches].sort((a, b) => a.arrivalAt - b.arrivalAt)[0];
// Resting pilots and who wakes first (CR-004).
const resting = state.pilots
.filter((p) => p.resting && p.restEndsAt !== null)
.sort((a, b) => a.restEndsAt! - b.restEndsAt!);
return (
{locationName(next.originId)} → {locationName(next.destinationId)} in{" "}
Nothing in flight.
{resting[0].name} wakes in Everyone is ready to fly. No ships yet — buy one in the Market.
Company runs: {Math.min(state.tutorial.runsCompleted, runsBeforeDeal)} of{" "}
{runsBeforeDeal}
{tutorialHint(state.tutorial, runsBeforeDeal)}
HQ
Next arrival
{next ? (
Pilots resting: {resting.length}
{resting[0] ? (
Flying for Halvorsen Lunar Freight