import { ArrowLeft, Gift, Loader2, WandSparkles } from 'lucide-react'; import { useEffect, useMemo, useRef, useState } from 'react'; import type { CreateBabyObjectMatchDraftRequest } from '../../../packages/shared/src/contracts/edutainmentBabyObject'; import { validateBabyObjectMatchItemNames } from '../../../packages/shared/src/contracts/edutainmentBabyObject'; import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformFieldLabel } from '../common/PlatformFieldLabel'; import { PlatformIconBadge } from '../common/PlatformIconBadge'; import { PlatformPillBadge } from '../common/PlatformPillBadge'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; import { PlatformSubpanel } from '../common/PlatformSubpanel'; import { PlatformTextField } from '../common/PlatformTextField'; type BabyObjectMatchWorkspaceProps = { isBusy?: boolean; error?: string | null; initialPayload?: CreateBabyObjectMatchDraftRequest | null; onBack: () => void; onCreateDraft: (payload: CreateBabyObjectMatchDraftRequest) => void; showBackButton?: boolean; title?: string | null; }; type BabyObjectMatchFormState = { itemAName: string; itemBName: string; }; function resolveInitialFormState( initialPayload: CreateBabyObjectMatchDraftRequest | null | undefined, ): BabyObjectMatchFormState { return { itemAName: initialPayload?.itemAName ?? '', itemBName: initialPayload?.itemBName ?? '', }; } export function BabyObjectMatchWorkspace({ isBusy = false, error = null, initialPayload = null, onBack, onCreateDraft, showBackButton = true, title = null, }: BabyObjectMatchWorkspaceProps) { const [formState, setFormState] = useState(() => resolveInitialFormState(initialPayload), ); const appliedInitialKeyRef = useRef(null); useEffect(() => { const nextInitialKey = JSON.stringify(initialPayload ?? null); if (appliedInitialKeyRef.current === nextInitialKey) { return; } appliedInitialKeyRef.current = nextInitialKey; setFormState(resolveInitialFormState(initialPayload)); }, [initialPayload]); const validation = useMemo( () => validateBabyObjectMatchItemNames(formState), [formState], ); const canSubmit = validation.valid && !isBusy; const submitForm = () => { if (!canSubmit) { return; } onCreateDraft({ itemAName: validation.itemAName, itemBName: validation.itemBName, }); }; return (
{showBackButton ? (
返回
) : null}
{title ? (

{title}

BETA
) : null}
} label="宝贝识物图标" size="xl" shape="rounded" tone="softBright" className="text-emerald-600 shadow-[0_12px_30px_rgba(16,185,129,0.14)]" />
宝贝识物
{error ? ( {error} ) : null}
{isBusy ? : null} 生成宝贝识物草稿
); } export default BabyObjectMatchWorkspace;