"use client"; import { useState, useTransition } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { AlertCircle, ArrowRight, BarChart3, Radar, ShieldAlert, Sparkles } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { competitorAnalysisSchema, sectorRequestSchema, type CompetitorAnalysis, type SectorRequest } from "@/lib/schema"; const sampleAnalysis: CompetitorAnalysis = { sector_overview: "Plant-based protein foods remain a sizable but uneven category, with growth concentrating in formats that balance taste, nutrition, and everyday use. Buyers are more selective than they were during the category’s hype cycle, rewarding brands that can prove repeat purchase and margin discipline. The structural dynamic is that mainstream adoption depends on price, product quality, and retailer confidence all improving at the same time.", key_players: [ { name: "Beyond Meat", positioning: "Category pioneer with strong awareness in retail and foodservice plant-based meat.", market_tier: "leader", key_weakness: "Sustained revenue pressure and uneven distribution have reduced its room for error." }, { name: "Impossible Foods", positioning: "Technology-forward challenger focused on meat-like flavor and broad U.S. availability.", market_tier: "challenger", key_weakness: "It still contends with consumer skepticism around processed formulations." }, { name: "Oatly", positioning: "Brand-led oat milk specialist with strong cafe and grocery recognition.", market_tier: "challenger", key_weakness: "Its tighter category focus limits coverage outside the dairy-alternative set." }, { name: "Hodo", positioning: "Whole-food niche brand known for premium tofu and cleaner-label protein products.", market_tier: "niche", key_weakness: "Its narrower scale constrains mass-market reach." } ], emerging_trends: [ { trend: "Clean-label reformulation", description: "Brands are simplifying ingredients and reducing sodium or saturated fat to counter ultra-processed perceptions. This is strongest where products still need to win over mainstream shoppers.", relevance_to_entrant: "A new entrant can build around this consumer expectation from the start.", confidence: "high" }, { trend: "Flexitarian-first positioning", description: "Messaging is shifting away from ideology and toward taste, convenience, and protein. Buyers increasingly include mixed-diet households rather than only strict vegans.", relevance_to_entrant: "The easiest wedge is often a mainstream use case, not a niche identity segment.", confidence: "high" }, { trend: "Retailers favor velocity over assortment breadth", description: "Shelf space is tightening, and weaker SKUs are being removed faster than before. Winning products need clearer differentiation and repeat demand.", relevance_to_entrant: "The GTM plan should be narrow, measurable, and retailer-friendly.", confidence: "medium" } ], white_spaces: [ { opportunity: "Affordable clean-label center-of-plate proteins", rationale: "There is still room between highly processed analogs and premium whole-food specialists. A product that stays simple but delivers better texture and price can occupy that middle." }, { opportunity: "Convenience-led refrigerated meal components", rationale: "Many buyers want easy weeknight formats rather than hero burgers alone. Strips, crumbles, snack packs, and deli-led formats better fit habitual consumption." } ], data_confidence: { overall_rating: "medium", flagged_uncertainties: [ "Private-company market share is often opaque.", "Category growth rates vary materially by geography and subsegment." ] } }; type ApiState = { analysis: CompetitorAnalysis | null; error: string | null; }; function MarketTierBadge({ value }: { value: CompetitorAnalysis["key_players"][number]["market_tier"] }) { return ( {value} ); } function ConfidenceBadge({ value }: { value: "high" | "medium" | "low" }) { return ( {value} ); } export function DashboardShell() { const [isPending, startTransition] = useTransition(); const [apiState, setApiState] = useState({ analysis: sampleAnalysis, error: null }); const form = useForm({ resolver: zodResolver(sectorRequestSchema), defaultValues: { sector: "", geography: "", customerType: "", focus: "" } }); const onSubmit = form.handleSubmit((values) => { startTransition(async () => { setApiState((current) => ({ ...current, error: null })); try { const response = await fetch("/api/analyze", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(values) }); const payload = await response.json(); if (!response.ok) { throw new Error(payload.error || "Request failed."); } const analysis = competitorAnalysisSchema.parse(payload); setApiState({ analysis, error: null }); } catch (error) { setApiState({ analysis: null, error: error instanceof Error ? error.message : "Unexpected request error." }); } }); }); return (
Competitive Intelligence Engine
Sector dashboard for fast competitor analysis. Submit a sector request and return structured market intelligence that matches your analysis schema.

Typed API contract and structured response rendering.

Mobile-first layout in a restrained black-and-white visual system.

Ready for a real LLM-backed analysis service behind the route.

Request Analysis Provide the target sector and optional commercial context for a sharper output.
{form.formState.errors.sector ? (

{form.formState.errors.sector.message}

) : null}