"use client"; import { useState } from "react"; import { useTranslations } from "next-intl"; import { Sparkles } from "lucide-react"; import { apiPostPublic, ApiClientError } from "@/lib/api/client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; type CoffeeAdvisorPick = { name: string; reason: string; menuItemId?: string | null; }; type CoffeeAdvisorResult = { summary: string; picks: CoffeeAdvisorPick[]; }; type CoffeeAdvisorPanelProps = { cafeSlug: string; }; export function CoffeeAdvisorPanel({ cafeSlug }: CoffeeAdvisorPanelProps) { const t = useTranslations("discoverPublic.coffeeAdvisor"); const [purpose, setPurpose] = useState(""); const [result, setResult] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const submit = async () => { const trimmed = purpose.trim(); if (trimmed.length < 3) return; setLoading(true); setError(null); setResult(null); try { const data = await apiPostPublic( "/api/public/coffee-advisor", { purpose: trimmed, cafeSlug } ); setResult(data); } catch (e) { if (e instanceof ApiClientError && e.code === "AI_NOT_CONFIGURED") { setError(t("notConfigured")); } else { setError(t("failed")); } } finally { setLoading(false); } }; return ( {t("title")}

{t("subtitle")}

setPurpose(e.target.value)} placeholder={t("placeholder")} onKeyDown={(e) => { if (e.key === "Enter" && !loading) void submit(); }} />
{error ? (

{error}

) : null} {result ? (

{result.summary}

{result.picks.length > 0 ? (
    {result.picks.map((pick) => (
  • {pick.name}

    {pick.reason}

  • ))}
) : null}
) : null}
); }