"use client";
import Image from "next/image";
import { useEffect, useState } from "react";
import type { ProductComment, ProductDetail } from "@/data/product-detail";
type TabId = "technical" | "comments" | "sizing";
const TABS: Array<{ id: TabId; labelFa: string; labelEn: string }> = [
{ id: "technical", labelFa: "مشخصات فنی", labelEn: "Technical info" },
{ id: "comments", labelFa: "نظرات", labelEn: "Comments" },
{ id: "sizing", labelFa: "راهنمای سایز", labelEn: "Sizing guide" },
];
type ProductTabsProps = {
product: ProductDetail;
initialTab?: TabId;
};
function Stars({ rating }: { rating: number }) {
return (
{"★".repeat(Math.max(0, Math.min(5, rating)))}
{"★".repeat(Math.max(0, 5 - rating))}
);
}
function CommentsList({ comments }: { comments: ProductComment[] }) {
if (!comments.length) {
return (
هنوز نظری ثبت نشده است.
);
}
return (
{comments.map((c) => (
-
{c.date}
{c.body}
))}
);
}
export default function ProductTabs({
product,
initialTab = "technical",
}: ProductTabsProps) {
const [tab, setTab] = useState(initialTab);
useEffect(() => {
const onHash = () => {
if (window.location.hash === "#product-tabs") {
setTab("sizing");
}
};
onHash();
window.addEventListener("hashchange", onHash);
return () => window.removeEventListener("hashchange", onHash);
}, []);
return (
{TABS.map((t) => {
const active = tab === t.id;
return (
);
})}
{tab === "technical" ? (
{product.description}
{product.technical.map((row) => (
-
{row.labelFa}
{row.labelEn}
- {row.value}
))}
) : null}
{tab === "comments" ? (
) : null}
{tab === "sizing" ? (
{product.sizeGuideImage ? (
) : (
Size guide image
)}
جدول اندازهها
Measurements (cm)
{product.sizeGuideNote}
| سایز |
سینه |
کمر |
قد |
{[
["S", "۸۸", "۷۰", "۹۲"],
["M", "۹۲", "۷۴", "۹۵"],
["L", "۹۶", "۷۸", "۹۸"],
["XL", "۱۰۰", "۸۲", "۱۰۰"],
].map((row) => (
{row.map((cell) => (
|
{cell}
|
))}
))}
) : null}
);
}