"use client";
import { FolderKanban, Home, Mail, Package, ShieldCheck, User } from "lucide-react";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useTheme } from "next-themes";
import { useLocale, useTranslations } from "next-intl";
import { useEffect, useState, type ComponentType } from "react";
import { LocaleToggle } from "@/components/layout/locale-toggle";
import { SoundToggle } from "@/components/sound-toggle";
import { ThemeToggle } from "@/components/theme-toggle";
import { Dock, DockIcon } from "@/components/ui/dock";
import { buildAdminUrl } from "@/lib/admin-routing";
import { getLocalizedPath, stripLocalePrefix, type AppLocale } from "@/lib/locale";
import { cn } from "@/lib/utils";
type SiteDockProps = {
lightLogoUrl?: string | null;
darkLogoUrl?: string | null;
defaultLocale: AppLocale;
/**
* Server-computed via `isSuperAdmin()` in the parent layout. This client
* component only decides whether to *render* the Admin shortcut — it performs
* no auth check and grants no access; the real guard lives server-side on
* each admin page/action.
*/
isSuperAdmin?: boolean;
};
type NavItem = {
key: "home" | "about" | "portfolio" | "products" | "contact";
path: string;
Icon: ComponentType<{ className?: string }>;
disabled?: boolean;
};
const navItems: NavItem[] = [
{ key: "home", path: "", Icon: Home },
{ key: "about", path: "/about", Icon: User },
{ key: "portfolio", path: "/portfolio", Icon: FolderKanban },
{ key: "products", path: "/products", Icon: Package, disabled: true },
{ key: "contact", path: "/contact", Icon: Mail },
];
function isNavItemActive(currentPath: string, itemPath: string) {
if (itemPath === "/") {
return currentPath === "/";
}
return currentPath === itemPath || currentPath.startsWith(`${itemPath}/`);
}
function MenuClock({ locale }: { locale: string }) {
const [time, setTime] = useState("");
useEffect(() => {
const format = () =>
setTime(
new Date().toLocaleTimeString(locale === "ar" ? "ar" : locale, {
hour: "2-digit",
minute: "2-digit",
}),
);
format();
const id = setInterval(format, 20_000);
return () => clearInterval(id);
}, [locale]);
return (
{time || "--:--"}
);
}
export function SiteDock({
lightLogoUrl,
darkLogoUrl,
defaultLocale,
isSuperAdmin = false,
}: SiteDockProps) {
const locale = useLocale();
const pathname = usePathname();
const t = useTranslations("navigation");
const { theme, resolvedTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const isArabic = locale === "ar";
const currentPath = stripLocalePrefix(pathname);
const homeHref = getLocalizedPath(locale, "/", defaultLocale);
const adminHref = buildAdminUrl("/");
const activeTheme = theme === "system" ? resolvedTheme : theme;
const isDark = mounted && activeTheme === "dark";
const logoSrc = isDark
? darkLogoUrl || lightLogoUrl || "/logos/dark-primary.svg"
: lightLogoUrl || darkLogoUrl || "/logos/light-primary.svg";
const brandSubtitle = isArabic
? "مطوّر ويب · فريلانسر"
: "Webdesigner Bremen · Freelancer";
const controlButtonClassName =
"h-8 w-8 rounded-full border border-transparent text-foreground/70 hover:bg-accent hover:text-foreground";
return (
<>
{/* ===== Top menu bar (macOS-style utility strip) ===== */}