import { Check, Puzzle, SlidersHorizontal } from 'lucide-react'; import { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import type { PuzzleCreativeTemplateSelection } from '../../../packages/shared/src/contracts/puzzleCreativeTemplate'; import { useAuthUi } from '../auth/AuthUiContext'; import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformIconBadge } from '../common/PlatformIconBadge'; import { PlatformMediaFrame } from '../common/PlatformMediaFrame'; import { PlatformModalCloseButton } from '../common/PlatformModalCloseButton'; import { PlatformSegmentedTabs } from '../common/PlatformSegmentedTabs'; import { PlatformStatGrid } from '../common/PlatformStatGrid'; import { PlatformSubpanel } from '../common/PlatformSubpanel'; import { PlatformTextField } from '../common/PlatformTextField'; type CreativeAgentTemplateConfirmPanelProps = { selection: PuzzleCreativeTemplateSelection; isBusy: boolean; onConfirm: (selection: PuzzleCreativeTemplateSelection) => void; onCancel: () => void; }; function clampLevelCount( value: number, selection: PuzzleCreativeTemplateSelection, ) { const { min, max } = resolveLevelCountBounds(selection); return Math.max(min, Math.min(max, value)); } function resolveLevelCountBounds(selection: PuzzleCreativeTemplateSelection) { if (selection.selectedLevelMode === 'single_level') { return { min: 1, max: 1, }; } return { min: 2, max: 6, }; } function canUseLevelMode( selection: PuzzleCreativeTemplateSelection, mode: PuzzleCreativeTemplateSelection['selectedLevelMode'], ) { if (selection.supportedLevelMode === 'single') { return mode === 'single_level'; } if (selection.supportedLevelMode === 'multi') { return mode === 'multi_level'; } return true; } export function CreativeAgentTemplateConfirmPanel({ selection, isBusy, onConfirm, onCancel, }: CreativeAgentTemplateConfirmPanelProps) { const platformTheme = useAuthUi()?.platformTheme ?? 'light'; const [isAdjustOpen, setIsAdjustOpen] = useState(false); const [draftSelection, setDraftSelection] = useState(selection); const levelCountBounds = resolveLevelCountBounds(draftSelection); useEffect(() => { setDraftSelection(selection); }, [selection]); const pointsText = `${draftSelection.costRange.minPoints} 到 ${draftSelection.costRange.maxPoints} 泥点`; const panel = (
{ if (event.target === event.currentTarget && !isBusy) { onCancel(); } }} >
event.stopPropagation()} >
{draftSelection.title}
预计 {pointsText}
} size="xl" tone="softBright" /> } aspect="landscape" surface="soft" className="rounded-[1.25rem]" fallbackShellClassName="bg-[radial-gradient(circle_at_28%_20%,rgba(255,255,255,0.92),transparent_32%),linear-gradient(135deg,rgba(255,194,123,0.86),rgba(255,93,132,0.82)_52%,rgba(92,186,255,0.78))]" fallbackClassName="tracking-normal" />
{draftSelection.reason}
setIsAdjustOpen((current) => !current)} > 调整 onConfirm(draftSelection)} > 确认
{isAdjustOpen ? (
event.stopPropagation()} >
调整关卡
setIsAdjustOpen(false)} title="关闭" />
{ setDraftSelection((current) => ({ ...current, selectedLevelMode: nextLevelMode, plannedLevelCount: nextLevelMode === 'single_level' ? 1 : Math.max(2, current.plannedLevelCount), })); }} radius="md" size="compact" />
setIsAdjustOpen(false)} > 完成
) : null}
); if (typeof document === 'undefined') { return null; } return createPortal(panel, document.body); }