"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 (| {key} | {val === null || val === undefined ? "—" : String(val)} |
|---|
{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{description}
{technicalNotes}
{deliveryNotes}
COMMENTS
پس از ورود میتوانید تجربه خود از این محصول را با سایر خریداران به اشتراک بگذارید.
ورود / ثبتنام