"use client"; import { useState } from "react"; import { EmptyState } from "@/components/ui/EmptyState"; import { postComment, type EntityComment, type TechnicalInfoField } from "@/lib/meshkee"; type Tab = "specs" | "review" | "comments"; const TABS: { id: Tab; label: string }[] = [ { id: "specs", label: "مشخصات فنی" }, { id: "review", label: "نقد و بررسی" }, { id: "comments", label: "نظرات کاربران" }, ]; function formatDate(iso?: string) { if (!iso) return ""; return new Intl.DateTimeFormat("fa-IR", { dateStyle: "medium" }).format(new Date(iso)); } function CommentsPanel({ entityId, initialComments }: { entityId: string; initialComments: EntityComment[] }) { const [comments, setComments] = useState(initialComments); const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [text, setText] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); if (!name.trim() || !text.trim()) return; setBusy(true); setError(null); const res = await postComment({ entityType: "product", entityId, authorName: name.trim(), authorEmail: email.trim() || undefined, text: text.trim(), }); setBusy(false); if (!res.ok) { setError(res.message ?? "ثبت نظر ناموفق بود."); return; } setComments((prev) => [{ id: `local-${Date.now()}`, authorName: name.trim(), text: text.trim() }, ...prev]); setText(""); }; return (
setName(e.target.value)} className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none transition-colors focus:border-red" /> setEmail(e.target.value)} className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none transition-colors focus:border-red" />