import { Loader2, Play, RefreshCcw, Send } from 'lucide-react'; import { useState } from 'react'; import type { PuzzleClearDraftResponse, PuzzleClearWorkProfileResponse, } from '../../../packages/shared/src/contracts/puzzleClear'; import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformBackActionButton } from '../common/PlatformBackActionButton'; import { PlatformMediaFrame } from '../common/PlatformMediaFrame'; import { PlatformMediaTileGrid } from '../common/PlatformMediaTileGrid'; import { PlatformStatGrid } from '../common/PlatformStatGrid'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; import { PlatformSubpanel } from '../common/PlatformSubpanel'; type PuzzleClearResultViewProps = { profile: PuzzleClearDraftResponse | PuzzleClearWorkProfileResponse; isBusy?: boolean; error?: string | null; onBack: () => void; onEdit: () => void; onStartTestRun: () => void; onPublish: () => void; onRegenerateAtlas: () => void; }; function isPuzzleClearWorkProfile( profile: PuzzleClearResultViewProps['profile'], ): profile is PuzzleClearWorkProfileResponse { return 'summary' in profile; } function getDraft(profile: PuzzleClearResultViewProps['profile']) { return isPuzzleClearWorkProfile(profile) ? profile.draft : profile; } export function PuzzleClearResultView({ profile, isBusy = false, error = null, onBack, onEdit, onStartTestRun, onPublish, onRegenerateAtlas, }: PuzzleClearResultViewProps) { const [isPublishing, setIsPublishing] = useState(false); const isWorkProfile = isPuzzleClearWorkProfile(profile); const draft = getDraft(profile); const summary = isWorkProfile ? profile.summary : null; const title = summary?.workTitle?.trim() || draft.workTitle.trim() || '拼消消'; const description = summary?.workDescription?.trim() || draft.workDescription.trim(); const boardBackgroundAsset = isWorkProfile ? (profile.boardBackgroundAsset ?? draft.boardBackgroundAsset) : draft.boardBackgroundAsset; const atlasAsset = isWorkProfile ? profile.atlasAsset : draft.atlasAsset; const patternGroups = isWorkProfile ? profile.patternGroups : draft.patternGroups; const cardAssets = isWorkProfile ? profile.cardAssets : draft.cardAssets; const previewCards = cardAssets.slice(0, 24); const canPublish = Boolean(isWorkProfile && summary?.publishReady); const handlePublish = async () => { setIsPublishing(true); try { await Promise.resolve(onPublish()); } finally { setIsPublishing(false); } }; return (