"use client"; import { useEffect, useState } from "react"; import { DOSSIER } from "@/components/frontend/operations"; import { formatActivityLine, resolveCurrentActivity, type NpcActivityOption, } from "@/lib/npcs/activity"; interface NpcActivityLineProps { /** How often (minutes) the activity reshuffles when nothing is forced. */ readonly intervalMinutes: number; /** The contact's possible activities. */ readonly activityOptions: NpcActivityOption[]; } /** * Reads the contact's "current activity" and reshuffles it on the configured * interval. A forced activity stays put until the flag is turned off. */ export function NpcActivityLine({ intervalMinutes, activityOptions }: NpcActivityLineProps) { const [tick, setTick] = useState(0); const reshuffle = intervalMinutes > 0 && activityOptions.length > 0; useEffect(() => { if (!reshuffle) return; const interval = setInterval(() => setTick((prev) => prev + 1), intervalMinutes * 60_000); return () => clearInterval(interval); }, [intervalMinutes, reshuffle]); const activity = resolveCurrentActivity(activityOptions, reshuffle ? `tick-${tick}` : undefined); return ( // leading-none keeps the label and chip off the inherited (tall) line-height, // so the chip matches the NpcStatusChips tags below it.