import { useState, useEffect } from "react"; import Sidebar from "@/components/Sidebar"; import Tools from "@/components/Tools"; import Header from "@/components/Header"; import PythonRunner from "@/components/PythonRunner"; import Calculator from "@/components/Calculator"; import Browser from "@/components/Browser"; import WebDesign from "@/components/WebDesign"; import FileConverter from "@/components/FileConverter"; import LanguageTranslator from "@/components/LanguageTranslator"; import ApiIntegrator from "@/components/ApiIntegrator"; import { useAuth } from '@/hooks/useAuth'; import MCPImage from "@/components/Image/MCPImage"; type Props = { children: React.ReactNode; }; const MCPLayout = ({ children }: Props) => { const [activeId, setActiveId] = useState(null); const [visibleTools, setVisibleTools] = useState(true); const [visibleSidebar, setVisibleSidebar] = useState(false); const { user, isAuthenticated, canAccessChat, loading: authLoading } = useAuth(); console.log('[MCPLayout] Auth state:', { user, isAuthenticated, canAccessChat, authLoading }); // 权限检查 if (authLoading) { return (

加载中...

); } if (!isAuthenticated) { const mainAppUrl = process.env.NEXT_PUBLIC_MAIN_APP_URL || 'https://valuefrontier.cn'; return (

请先登录

您需要登录才能使用 AI 助手

前往登录
); } if (!canAccessChat) { const mainAppUrl = process.env.NEXT_PUBLIC_MAIN_APP_URL || 'https://valuefrontier.cn'; return (

需要订阅才能使用 AI 助手

升级到高级版解锁所有功能

当前订阅等级:{user?.subscription_type || '未订阅'}

查看订阅方案
); } return (
setVisibleSidebar(false)} onClickNewChat={() => setActiveId(null)} /> {/* 用户信息显示 */} {user && (
{user.avatar_url ? ( {user.username ) : (
{(user.username || user.nickname || 'U')[0].toUpperCase()}
)}

{user.username || user.nickname}

{user.subscription_type === 'max' ? '🌟 MAX会员' : user.subscription_type === 'premium' ? '💎 高级会员' : user.subscription_type === 'pro' ? '🚀 专业版' : '免费版'}

{user.subscription_days_left && user.subscription_days_left > 0 && (

剩余 {user.subscription_days_left} 天

)}
)}
setVisibleSidebar(true)} onToggleTools={() => setVisibleTools(!visibleTools)} /> {activeId === "python" ? ( ) : activeId === "calculator" ? ( ) : activeId === "browser" ? ( ) : activeId === "web-design" ? ( ) : activeId === "exchange" ? ( ) : activeId === "language" ? ( ) : activeId === "api" ? ( ) : ( children )}
setVisibleTools(!visibleTools)} />
); }; export default MCPLayout;