"use client"; import { use, useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Separator } from "@/components/ui/separator"; import { Textarea } from "@/components/ui/textarea"; import { Eye, MessageSquare, Copy, Share2, Sparkles, History, Loader2, Send, MousePointer2 } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { ScrollArea } from "@/components/ui/scroll-area"; import { toast } from "sonner"; import { cn } from "@/lib/utils"; // Mock data for page variations const mockPageData: Record = { "landing-hero": { name: "Landing Page Hero", emoji: "✨", style: "modern", prompt: "Create a modern landing page hero section with gradient background", v0Url: "https://v0.dev/chat/abc123", variations: [ { id: 1, name: "Version 1 - Blue Gradient", thumbnail: "https://placehold.co/800x600/1e40af/ffffff?text=Hero+V1", createdAt: "2025-11-11", views: 45, comments: 3, }, { id: 2, name: "Version 2 - Purple Gradient", thumbnail: "https://placehold.co/800x600/7c3aed/ffffff?text=Hero+V2", createdAt: "2025-11-10", views: 32, comments: 2, }, { id: 3, name: "Version 3 - Minimal", thumbnail: "https://placehold.co/800x600/6b7280/ffffff?text=Hero+V3", createdAt: "2025-11-09", views: 28, comments: 1, }, ], }, "dashboard": { name: "Dashboard Layout", emoji: "📊", style: "minimal", prompt: "Design a clean dashboard with sidebar, metrics cards, and charts", v0Url: "https://v0.dev/chat/def456", variations: [ { id: 1, name: "Version 1 - Default", thumbnail: "https://placehold.co/800x600/7c3aed/ffffff?text=Dashboard+V1", createdAt: "2025-11-10", views: 78, comments: 8, }, ], }, "pricing": { name: "Pricing Cards", emoji: "💳", style: "colorful", prompt: "Three-tier pricing cards with features, hover effects, and CTA buttons", v0Url: "https://v0.dev/chat/ghi789", variations: [ { id: 1, name: "Version 1 - Standard", thumbnail: "https://placehold.co/800x600/059669/ffffff?text=Pricing+V1", createdAt: "2025-11-09", views: 102, comments: 12, }, { id: 2, name: "Version 2 - Compact", thumbnail: "https://placehold.co/800x600/0891b2/ffffff?text=Pricing+V2", createdAt: "2025-11-08", views: 67, comments: 5, }, ], }, "user-profile": { name: "User Profile", emoji: "👤", style: "modern", prompt: "User profile page with avatar, bio, stats, and activity feed", v0Url: "https://v0.dev/chat/jkl012", variations: [ { id: 1, name: "Version 1 - Default", thumbnail: "https://placehold.co/800x600/dc2626/ffffff?text=Profile+V1", createdAt: "2025-11-08", views: 56, comments: 5, }, ], }, }; export default function DesignPageView({ params, }: { params: Promise<{ projectId: string; pageSlug: string }>; }) { const { projectId, pageSlug } = use(params); const pageData = mockPageData[pageSlug] || mockPageData["landing-hero"]; const [editPrompt, setEditPrompt] = useState(""); const [isGenerating, setIsGenerating] = useState(false); const [currentVersion, setCurrentVersion] = useState(pageData.variations[0]); const [versionsModalOpen, setVersionsModalOpen] = useState(false); const [commentsModalOpen, setCommentsModalOpen] = useState(false); const [chatMessage, setChatMessage] = useState(""); const [pageName, setPageName] = useState(pageData.name); const [isEditingName, setIsEditingName] = useState(false); const [designModeActive, setDesignModeActive] = useState(false); const [selectedElement, setSelectedElement] = useState(null); const handleIterate = async () => { if (!editPrompt.trim()) { toast.error("Please enter a prompt to iterate"); return; } setIsGenerating(true); try { // Call v0 API to generate update const response = await fetch('/api/v0/iterate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chatId: pageData.v0Url.split('/').pop(), message: editPrompt, projectId, }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || 'Failed to iterate'); } toast.success("Design updated!", { description: "Your changes have been generated", }); // Refresh or update the current version setEditPrompt(""); } catch (error) { console.error('Error iterating:', error); toast.error(error instanceof Error ? error.message : "Failed to iterate design"); } finally { setIsGenerating(false); } }; const handlePushToCursor = () => { toast.success("Code will be pushed to Cursor", { description: "This feature will send the component code to your IDE", }); // TODO: Implement actual push to Cursor IDE }; return ( <>
{/* Toolbar */}
{isEditingName ? ( setPageName(e.target.value)} onBlur={() => { setIsEditingName(false); toast.success("Page name updated"); }} onKeyDown={(e) => { if (e.key === 'Enter') { setIsEditingName(false); toast.success("Page name updated"); } }} className="text-lg font-semibold bg-transparent border-b border-primary outline-none px-1 min-w-[200px]" autoFocus /> ) : (

setIsEditingName(true)} > {pageName}

)}
{/* Live Preview */}
{/* Sample SaaS Dashboard Component */}
{/* Page Header */}
{ if (designModeActive) { e.stopPropagation(); setSelectedElement("page-header"); } }} >

{ if (designModeActive) { e.stopPropagation(); setSelectedElement("page-title"); } }} > Dashboard Overview

Welcome back! Here's what's happening today.

{/* Stats Grid */}
{ if (designModeActive) { e.stopPropagation(); setSelectedElement("stats-grid"); } }} > {[ { label: "Total Users", value: "2,847", change: "+12.3%", trend: "up" }, { label: "Revenue", value: "$45,231", change: "+8.1%", trend: "up" }, { label: "Active Projects", value: "127", change: "-2.4%", trend: "down" }, { label: "Conversion Rate", value: "3.24%", change: "+0.8%", trend: "up" }, ].map((stat, i) => ( { if (designModeActive) { e.stopPropagation(); setSelectedElement(`stat-card-${i}`); } }} > {stat.label} {stat.value} {stat.change} ))}
{/* Data Table */} { if (designModeActive) { e.stopPropagation(); setSelectedElement("data-table"); } }} >
Recent Projects Your team's latest work
{[ { name: "Mobile App Redesign", status: "In Progress", team: "Design Team", updated: "2 hours ago" }, { name: "API Documentation", status: "Review", team: "Engineering", updated: "5 hours ago" }, { name: "Marketing Website", status: "Completed", team: "Marketing", updated: "1 day ago" }, { name: "User Dashboard v2", status: "Planning", team: "Product", updated: "3 days ago" }, ].map((project, i) => (
{ if (designModeActive) { e.stopPropagation(); setSelectedElement(`table-row-${i}`); } }} >

{project.name}

{project.team}

{project.status} {project.updated}
))}
{/* Floating Chat Interface - v0 Style */}
{/* Input Area */}