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 = (