"use client"; import { useMemo, useState, type ReactNode } from "react"; import { site } from "@/data/home"; type ProductTabsProps = { description?: string | null; technicalNotes?: string | null; deliveryNotes?: string | null; technicalValues?: unknown; }; type TabId = "description" | "technical" | "comments"; const tabMeta: Record< TabId, { label: string; labelEn: string } > = { description: { label: "توضیحات", labelEn: "Description" }, technical: { label: "مشخصات فنی", labelEn: "Technical Info" }, comments: { label: "نظرات", labelEn: "Comments" }, }; function renderTechnicalValues(value: unknown): ReactNode { if (value === null || value === undefined) return null; if (typeof value === "string") { return (

{value}

); } if (Array.isArray(value)) { if (value.length === 0) return null; return ( ); } if (typeof value === "object") { const entries = Object.entries(value as Record); if (entries.length === 0) return null; return (
{entries.map(([key, val]) => ( ))}
{key} {val === null || val === undefined ? "—" : String(val)}
); } return

{String(value)}

; } export function ProductTabs({ description, technicalNotes, deliveryNotes, technicalValues, }: ProductTabsProps) { const tabs = useMemo(() => { const items: { id: TabId; label: string; labelEn: string }[] = []; if (description?.trim()) { items.push({ id: "description", ...tabMeta.description }); } const hasTechnical = Boolean(technicalNotes?.trim()) || Boolean(deliveryNotes?.trim()) || (technicalValues !== null && technicalValues !== undefined && !(typeof technicalValues === "object" && !Array.isArray(technicalValues) && Object.keys(technicalValues as object).length === 0) && !(Array.isArray(technicalValues) && technicalValues.length === 0)); if (hasTechnical) { items.push({ id: "technical", ...tabMeta.technical }); } items.push({ id: "comments", ...tabMeta.comments }); return items; }, [deliveryNotes, description, technicalNotes, technicalValues]); const [activeTab, setActiveTab] = useState(tabs[0]?.id ?? "comments"); if (tabs.length === 0) return null; return (
{tabs.map((tab) => { const isActive = activeTab === tab.id; return ( ); })}
{activeTab === "description" && description ? (

{description}

) : null} {activeTab === "technical" ? (
{technicalNotes ? (

TECHNICAL NOTES

{technicalNotes}

) : null} {renderTechnicalValues(technicalValues)} {deliveryNotes ? (

DELIVERY

{deliveryNotes}

) : null}
) : null} {activeTab === "comments" ? (

COMMENTS

برای ثبت نظر وارد حساب کاربری شوید

پس از ورود می‌توانید تجربه خود از این محصول را با سایر خریداران به اشتراک بگذارید.

ورود / ثبت‌نام
) : null}
); }