'use client';
import { useState, useEffect, useCallback } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { usePrestigeStore, useGameStore } from '@/lib/game/stores';
import { PRESTIGE_DEF } from '@/lib/game/constants/prestige';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scroll-area';
import { SectionHeader } from '@/components/ui/section-header';
import { DebugName } from '@/components/game/debug/debug-context';
import { fmt } from '@/lib/game/stores';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
// ─── Stat Cell ────────────────────────────────────────────────────────────────
function PrestigeStatCell({ value, label, color }: { value: string | number; label: string; color: string }) {
return (
);
}
// ─── Insight Summary ──────────────────────────────────────────────────────────
function InsightSummary({ insight, totalInsight, loopCount, loopInsight }: {
insight: number;
totalInsight: number;
loopCount: number;
loopInsight: number;
}) {
return (
);
}
// ─── Memories Card ────────────────────────────────────────────────────────────
function MemoriesCard({ memories, memorySlots }: { memories: { skillId: string; level: number; tier: number }[]; memorySlots: number }) {
return (
Skills carried between loops. Slots: {memories.length}/{memorySlots}
{memories.length === 0 ? (
No memories stored yet.
) : (
{memories.map((m) => (
{m.skillId}
Lv.{m.level} T{m.tier}
))}
)}
);
}
// ─── Pacts Card ───────────────────────────────────────────────────────────────
function PactsCard({ signedPacts, pactSlots, defeatedGuardians }: {
signedPacts: number[];
pactSlots: number;
defeatedGuardians: number[];
}) {
return (
Guardian pacts signed. Slots: {signedPacts.length}/{pactSlots}
{defeatedGuardians.length > 0 && (
Defeated guardians: {defeatedGuardians.map((f) => `F${f}`).join(', ')}
)}
{signedPacts.length === 0 ? (
No pacts signed yet.
) : (
{signedPacts.map((f) => (
✓ Floor {f} — Pact signed
))}
)}
);
}
// ─── Upgrade Card ─────────────────────────────────────────────────────────────
interface UpgradeCardProps {
id: string;
name: string;
desc: string;
max: number;
cost: number;
currentLevel: number;
insight: number;
onPurchase: (id: string) => void;
}
function UpgradeCard({ id, name, desc, max, cost, currentLevel, insight, onPurchase }: UpgradeCardProps) {
const isMaxed = currentLevel >= max;
const canAfford = insight >= cost;
const disabled = isMaxed || !canAfford;
return (
{name}
{currentLevel}/{max}
{desc}
Cost: {fmt(cost)} insight
onPurchase(id)}
className="h-7 px-3 text-xs"
>
{isMaxed ? 'Maxed' : 'Buy'}
);
}
// ─── Reset Loop Section ──────────────────────────────────────────────────────
function ResetLoopSection({ loopInsight, onReset }: { loopInsight: number; onReset: () => void }) {
return (
Reset Loop
End the current loop and gain {fmt(loopInsight)} insight. Your prestige upgrades, memories, and pacts are preserved.
Reset Loop
Reset the Loop?
This will end your current loop and award you {fmt(loopInsight)} insight .
Your prestige upgrades, memories, and pacts will be preserved.
Day, hour, mana, floor progress, and combat state will be reset.
Cancel
Confirm Reset
);
}
// ─── Main Component ───────────────────────────────────────────────────────────
export function PrestigeTab() {
const [mounted, setMounted] = useState(false);
const {
insight,
totalInsight,
loopInsight,
loopCount,
prestigeUpgrades,
memorySlots,
memories,
pactSlots,
signedPacts,
defeatedGuardians,
doPrestige,
} = usePrestigeStore(useShallow((s) => ({
insight: s.insight,
totalInsight: s.totalInsight,
loopInsight: s.loopInsight,
loopCount: s.loopCount,
prestigeUpgrades: s.prestigeUpgrades,
memorySlots: s.memorySlots,
memories: s.memories,
pactSlots: s.pactSlots,
signedPacts: s.signedPacts,
defeatedGuardians: s.defeatedGuardians,
doPrestige: s.doPrestige,
})));
const startNewLoop = useGameStore((s) => s.startNewLoop);
useEffect(() => {
setMounted(true);
}, []);
const handlePurchase = useCallback((id: string) => {
doPrestige(id);
}, [doPrestige]);
const handleResetLoop = useCallback(() => {
startNewLoop();
}, [startNewLoop]);
if (!mounted) {
return (
Loading prestige…
);
}
const upgradeEntries = Object.entries(PRESTIGE_DEF);
return (
{upgradeEntries.map(([id, def]) => (
))}
);
}
PrestigeTab.displayName = 'PrestigeTab';