'use client' import { useEffect, useState } from 'react' import { Badge } from '@/components/ui/badge' import { Panel, PanelContent, PanelHeader, PanelTitle } from '@/components/ui/panel' import { Progress } from '@/components/ui/progress' import { StatCard } from '@/components/ui/stat-card' import { StatusGrid, type SystemEntry } from '@/components/ui/status-grid' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { CrewPanel } from '@/components/crew-panel' import { EventLogPanel } from '@/components/event-log' import { LocalSystemPanel } from '@/components/local-system' import { MissionPanel } from '@/components/missions' import { ShipSystemsPanel } from '@/components/ship-systems' import { SkillTreePanel } from '@/components/skill-tree' import { WorldMapPanel } from '@/components/world-map' import { CREW_CAPACITY } from '@/lib/game/ship-costs' import type { CrewDto, SystemState } from '@/lib/game/save' import type { ShipState } from '@/lib/game/ship' import type { TechDto } from '@/lib/game/tech' // Interface base: layout + visual treatment rebuilt from the scificn-ui Mission Control // showcase (src/app/_pages/showcase/mission-control-content.tsx in baxy5/scificn-ui). All seven // tabs render live data (/api/world, /api/system, /api/crew, /api/ship, /api/tech, /api/missions, // /api/events); the right column's CARGO HOLD renders from the lifted /api/system state. Single // player, no auth, by design. function useNarrow(threshold = 900): boolean { const [narrow, setNarrow] = useState( () => typeof window !== 'undefined' && window.innerWidth < threshold ) useEffect(() => { const handle = () => setNarrow(window.innerWidth < threshold) window.addEventListener('resize', handle, { passive: true }) return () => window.removeEventListener('resize', handle) }, [threshold]) return narrow } export function MissionControl() { const narrow = useNarrow() const [tick, setTick] = useState(0) // Ship + system state is owned here (not in the tab panels): the SHIP SYSTEMS tab mirrors ship // actions via setShip, and the right column's CARGO HOLD renders from the lifted inventory — // the LOCAL SYSTEM tab reports each scan's response up via setSystem. Crew count feeds the // roster bar — refetched on page load, like the other panels. const [ship, setShip] = useState(null) const [system, setSystem] = useState(null) const [techs, setTechs] = useState(null) const [crewCount, setCrewCount] = useState(null) useEffect(() => { let cancelled = false fetch('/api/ship') .then(async (res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return (await res.json()) as ShipState }) .then((s) => { if (!cancelled) setShip(s) }) .catch(() => {}) // left column + tab keep their loading state on failure fetch('/api/system') .then(async (res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return (await res.json()) as SystemState }) .then((s) => { if (!cancelled) setSystem(s) }) .catch(() => {}) fetch('/api/tech') .then(async (res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return (await res.json()) as TechDto[] }) .then((t) => { if (!cancelled) setTechs(t) }) .catch(() => {}) fetch('/api/crew') .then(async (res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`) return (await res.json()) as CrewDto[] }) .then((c) => { if (!cancelled) setCrewCount(c.length) }) .catch(() => {}) return () => { cancelled = true } }, []) useEffect(() => { const id = setInterval(() => setTick((t) => t + 1), 1000) return () => clearInterval(id) }, []) const timeStr = new Date().toLocaleTimeString('en-GB', { hour12: false }) // Slugs of the researched techs — drives the effective caps + build gates in the SHIP SYSTEMS // tab via the same pure helpers the API enforces (lib/game/tech.ts). const researchedSlugs = new Set((techs ?? []).filter((t) => t.state === 'RESEARCHED').map((t) => t.slug)) return (
{/* ── HEADER ── */}
◄ SHIP │

SPACEWANDERER

{!narrow && ( // SHIP STATUS // CREW MANIFEST )}
{!narrow && ( SHIP NOMINAL )} SECTOR SCAN {timeStr}
{/* ── BODY ── */}
{/* STAT CARDS — placeholder ship readouts */}
{/* 3-COLUMN GRID */}
{/* ── LEFT: SHIP SYSTEMS + VESSEL METRICS (mirrors the SHIP SYSTEMS tab) ── */}
SHIP SYSTEMS
s.built) ? 'ACTIVE' : 'OFFLINE'}> {ship ? `${ship.systems.filter((s) => s.built).length} ONLINE` : '—'}
{ship ? ( ({ name: s.type, status: s.built ? ('ACTIVE' as const) : ('OFFLINE' as const), detail: s.built ? `LV ${s.level} · CAP ${s.capacity}` : undefined, }))} /> ) : (
LOADING…
)}
VESSEL METRICS {ship ? ( // Bars driven by real values: hull/reactor from system levels (level × 20, capped), // crew roster vs the display cap; SECTOR/TURN rows folded in from the old SHIP DATA // placeholder (the rest of it duplicated these bars or had no game equivalent).
s.type === 'HULL')?.level ?? 0) * 20)} /> s.type === 'REACTOR')?.level ?? 0) * 20)} />
{[ { label: 'SECTOR', value: (system?.systemName ?? '—').toUpperCase() }, { label: 'TURN', value: String(ship.turn) }, ].map((item, i) => (
{item.label} {item.value}
))}
) : ( LOADING… )}
{/* ── CENTER: GAME TEMPLATE TABS (visual only — no handlers, placeholder data) ── */}
{/* flex column + minHeight:0 so the tab content scrolls inside the panel (#21) — the Panel root's default overflow:hidden would otherwise clip it */} OPERATIONS // SHIP COMMAND
SYS NOMINAL
WORLD MAP LOCAL SYSTEM CREW SHIP SYSTEMS SKILL TREE MISSIONS EVENT LOG {/* WORLD MAP TAB — live data from /api/world */} {/* LOCAL SYSTEM TAB — live data (state owned by MissionControl; scans report up) */} {/* CREW TAB — live data from /api/crew */} {/* SHIP SYSTEMS TAB — live data from /api/ship (state owned by MissionControl) */} {/* SKILL TREE TAB — live data from /api/tech (state owned by MissionControl) */} {/* MISSIONS TAB — live data from /api/missions */} {/* EVENT LOG TAB */}
{/* ── RIGHT: CARGO HOLD (persistent — inventory lifted from /api/system) ── */}
CARGO HOLD // INVENTORY {system && (
0 ? 'ACTIVE' : 'OFFLINE'}> {system.inventory.reduce((n, i) => n + i.qty, 0)} UNITS
)}
{!system ? (
LOADING…
) : system.inventory.length === 0 ? (
EMPTY — EXPLORE WORLDS TO FIND THINGS
) : ( system.inventory.map((item) => (
{item.name} // {item.kind} ×{item.qty}
)) )}
{/* ── FOOTER ── */}
) }