"use client"; import { ReactNode, useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { TenantSwitcher } from "@/components/TenantSwitcher"; import { Button } from "@/components/ui"; import { useAuth } from "@/hooks/useAuth"; import { useMe } from "@/hooks/useMe"; import { loadCommercialProducts } from "../adapters"; import type { CommercialProduct } from "../types"; import { resolveProductLaunchUrl } from "../types"; const CORE_NAV = [ { href: "/dashboard", label: "داشبورد" }, { href: "/apps", label: "اپ‌ها" }, { href: "/billing", label: "Billing" }, { href: "/domains", label: "دامنه" }, { href: "/notifications", label: "اعلان‌ها" }, { href: "/help", label: "راهنما" }, { href: "/dashboard/settings", label: "حساب" }, ]; /** Premium authenticated commercial OS shell — dynamic product links from registry. */ export function PlatformShell({ children, title, subtitle, }: { children: ReactNode; title?: string; subtitle?: string; }) { const pathname = usePathname(); const { signOut } = useAuth(); const { me, reload: reloadMe } = useMe(); const [products, setProducts] = useState([]); const [query, setQuery] = useState(""); const [mobileOpen, setMobileOpen] = useState(false); useEffect(() => { void loadCommercialProducts().then((r) => { if (r.availability === "ready") { setProducts(r.data.filter((p) => p.visibility !== "hidden")); } }); }, []); const filtered = products.filter((p) => { if (!query.trim()) return true; const q = query.trim().toLowerCase(); return ( p.display_name.toLowerCase().includes(q) || p.product_code.toLowerCase().includes(q) || (p.category || "").toLowerCase().includes(q) ); }); const navLink = (href: string, label: string) => { const active = pathname === href || pathname.startsWith(`${href}/`); return ( setMobileOpen(false)} className={`rounded-xl px-3 py-2 text-sm transition ${ active ? "bg-primary text-white shadow-sm" : "text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-800" }`} > {label} ); }; const sidebar = (

Workspace

جستجو

setQuery(e.target.value)} placeholder="محصول / دسته…" className="mx-2 mt-2 rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-900" />

Apps

ارزیابی مجدد
); return (
{title ?

{title}

: null}
{mobileOpen ? (
{sidebar}
) : null}
{title ? (

{title}

) : null} {subtitle ?

{subtitle}

: null}
{me ? ( void reloadMe()} /> ) : null}
{children}
); }