"use client"; // Barra lateral: recolhida em 72 px (só ícones) e expandida POR CIMA do conteúdo ao passar o mouse // ou ao navegar pelo teclado (regras .rail em globals.css). Os rótulos ficam sempre no DOM, então // leitores de tela os leem mesmo com a barra recolhida. // Geometria recolhida: cada item tem 48 px (72 − 2×12) e o ícone de 20 px fica em x 26–46, ou seja, // centrado na barra. Por isso os itens nunca podem crescer com o rótulo: a lista é flex em coluna // (uma trilha de grid "auto" cresceria até a largura do texto e empurraria o fundo do item ativo // para fora da barra) e o rótulo pode transbordar, invisível, dentro do item. // Em tela baixa (1024×768) a barra rola na vertical, para Configurações (no rodapé) não ficar cortada. import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState, type ComponentType } from "react"; import { CLIPPER_SECTIONS, activeSection } from "./clipper-shell"; import { ChartIcon, CubeIcon, FilmIcon, MicIcon, PublishIcon, ScissorsIcon, SettingsIcon, SparkIcon, TerminalIcon, UsersIcon } from "./icons"; import { LogoMark, Wordmark } from "./logo"; import { getSummary } from "./publishing-client"; import { cx } from "./ui"; type SubItem = { href: string; label: string; icon?: ComponentType<{ size?: number }> }; type NavItem = { href: string; label: string; hint: string; icon: ComponentType<{ size?: number }>; /** Subpáginas: aparecem abaixo do item, só com a barra expandida e o item ativo (regra .rail-sub em globals.css). */ children?: SubItem[]; /** Qual subitem está ativo para um caminho (padrão: o próprio href). */ activeChild?: (pathname: string) => string | null; }; /** Contador de "aguardando aprovação" no menu: relê a cada 30 s (só com a aba visível) e ao trocar de página. */ const SUMMARY_POLL_MS = 30_000; const NAV: NavItem[] = [ { href: "/dashboard", label: "Dashboard", hint: "O que funciona e o que não", icon: ChartIcon }, { href: "/", label: "Histórias", hint: "Episódios e votação", icon: FilmIcon }, { href: "/clipper", label: "Clipador", hint: "Cortes de live", icon: ScissorsIcon, children: CLIPPER_SECTIONS.map((s) => ({ href: s.href, label: s.label, icon: s.icon })), activeChild: (pathname) => activeSection(pathname)?.href ?? null, }, { href: "/characters", label: "Personagens", hint: "Elenco reaproveitável", icon: UsersIcon }, { href: "/assets", label: "Assets", hint: "Biblioteca e envios", icon: CubeIcon }, { href: "/voices", label: "Vozes", hint: "Narração e legenda", icon: MicIcon }, { href: "/agent", label: "Agente", hint: "Claude e Codex", icon: TerminalIcon }, ]; /** Depois do estúdio: onde as histórias vão ao ar. */ const DISTRIBUTION: NavItem[] = [ { href: "/accounts", label: "Canais de publicação", hint: "YouTube, TikTok e Instagram", icon: UsersIcon }, { href: "/publishing", label: "Publicações", hint: "Aprovar, agendar, acompanhar", icon: PublishIcon }, ]; const SETTINGS: NavItem = { href: "/settings", label: "Configurações", hint: "Horários, apps e navegador", icon: SettingsIcon }; function useAwaitingCount(pathname: string): number | null { const [count, setCount] = useState(null); useEffect(() => { let cancelled = false; const load = async () => { if (document.visibilityState === "hidden") return; const r = await getSummary(); if (!cancelled) setCount(r.ok ? r.data.awaitingApproval : null); }; void load(); const timer = setInterval(load, SUMMARY_POLL_MS); document.addEventListener("visibilitychange", load); return () => { cancelled = true; clearInterval(timer); document.removeEventListener("visibilitychange", load); }; }, [pathname]); return count; } function isActive(pathname: string, href: string): boolean { return href === "/" ? pathname === "/" || pathname.startsWith("/stories") : pathname.startsWith(href); } export function Sidebar() { const pathname = usePathname(); const awaiting = useAwaitingCount(pathname); return ( ); } function NavLink({ item, active, count = null, countLabel }: { item: NavItem; active: boolean; /** Número ao lado do ícone (some quando é 0 ou desconhecido). */ count?: number | null; countLabel?: string; }) { const { href, label, hint, icon: Icon, children } = item; const pathname = usePathname(); const showCount = count !== null && count > 0; // Com subpáginas: o item principal marca a seção; o subitem marca a página (aria-current fica no subitem). const activeChild = active && children ? item.activeChild?.(pathname) ?? null : null; const link = (