"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useAuth } from "@/hooks/useAuth"; import { useHeaderSession } from "@/hooks/useHeaderSession"; import { useTenantHost } from "@/hooks/useTenantHost"; import { useTheme } from "@/hooks/useTheme"; import { Button, Container } from "@/components/ui"; import { useColorMode } from "@/components/providers/ColorModeProvider"; import { loadCommercialNotifications } from "@/modules/commercial/adapters"; import type { CommercialNotification } from "@/modules/commercial/types"; export function SiteHeader() { const { theme } = useTheme(); const host = useTenantHost(); const { login, loading, user } = useAuth(); const { isSsoAuth, isLoggedIn } = useHeaderSession(); const { mode, toggle } = useColorMode(); const isPlatformAdmin = user?.roles?.includes("platform_admin") || user?.roles?.includes("tenant_admin"); const brandName = host.isTenantHost ? theme?.site_name ?? "Workspace" : theme?.site_name ?? "Torbatyar"; const brandSub = host.isTenantHost ? "workspace روی تربت‌یار" : "Commercial SaaS Platform"; const [notifications, setNotifications] = useState([]); const [notifOpen, setNotifOpen] = useState(false); const [notifMsg, setNotifMsg] = useState(null); const [search, setSearch] = useState(""); useEffect(() => { if (!isLoggedIn || !isSsoAuth) return; void loadCommercialNotifications().then((r) => { if (r.availability === "ready") { setNotifications(r.data); setNotifMsg(null); } else { setNotifications([]); setNotifMsg(r.message || null); } }); }, [isLoggedIn, isSsoAuth]); const onSearch = (e: React.FormEvent) => { e.preventDefault(); const q = search.trim(); if (!q) { window.location.href = "/search"; return; } window.location.href = `/search?q=${encodeURIComponent(q)}`; }; return (
{brandName.charAt(0)}

{brandName}

{brandSub}

{isLoggedIn && isSsoAuth ? (
setSearch(e.target.value)} placeholder="جستجوی اپ‌ها…" className="w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-gray-700 dark:bg-gray-900" aria-label="جستجو" />
) : null}
); }