"use client";
import { useState, useTransition } from "react";
import { Star, MessageSquare, Loader2, CheckCircle2, ChevronDown, ChevronUp } from "lucide-react";
function StarRating({ rating }: { rating: number }) {
return (
{[1, 2, 3, 4, 5].map((s) => (
))}
);
}
const TERRITORY_NAMES: Record = {
USA: "🇺🇸", TUR: "🇹🇷", GBR: "🇬🇧", DEU: "🇩🇪", FRA: "🇫🇷",
JPN: "🇯🇵", KOR: "🇰🇷", CHN: "🇨🇳", AUS: "🇦🇺", CAN: "🇨🇦",
BRA: "🇧🇷", IND: "🇮🇳", RUS: "🇷🇺", ESP: "🇪🇸", ITA: "🇮🇹",
};
export default function ReviewCard({ review }: { review: any }) {
const attr = review.attributes ?? {};
const [expanded, setExpanded] = useState(false);
const [showReply, setShowReply] = useState(false);
const [replyText, setReplyText] = useState("");
const [submitting, startTransition] = useTransition();
const [submitted, setSubmitted] = useState(false);
const [error, setError] = useState(null);
const bodyPreview = attr.body?.length > 140 ? attr.body.slice(0, 140) + "…" : attr.body;
function handleReply() {
setError(null);
startTransition(async () => {
const res = await fetch("/api/asc/review-response", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ reviewId: review.id, responseBody: replyText }),
});
if (res.ok) {
setSubmitted(true);
setShowReply(false);
setTimeout(() => setSubmitted(false), 3000);
} else {
const d = await res.json();
setError(d.error ?? "Gönderilemedi");
}
});
}
return (
{/* Header */}
{TERRITORY_NAMES[attr.territory] ?? ""} {attr.territory}
{attr.title && (
{attr.title}
)}
{attr.createdDate
? new Date(attr.createdDate).toLocaleDateString("tr-TR", {
month: "short", day: "numeric", year: "numeric",
})
: ""}
{/* Body */}
{expanded ? attr.body : bodyPreview}
{attr.body?.length > 140 && (
)}
{/* Reviewer */}
{attr.reviewerNickname && (
— {attr.reviewerNickname}
)}
{/* Reply section */}
{submitted ? (
Yanıt gönderildi
) : (
)}
{showReply && (
)}
);
}