import { FolderKanban, Palette, Search, UserRound } from 'lucide-react'; import { type ComponentType, type FormEvent, lazy, Suspense, useCallback, useEffect, useState, } from 'react'; import { PlatformMudPointWalletEntry } from '../../../packages/shared/src/components/PlatformMudPointWalletEntry'; import { PlatformProfileRechargeModal } from '../../../packages/shared/src/components/PlatformProfileRechargeModal'; import { PlatformProfileWalletLedgerModal } from '../../../packages/shared/src/components/PlatformProfileWalletLedgerModal'; import type { ProfileDashboardSummary } from '../../../packages/shared/src/contracts/runtime'; import { pushAppHistoryPath, replaceAppHistoryPath, } from '../../routing/activeAppPageRoutes'; import { getPlatformProfileDashboard } from '../../services/platform-entry/platformProfileClient'; import { useAuthUi } from '../auth/AuthUiContext'; import { FLOATING_FEEDBACK_FORM_URL } from '../common/floatingFeedbackEntryModel'; import { resolveActivePublicUserCode, resolveActiveUserAvatarLabel, } from './platformActiveProfileModel'; import { PlatformActiveProfileView } from './PlatformActiveProfileView'; import type { PlatformEntryFlowShellProps } from './platformEntryActiveTypes'; import { usePlatformDesktopLayout } from './platformEntryResponsive'; import { PlatformProfileApiKeysModal } from './PlatformProfileApiKeysModal'; import { PlatformProfileReferralModal } from './PlatformProfileReferralModal'; import { PlatformProfileRewardCodeRedeemModal } from './PlatformProfileRewardCodeRedeemModal'; import { PlatformRechargePaymentConfirmationMask, PlatformRechargePaymentResultDialog, } from './PlatformRechargePaymentStatusDialogs'; import { usePlatformProfileCenterController } from './usePlatformProfileCenterController'; const ImageCanvasEditorView = lazy(async () => { const module = await import('../image-editor/ImageCanvasEditorView'); return { default: module.ImageCanvasEditorView }; }); const CreationLandingView = lazy(async () => { const module = await import('../creation-home/CreationLandingView'); return { default: module.CreationLandingView }; }); const ProjectGalleryView = lazy(async () => { const module = await import('../project/ProjectGalleryView'); return { default: module.ProjectGalleryView }; }); type ActiveRailButtonProps = { active: boolean; emphasized?: boolean; icon: ComponentType<{ className?: string }>; iconSrc: string; label: string; onClick: () => void; }; function ActiveRailButton({ active, emphasized = false, icon: Icon, iconSrc, label, onClick, }: ActiveRailButtonProps) { return ( ); } function ActiveBottomNavButton({ active, emphasized = false, icon: Icon, label, onClick, }: Omit) { return ( ); } function ActivePlatformBrand() { return ( 陶泥 GENARRATIVE ); } function LoadingPanel({ label }: { label: string }) { return (
{label}
); } export function PlatformEntryFlowShellImpl({ selectionStage, setSelectionStage, }: PlatformEntryFlowShellProps) { const authUi = useAuthUi(); const [dashboard, setDashboard] = useState( null, ); const [isLoadingDashboard, setIsLoadingDashboard] = useState(false); const [isApiKeysOpen, setIsApiKeysOpen] = useState(false); const [searchInput, setSearchInput] = useState(''); const [activeSearchKeyword, setActiveSearchKeyword] = useState(''); const isDesktopLayout = usePlatformDesktopLayout(); const refreshDashboard = useCallback(async () => { if (!authUi?.user || !authUi.canAccessProtectedData) { setDashboard(null); return; } setIsLoadingDashboard(true); try { setDashboard(await getPlatformProfileDashboard()); } catch { setDashboard(null); } finally { setIsLoadingDashboard(false); } }, [authUi?.canAccessProtectedData, authUi?.user]); useEffect(() => { void refreshDashboard(); }, [refreshDashboard]); const isProfileStage = selectionStage === 'profile'; const profileCenter = usePlatformProfileCenterController({ activeTab: isProfileStage ? 'profile' : 'project', isAuthenticated: Boolean(authUi?.user), showRechargeEntry: true, onRechargeSuccess: refreshDashboard, requestLogin: () => authUi?.openLoginModal(), currentUser: authUi?.user, }); const openCreation = useCallback(() => { pushAppHistoryPath('/creation'); setSelectionStage('creation-home', { path: '/creation' }); }, [setSelectionStage]); const openProjects = useCallback(() => { pushAppHistoryPath('/project'); setSelectionStage('project', { path: '/project' }); }, [setSelectionStage]); const openProfile = useCallback(() => { pushAppHistoryPath('/profile'); setSelectionStage('profile', { path: '/profile' }); }, [setSelectionStage]); const openEditorProject = useCallback( (projectId: string, options?: { guide?: boolean; tool?: string }) => { const params = new URLSearchParams(); params.set('projectid', projectId); if (options?.guide) { params.set('guide', 'toolbar'); } if (options?.tool) { params.set('tool', options.tool); } const path = `/editor/canvas?${params.toString()}`; pushAppHistoryPath(path); setSelectionStage('image-editor', { path }); }, [setSelectionStage], ); const replaceWithProjectGallery = useCallback(() => { replaceAppHistoryPath('/project'); setSelectionStage('project', { path: '/project' }); }, [setSelectionStage]); if (selectionStage === 'image-editor') { return (
}>
); } const isAuthenticated = Boolean(authUi?.user); const balance = dashboard?.walletBalance ?? profileCenter.rechargeCenter?.mudPointBalance?.totalPoints ?? profileCenter.rechargeCenter?.walletBalance ?? null; const isCreationStage = !isProfileStage && (selectionStage === 'platform' || selectionStage === 'creation-home'); const avatarUrl = authUi?.user?.avatarUrl?.trim() || null; const avatarLabel = resolveActiveUserAvatarLabel(authUi?.user); const publicUserCode = resolveActivePublicUserCode(authUi?.user); const openRecharge = () => { profileCenter.setIsRechargeOpen(true); profileCenter.loadRechargeCenter(); }; const openUserSurface = () => { if (isAuthenticated) { authUi?.openAccountModal(); return; } authUi?.openLoginModal(); }; const openFeedback = () => { window.open(FLOATING_FEEDBACK_FORM_URL, '_blank', 'noopener,noreferrer'); }; const submitSearch = (event: FormEvent) => { event.preventDefault(); const keyword = searchInput.trim(); setActiveSearchKeyword(keyword); if (isProfileStage) { openCreation(); } }; return ( <>
{isAuthenticated ? ( ) : null}
{isProfileStage ? ( authUi?.openLoginModal()} onOpenApiKeys={() => setIsApiKeysOpen(true)} onOpenCommunity={() => profileCenter.openProfilePopupPanel('community') } onOpenFeedback={openFeedback} onOpenRecharge={openRecharge} onOpenRewardCode={profileCenter.openRewardCodeModal} onOpenSettings={() => authUi?.openSettingsModal()} onOpenWalletLedger={profileCenter.openWalletLedgerPanel} onUserUpdated={(user) => authUi?.setCurrentUser(user)} /> ) : isCreationStage ? ( } > ) : ( }> )}
{profileCenter.isRechargeOpen ? ( profileCenter.setIsRechargeOpen(false)} onRetry={profileCenter.loadRechargeCenter} onBuy={profileCenter.buyRechargeProduct} onConfirmNativePayment={profileCenter.confirmNativeWechatPayment} onCloseNativePayment={profileCenter.closeNativeWechatPayment} /> ) : null} {profileCenter.isRewardCodeOpen ? ( profileCenter.setIsRewardCodeOpen(false)} /> ) : null} {profileCenter.profilePopupPanel ? ( ) : null} {isApiKeysOpen ? ( setIsApiKeysOpen(false)} /> ) : null} {profileCenter.isWalletLedgerOpen ? ( profileCenter.setIsWalletLedgerOpen(false)} onRetry={profileCenter.loadWalletLedger} /> ) : null} {profileCenter.rechargePaymentResult ? ( profileCenter.setRechargePaymentResult(null)} /> ) : null} {profileCenter.wechatRechargeOrderConfirmationState ? ( ) : null} ); } export default PlatformEntryFlowShellImpl;