export default async function handler(req, res) { if (req.method !== 'POST') { return res.status(405).json({ error: 'Method not allowed' }); } const { prompt } = req.body; const responses = [ { code: `import React, { useState } from 'react';\n\nexport default function TodoApp() {\n const [todos, setTodos] = useState([]);\n const [input, setInput] = useState('');\n\n const addTodo = () => {\n if (input.trim()) {\n setTodos([...todos, { id: Date.now(), text: input, done: false }]);\n setInput('');\n }\n };\n\n return (\n
\n

Todo App

\n
\n setInput(e.target.value)}\n className="flex-1 px-3 py-2 border rounded"\n placeholder="Add a task..."\n />\n \n
\n {todos.map(todo => (\n
\n \n {todo.text}\n
\n ))}\n
\n );\n}`, explanation: "I've created a Todo application with add functionality, state management, and a clean UI. The app uses React hooks for state and includes input validation." }, { code: `import React, { useState, useEffect } from 'react';\n\nexport default function WeatherDashboard() {\n const [city, setCity] = useState('San Francisco');\n const [weather, setWeather] = useState(null);\n\n useEffect(() => {\n // Simulated weather data\n setWeather({\n temp: 72,\n condition: 'Sunny',\n humidity: 45,\n wind: 12\n });\n }, [city]);\n\n return (\n
\n

Weather Dashboard

\n
{weather?.temp}°
\n
{weather?.condition}
\n
\n 💧 {weather?.humidity}%\n 💨 {weather?.wind} mph\n
\n
\n );\n}`, explanation: "Built a weather dashboard with a gradient design, simulated data fetching, and responsive layout. Features temperature display, conditions, and atmospheric data." }, { code: `import React, { useState } from 'react';\n\nexport default function Dashboard() {\n const [activeTab, setActiveTab] = useState('overview');\n const stats = [\n { label: 'Revenue', value: '$48,200', change: '+12.5%' },\n { label: 'Users', value: '2,847', change: '+8.2%' },\n { label: 'Orders', value: '1,423', change: '+23.1%' },\n ];\n\n return (\n
\n

Dashboard

\n
\n {stats.map(stat => (\n
\n
{stat.label}
\n
{stat.value}
\n
{stat.change}
\n
\n ))}\n
\n
\n );\n}`, explanation: "Created an analytics dashboard with stat cards, tab navigation, and a clean layout. Features KPI tracking with percentage changes and responsive grid." } ]; const randomResponse = responses[Math.floor(Math.random() * responses.length)]; // Simulate AI processing delay await new Promise(resolve => setTimeout(resolve, 1500)); res.status(200).json({ success: true, prompt, ...randomResponse }); }