"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { Pause, Play } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Item, ItemContent, ItemDescription, ItemTitle } from "@/components/ui/item"; import { toggleProduction } from "@/app/(frontend)/logistics/base/actions"; export interface ProductionRecipeLine { readonly name: string; readonly amountPerHour: number; } export interface ProductionPanelProps { readonly gameStructureId: number; readonly complete: boolean; readonly paused: boolean; readonly stallReason: string | null; readonly inputs: readonly ProductionRecipeLine[]; readonly outputs: readonly ProductionRecipeLine[]; readonly canManage: boolean; } const STALL_LABELS: Record = { no_labor: "No active labor crew", missing_inputs: "Missing input materials", storage_full: "Storage is full", }; export function ProductionPanel({ gameStructureId, complete, paused, stallReason, inputs, outputs, canManage, }: ProductionPanelProps) { const router = useRouter(); const [loading, setLoading] = useState(false); if (!complete) return null; if (inputs.length === 0 && outputs.length === 0) return null; const toggle = async () => { setLoading(true); try { const result = await toggleProduction(gameStructureId, !paused); if (result.success) { toast.success(!paused ? "Production resumed." : "Production paused."); router.refresh(); } else { toast.error(result.error ?? "Could not change production."); } } finally { setLoading(false); } }; const statusText = paused ? "Paused" : stallReason ? (STALL_LABELS[stallReason] ?? stallReason) : "Running"; return (
Production {statusText} Runs per game tick while staffed; outputs land in void storage.
{canManage && ( )}
{stallReason === "missing_inputs" && (

Deliver the input materials below to resume the recipe.

)}

Inputs / hour

{inputs.length === 0 ? (

None

) : (
    {inputs.map((line) => (
  • {line.amountPerHour.toLocaleString()} {line.name}
  • ))}
)}

Outputs / hour

{outputs.length === 0 ? (

None

) : (
    {outputs.map((line) => (
  • {line.amountPerHour.toLocaleString()} {line.name}
  • ))}
)}
); }