"use client"; import { Brain, CircleUser, Globe, Keyboard, KeyRound, Monitor, ReceiptText, ShieldCheck, Sparkles, Workflow, } from "lucide-react"; import dynamic from "next/dynamic"; import { useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import { useCallback, useEffect, useMemo, useState } from "react"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { usePlatform } from "@/hooks/use-platform"; import { cn } from "@/lib/utils"; const ProfileContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/ProfileContent").then( (m) => ({ default: m.ProfileContent }) ), { ssr: false } ); const ApiKeyContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/ApiKeyContent").then( (m) => ({ default: m.ApiKeyContent }) ), { ssr: false } ); const PromptsContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/PromptsContent").then( (m) => ({ default: m.PromptsContent }) ), { ssr: false } ); const CommunityPromptsContent = dynamic( () => import( "@/app/dashboard/[search_space_id]/user-settings/components/CommunityPromptsContent" ).then((m) => ({ default: m.CommunityPromptsContent })), { ssr: false } ); const PurchaseHistoryContent = dynamic( () => import( "@/app/dashboard/[search_space_id]/user-settings/components/PurchaseHistoryContent" ).then((m) => ({ default: m.PurchaseHistoryContent })), { ssr: false } ); const DesktopContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/DesktopContent").then( (m) => ({ default: m.DesktopContent }) ), { ssr: false } ); const DesktopShortcutsContent = dynamic( () => import( "@/app/dashboard/[search_space_id]/user-settings/components/DesktopShortcutsContent" ).then((m) => ({ default: m.DesktopShortcutsContent })), { ssr: false } ); const MemoryContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/MemoryContent").then( (m) => ({ default: m.MemoryContent }) ), { ssr: false } ); const AgentPermissionsContent = dynamic( () => import( "@/app/dashboard/[search_space_id]/user-settings/components/AgentPermissionsContent" ).then((m) => ({ default: m.AgentPermissionsContent })), { ssr: false } ); const AgentStatusContent = dynamic( () => import("@/app/dashboard/[search_space_id]/user-settings/components/AgentStatusContent").then( (m) => ({ default: m.AgentStatusContent }) ), { ssr: false } ); export type UserSettingsTab = | "profile" | "api-key" | "prompts" | "community-prompts" | "memory" | "agent-permissions" | "agent-status" | "purchases" | "desktop" | "desktop-shortcuts"; interface UserSettingsPanelProps { searchSpaceId: string; initialTab?: UserSettingsTab; } export function UserSettingsPanel({ searchSpaceId, initialTab = "profile", }: UserSettingsPanelProps) { const t = useTranslations("userSettings"); const router = useRouter(); const { isDesktop } = usePlatform(); const [activeTab, setActiveTab] = useState(initialTab); const [tabScrollPos, setTabScrollPos] = useState<"start" | "middle" | "end">("start"); useEffect(() => { setActiveTab(initialTab); }, [initialTab]); const handleTabScroll = useCallback((e: React.UIEvent) => { const el = e.currentTarget; const atStart = el.scrollLeft <= 2; const atEnd = el.scrollWidth - el.scrollLeft - el.clientWidth <= 2; setTabScrollPos(atStart ? "start" : atEnd ? "end" : "middle"); }, []); const navItems = useMemo( () => [ { value: "profile", label: t("profile_nav_label"), icon: }, { value: "api-key", label: t("api_key_nav_label"), icon: , }, { value: "prompts", label: "My Prompts", icon: , }, { value: "community-prompts", label: "Community Prompts", icon: , }, { value: "memory", label: "Memory", icon: , }, { value: "agent-permissions", label: "Agent Permissions", icon: , }, { value: "agent-status", label: "Agent Status", icon: , }, { value: "purchases", label: "Purchase History", icon: , }, ...(isDesktop ? [ { value: "desktop" as const, label: "App Preferences", icon: , }, { value: "desktop-shortcuts" as const, label: "Hotkeys", icon: , }, ] : []), ], [t, isDesktop] ); const selectedTab = navItems.some((item) => item.value === activeTab) ? activeTab : "profile"; const selectedLabel = navItems.find((item) => item.value === selectedTab)?.label ?? t("title"); const handleItemChange = (tab: UserSettingsTab) => { setActiveTab(tab); const suffix = tab === "profile" ? "" : `?tab=${tab}`; router.replace(`/dashboard/${searchSpaceId}/user-settings${suffix}`, { scroll: false }); }; return (

{t("title")}

{navItems.map((item) => ( ))}

{selectedLabel}

{selectedTab === "profile" && } {selectedTab === "api-key" && } {selectedTab === "prompts" && } {selectedTab === "community-prompts" && } {selectedTab === "memory" && } {selectedTab === "agent-permissions" && } {selectedTab === "agent-status" && } {selectedTab === "purchases" && } {selectedTab === "desktop" && } {selectedTab === "desktop-shortcuts" && }
); }