"use client"; import Image from "next/image"; import Link from "next/link"; import { useState } from "react"; import { MEGA_MENU_TABS } from "@/data/home"; export type MegaColumn = { title: string; href: string; links: readonly { label: string; href: string }[]; }; export type MegaTabData = { id: string; nameFa: string; nameEn: string; href: string; image: string; /** Second-level categories as columns, each with third-level children */ columns?: readonly MegaColumn[]; /** Flat fallback when columns are not provided */ links?: readonly { label: string; href: string }[]; }; type ProductsMegaMenuProps = { open: boolean; onClose: () => void; tabs?: MegaTabData[]; }; function columnsForTab(tab: MegaTabData): MegaColumn[] { if (tab.columns?.length) return [...tab.columns]; if (tab.links?.length) { return [ { title: tab.nameFa, href: tab.href, links: tab.links, }, ]; } return []; } export default function ProductsMegaMenu({ open, onClose, tabs, }: ProductsMegaMenuProps) { const list = (tabs?.length ? tabs : MEGA_MENU_TABS) as MegaTabData[]; const [activeId, setActiveId] = useState(list[0]?.id ?? "coat"); const active = list.find((t) => t.id === activeId) ?? list[0]; if (!open || !active) return null; const columns = columnsForTab(active); return (
{list.map((tab) => { const selected = tab.id === active.id; return ( ); })}
{columns.map((col) => (
{col.title} {col.links.length > 0 ? (
    {col.links.map((link) => (
  • {link.label}
  • ))}
) : null}
))}
{list.map((tab) => (
))}
); }