"use client"; import { use, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Sparkles, ChevronRight, ChevronDown, Folder, FileText, Palette, LayoutGrid, Workflow, Github, RefreshCw, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { toast } from "sonner"; import { usePathname } from "next/navigation"; import { PageTemplate, PageSection, PageCard as TemplateCard, } from "@/components/layout/page-template"; // Mock tree structure - Core Product screens const coreProductTree = [ { id: "dashboard", name: "Dashboard", type: "folder", children: [ { id: "overview", name: "Overview", type: "page", route: "/dashboard", variations: 2 }, { id: "analytics", name: "Analytics", type: "page", route: "/dashboard/analytics", variations: 1 }, { id: "projects", name: "Projects", type: "page", route: "/dashboard/projects", variations: 2 }, { id: "activity", name: "Activity", type: "page", route: "/dashboard/activity", variations: 1 }, ], }, { id: "profile", name: "Profile & Settings", type: "folder", children: [ { id: "user-profile", name: "User Profile", type: "page", route: "/profile", variations: 2 }, { id: "edit-profile", name: "Edit Profile", type: "page", route: "/profile/edit", variations: 1 }, { id: "account", name: "Account Settings", type: "page", route: "/settings/account", variations: 1 }, { id: "billing", name: "Billing", type: "page", route: "/settings/billing", variations: 2 }, { id: "notifications", name: "Notifications", type: "page", route: "/settings/notifications", variations: 1 }, ], }, ]; // AI-suggested screens for Core Product const suggestedCoreScreens = [ { id: "team-management", name: "Team Management", reason: "Collaborate with team members and manage permissions", version: "V1", }, { id: "reports", name: "Reports & Insights", reason: "Data-driven decision making with comprehensive reports", version: "V2", }, { id: "integrations", name: "Integrations", reason: "Connect with external tools and services", version: "V2", }, { id: "search", name: "Global Search", reason: "Quick access to any content across the platform", version: "V2", }, { id: "empty-states", name: "Empty States", reason: "Guide users when no data is available", version: "V1", }, ]; // Mock tree structure - User Flows const userFlowsTree = [ { id: "authentication", name: "Authentication", type: "folder", children: [ { id: "signup", name: "Sign Up", type: "page", route: "/signup", variations: 3 }, { id: "login", name: "Login", type: "page", route: "/login", variations: 2 }, { id: "forgot-password", name: "Forgot Password", type: "page", route: "/forgot-password", variations: 1 }, { id: "verify-email", name: "Verify Email", type: "page", route: "/verify-email", variations: 1 }, ], }, { id: "onboarding", name: "Onboarding", type: "folder", children: [ { id: "welcome", name: "Welcome", type: "page", route: "/onboarding/welcome", variations: 2 }, { id: "setup-profile", name: "Setup Profile", type: "page", route: "/onboarding/profile", variations: 2 }, { id: "preferences", name: "Preferences", type: "page", route: "/onboarding/preferences", variations: 1 }, { id: "complete", name: "Complete", type: "page", route: "/onboarding/complete", variations: 1 }, ], }, ]; // AI-suggested flows/screens const suggestedFlows = [ { id: "password-reset", name: "Password Reset Flow", reason: "Users need a complete password reset journey", version: "V1", screens: [ { name: "Reset Request" }, { name: "Check Email" }, { name: "New Password" }, { name: "Success" }, ], }, { id: "email-verification", name: "Email Verification Flow", reason: "Enhance security with multi-step verification", version: "V2", screens: [ { name: "Verification Sent" }, { name: "Enter Code" }, { name: "Verified" }, ], }, { id: "two-factor-setup", name: "Two-Factor Auth Setup", reason: "Add additional security layer for users", version: "V2", screens: [ { name: "Enable 2FA" }, { name: "Setup Authenticator" }, { name: "Verify Code" }, { name: "Backup Codes" }, ], }, ]; const DESIGN_NAV_ITEMS = [ { title: "Core Screens", icon: LayoutGrid, href: "#screens" }, { title: "User Flows", icon: Workflow, href: "#flows" }, { title: "Style Guide", icon: Palette, href: "#style-guide" }, ]; export default function UIUXPage({ params }: { params: Promise<{ projectId: string }> }) { const { projectId } = use(params); const pathname = usePathname(); const workspace = pathname.split('/')[1]; // quick hack to get workspace const [prompt, setPrompt] = useState(""); const [selectedStyle, setSelectedStyle] = useState(null); const [isGenerating, setIsGenerating] = useState(false); // GitHub connection state const [isGithubConnected, setIsGithubConnected] = useState(false); const [githubRepo, setGithubRepo] = useState(null); const [lastSyncTime, setLastSyncTime] = useState(null); const [isSyncing, setIsSyncing] = useState(false); // Tree view state const [expandedFolders, setExpandedFolders] = useState>(new Set(["authentication", "dashboard"])); const toggleFolder = (folderId: string) => { const newExpanded = new Set(expandedFolders); if (newExpanded.has(folderId)) { newExpanded.delete(folderId); } else { newExpanded.add(folderId); } setExpandedFolders(newExpanded); }; const handleConnectGithub = async () => { toast.info("Opening GitHub OAuth..."); setTimeout(() => { setIsGithubConnected(true); setGithubRepo("username/repo-name"); toast.success("GitHub connected!", { description: "Click Sync to scan your repository", }); }, 1500); }; const handleSyncRepository = async () => { setIsSyncing(true); try { toast.info("Syncing repository...", { description: "AI is analyzing your codebase", }); const response = await fetch('/api/github/sync', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ projectId, repo: githubRepo, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Failed to sync repository'); } setLastSyncTime(new Date().toISOString()); toast.success("Repository synced!", { description: `Found ${data.pageCount} pages`, }); } catch (error) { console.error('Error syncing repository:', error); toast.error(error instanceof Error ? error.message : "Failed to sync repository"); } finally { setIsSyncing(false); } }; const handleGenerate = async () => { if (!prompt.trim()) { toast.error("Please enter a design prompt"); return; } setIsGenerating(true); try { const response = await fetch('/api/v0/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt, style: selectedStyle, projectId, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Failed to generate design'); } toast.success("Design generated successfully!", { description: "Opening in v0...", action: { label: "View", onClick: () => window.open(data.webUrl, '_blank'), }, }); window.open(data.webUrl, '_blank'); setPrompt(""); setSelectedStyle(null); } catch (error) { console.error('Error generating design:', error); toast.error(error instanceof Error ? error.message : "Failed to generate design"); } finally { setIsGenerating(false); } }; const sidebarItems = DESIGN_NAV_ITEMS.map((item) => { const fullHref = `/${workspace}/project/${projectId}/design${item.href}`; return { ...item, href: fullHref, isActive: pathname === fullHref || pathname.startsWith(fullHref), }; }); return (
{/* GitHub Connection / Sync */}
{!isGithubConnected ? ( <>

Connect Repository

Sync your GitHub repo to detect pages

) : ( <>

{githubRepo}

{lastSyncTime && (

Synced {new Date(lastSyncTime).toLocaleTimeString()}

)}
)}
{/* Product Screens - Split into two columns */}
{/* Core Product */} Core Product
{coreProductTree.map((folder) => (
{/* Folder */} {/* Pages in folder */} {expandedFolders.has(folder.id) && (
{folder.children.map((page: any) => ( ))}
)}
))} {/* AI Suggested Screens */}

AI Suggested

{suggestedCoreScreens.map((screen) => (
{screen.name}
{screen.version}
))}
{/* User Flows */} User Flows
{userFlowsTree.map((folder) => (
{/* Folder */} {/* Pages in folder - with flow indicators */} {expandedFolders.has(folder.id) && (
{folder.children.map((page: any, index: number) => (
))}
)}
))} {/* AI Suggested Flows */}

AI Suggested

{suggestedFlows.map((flow) => (
{/* Suggested screens in flow */} {expandedFolders.has(`suggested-${flow.id}`) && (
{flow.screens.map((screen: any, index: number) => (
{index + 1}
{screen.name}
))} {/* Generate button */}
)}
))}
); }