"use client"; import Link from "next/link"; import { useState } from "react"; import { buildCategoryTree, categoryLabel } from "@/lib/meshkee/format"; import type { Category } from "@/lib/meshkee/types"; import { storeCategoryHref } from "@/lib/meshkee/urls"; export function ProductsMegaMenu({ categories }: { categories: Category[] }) { const [open, setOpen] = useState(false); const tree = buildCategoryTree(categories).filter( (node) => node.children.length > 0 || !node.parentId, ); const withChildren = tree.filter((node) => node.children.length > 0); const leafParents = tree.filter((node) => node.children.length === 0); return (
setOpen(true)} onMouseLeave={() => setOpen(false)} > setOpen(true)} aria-expanded={open} > محصولات {open ? (
{tree.length === 0 ? (

دسته‌بندی‌ای برای نمایش وجود ندارد.

) : ( <>
{withChildren.map((parent) => (
setOpen(false)} > {categoryLabel(parent)}
    {parent.children.map((child) => (
  • setOpen(false)} > {categoryLabel(child)}
  • ))}
))}
{leafParents.length > 0 ? (

More

    {leafParents.map((parent) => (
  • setOpen(false)} > {categoryLabel(parent)}
  • ))}
) : null} )}
) : null}
); }