- Clipador em subpáginas (Cortes, Sessões, Fontes, Jogos, Ajustes) com moldura comum, lista + diálogo dos cortes e submenu na barra lateral. - Perfis de jogo (o que a IA sabe de cada jogo), parar pausa o monitor e idioma por fonte e por canal de publicação (migração v9: accounts.language). - Juiz: Gemini CLI como terceiro provedor e IA reserva por chamada — se a IA escolhida cair por cota, login, chave ou rede, a próxima da ordem de Configurações → IA responde (com pausa da que caiu). Lê data/ai/settings.json e o cofre data/ai/vault.bin (DPAPI) escritos pelo painel; contrato em doc/ia.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
187 lines
9.9 KiB
TypeScript
187 lines
9.9 KiB
TypeScript
"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<number | null>(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 (
|
||
<aside aria-label="Navegação"
|
||
className="rail fixed inset-y-0 left-0 z-50 flex flex-col overflow-x-hidden overflow-y-auto border-r border-line [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||
<Link href="/" className="mx-3 mt-4 mb-6 flex h-12 shrink-0 items-center gap-3 rounded-control px-[0.5rem]">
|
||
<LogoMark size={32} className="shrink-0" />
|
||
<Wordmark className="rail-label whitespace-nowrap" />
|
||
<span className="sr-only">— início</span>
|
||
</Link>
|
||
|
||
{/* Ação principal do produto, sempre à mão */}
|
||
<Link href="/#nova-historia"
|
||
className="group mx-3 mb-5 flex h-11 min-w-0 shrink-0 items-center gap-3 overflow-hidden rounded-control border border-accent/30 bg-accent-soft px-[0.8125rem] text-accent transition-colors hover:border-accent/60 hover:bg-accent/15">
|
||
<SparkIcon size={20} />
|
||
<span className="rail-label whitespace-nowrap text-sm font-semibold">Nova história com IA</span>
|
||
</Link>
|
||
|
||
<div className="rail-label mx-6 mb-2 text-eyebrow font-semibold uppercase whitespace-nowrap text-fg-subtle" aria-hidden="true">Estúdio</div>
|
||
<nav aria-label="Principal" className="flex flex-col gap-1 px-3">
|
||
{NAV.map((item) => <NavLink key={item.href} item={item} active={isActive(pathname, item.href)} />)}
|
||
</nav>
|
||
|
||
{/* Separador: com a barra recolhida, só a linha marca a troca de grupo. */}
|
||
<div aria-hidden="true" className="mx-6 mt-5 mb-4 h-px shrink-0 bg-line" />
|
||
<div className="rail-label mx-6 mb-2 text-eyebrow font-semibold uppercase whitespace-nowrap text-fg-subtle" aria-hidden="true">Distribuição</div>
|
||
<nav aria-label="Distribuição" className="flex flex-col gap-1 px-3">
|
||
{DISTRIBUTION.map((item) => (
|
||
<NavLink key={item.href} item={item} active={isActive(pathname, item.href)}
|
||
count={item.href === "/publishing" ? awaiting : null} countLabel="aguardando aprovação" />
|
||
))}
|
||
</nav>
|
||
|
||
<nav aria-label="Ajustes" className="mt-auto flex flex-col gap-1 px-3 pt-4">
|
||
<NavLink item={SETTINGS} active={isActive(pathname, SETTINGS.href)} />
|
||
</nav>
|
||
|
||
<div className="mt-3 mb-20 flex items-center gap-3 px-[1.9375rem] text-xs text-fg-subtle">
|
||
<span className="relative flex size-2.5 shrink-0" aria-hidden="true">
|
||
<span className="absolute inset-0 rounded-full bg-success/40" />
|
||
<span className="relative m-[2px] size-1.5 rounded-full bg-success" />
|
||
</span>
|
||
<span className="rail-label whitespace-nowrap">Painel local · porta 4500</span>
|
||
</div>
|
||
</aside>
|
||
);
|
||
}
|
||
|
||
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 = (
|
||
<Link href={href} aria-current={active && !children ? "page" : undefined}
|
||
className={cx(
|
||
"relative flex h-12 min-w-0 shrink-0 items-center gap-3 overflow-hidden rounded-control px-3.5 transition-colors",
|
||
active ? "bg-raised text-fg" : "text-fg-muted hover:bg-raised/70 hover:text-fg",
|
||
)}>
|
||
<span aria-hidden="true"
|
||
className={cx("absolute top-3 bottom-3 left-0 w-[3px] rounded-r-full bg-accent transition-opacity", active ? "opacity-100" : "opacity-0")} />
|
||
<span className={cx("relative shrink-0", active && "text-accent")}>
|
||
<Icon size={20} />
|
||
{/* Com a barra recolhida o número fica no canto do ícone; o texto completo vai para leitores de tela. */}
|
||
{showCount && (
|
||
<span aria-hidden="true"
|
||
className="absolute -top-2 -right-2.5 grid h-4 min-w-4 place-items-center rounded-full bg-accent px-1 text-[0.625rem] leading-none font-bold text-accent-fg tabular-nums">
|
||
{count > 99 ? "99+" : count}
|
||
</span>
|
||
)}
|
||
</span>
|
||
<span className="rail-label grid min-w-0 whitespace-nowrap leading-tight">
|
||
<span className="text-sm font-medium">{label}</span>
|
||
<span className="text-[0.6875rem] text-fg-subtle">{hint}</span>
|
||
</span>
|
||
{showCount && <span className="sr-only">: {count} {countLabel}</span>}
|
||
</Link>
|
||
);
|
||
if (!children || !active) return link;
|
||
return (
|
||
<div className="grid">
|
||
{link}
|
||
{/* Subpáginas: abrem com a barra (altura animada por grid-template-rows); recolhida, não ocupam espaço. */}
|
||
<div className="rail-sub">
|
||
<ul className="min-h-0 overflow-hidden" aria-label={`Seções de ${label}`}>
|
||
{children.map((c) => {
|
||
const on = activeChild === c.href;
|
||
const SubIcon = c.icon;
|
||
return (
|
||
<li key={c.href}>
|
||
<Link href={c.href} aria-current={on ? "page" : undefined}
|
||
className={cx("relative flex h-8 items-center gap-2.5 rounded-control py-1 pr-3 pl-[2.75rem] text-[0.8125rem] whitespace-nowrap transition-colors",
|
||
on ? "bg-raised/60 font-semibold text-fg" : "text-fg-subtle hover:bg-raised/40 hover:text-fg")}>
|
||
{/* Mesmo ícone da sub-navegação do topo do Clipador; sem ícone, um ponto. */}
|
||
{SubIcon
|
||
? <span aria-hidden="true" className={cx("flex shrink-0", on ? "text-accent" : "text-fg-subtle")}><SubIcon size={15} /></span>
|
||
: <span aria-hidden="true" className={cx("size-1.5 shrink-0 rounded-full", on ? "bg-accent" : "bg-line-strong")} />}
|
||
<span className="rail-label">{c.label}</span>
|
||
</Link>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|