Repository Public
1"use client";2import Link from "next/link";3import { usePathname } from "next/navigation";4import { useEffect, useState, type ReactNode } from "react";5import { useLocale } from "@/i18n/client";6import { dict } from "@/i18n/dict";7import { api, setCsrf } from "@/lib/client-api";8import { LogoMark } from "@/components/brand";9import { LocaleSwitch, ModeToggle } from "@/components/site/controls";1011const T = dict({12 dashboard: ["Tableau de bord", "Dashboard"], create: ["Créer", "Create"], assets: ["Médias", "Media"], templates: ["Modèles", "Templates"],13 revisions: ["Historique", "History"], settings: ["Réglages", "Settings"], site: ["Voir le site", "View site"], signOut: ["Se déconnecter", "Sign out"], nav: ["Navigation du studio", "Studio navigation"],14});15const I = ({ d }: { d: string }) => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={d} /></svg>;16const ICONS = {17 dashboard: "M4 13h6V4H4zM14 20h6v-9h-6zM4 20h6v-3H4zM14 7h6V4h-6z", create: "M12 5v14M5 12h14", assets: "M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zM4 16l4.5-4.5 3.5 3.5 3-3 5 5",18 templates: "M4 5h16M4 5v14h16V5M4 10h16M10 10v9", revisions: "M12 8v4l3 2M4 12a8 8 0 1 0 2.5-5.8M4 4v4h4", settings: "M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19 12l2-1-2-4-2 1-2-1.2V4h-4v2.8L9 8 7 7 5 11l2 1v2l-2 1 2 4 2-1 2 1.2V22h4v-2.8l2-1.2 2 1 2-4-2-1z",19};2021/**22 * Studio frame. Desktop: a rail on the left. Phone: a tab bar at the bottom, above the home indicator, with the23 * primary action (create) in the middle. `bare` pages (the editor) take the whole viewport and draw their own bars.24 */25export function AdminShell({ csrfToken, children }: { csrfToken: string; children: ReactNode }) {26 setCsrf(csrfToken);27 const locale = useLocale(), t = T(locale), path = usePathname();28 const [busy, setBusy] = useState(false);29 useEffect(() => { setCsrf(csrfToken); }, [csrfToken]);30 const bare = /^\/admin\/sheets\/[^/]+\/edit/.test(path);31 const items = [["/admin", t.dashboard, ICONS.dashboard], ["/admin/assets", t.assets, ICONS.assets], ["/admin/sheets/new", t.create, ICONS.create], ["/admin/templates", t.templates, ICONS.templates], ["/admin/revisions", t.revisions, ICONS.revisions], ["/admin/settings", t.settings, ICONS.settings]] as const;32 const active = (href: string) => (href === "/admin" ? path === "/admin" : path.startsWith(href));33 const signOut = async () => { setBusy(true); try { await api("/api/auth/logout", { method: "POST", body: {} }); } finally { window.location.assign("/admin/login"); } };34 if (bare) return <>{children}</>;35 return (36 <div className="min-h-dvh md:pl-60">37 <aside className="fixed inset-y-0 left-0 z-30 hidden w-60 flex-col border-r border-line bg-surface md:flex">38 <Link href="/admin" className="flex h-14 items-center gap-2.5 border-b border-line px-5"><LogoMark size={26} /><span className="font-display text-xl font-semibold">Sheet</span><span className="eyebrow ml-1">Studio</span></Link>39 <nav aria-label={t.nav} className="flex-1 space-y-1 p-3">40 {[items[2], items[0], items[1], items[3], items[4], items[5]].map(([href, label, d]) => (41 <Link key={href} href={href} aria-current={active(href) ? "page" : undefined}42 className={`flex min-h-11 items-center gap-3 rounded-xl px-3 text-[0.9375rem] font-medium ${href === "/admin/sheets/new" ? "mb-3 bg-accent text-accent-ink" : active(href) ? "bg-raised text-ink" : "text-muted hover:bg-raised hover:text-ink"}`}>43 <I d={d} />{label}44 </Link>45 ))}46 </nav>47 <div className="flex items-center gap-1 border-t border-line p-3"><LocaleSwitch /><ModeToggle />48 <a href="/" className="btn btn-ghost btn-sm ml-auto">{t.site}</a></div>49 <button type="button" onClick={signOut} disabled={busy} className="m-3 mt-0 btn btn-sm">{t.signOut}</button>50 </aside>51 <header className="sticky top-0 z-30 flex h-14 items-center gap-1 border-b border-line bg-paper/90 px-4 backdrop-blur md:hidden" style={{ paddingTop: "env(safe-area-inset-top)", height: "calc(3.5rem + env(safe-area-inset-top))" }}>52 <Link href="/admin" className="mr-auto flex items-center gap-2"><LogoMark size={26} /><span className="font-display text-xl font-semibold">Sheet</span></Link>53 <LocaleSwitch /><ModeToggle /><button type="button" onClick={signOut} disabled={busy} className="btn btn-ghost btn-sm">{t.signOut}</button>54 </header>55 <main className="mx-auto max-w-[1180px] px-4 pb-28 pt-6 md:px-8 md:pb-12 md:pt-8">{children}</main>56 <nav aria-label={t.nav} className="fixed inset-x-0 bottom-0 z-30 grid grid-cols-6 border-t border-line bg-surface/95 backdrop-blur md:hidden" style={{ paddingBottom: "env(safe-area-inset-bottom)" }}>57 {[items[0], items[1], items[2], items[3], items[4], items[5]].map(([href, label, d]) => (58 <Link key={href} href={href} aria-current={active(href) ? "page" : undefined} className={`flex min-h-14 flex-col items-center justify-center gap-0.5 text-[0.625rem] font-medium ${active(href) ? "text-accent" : "text-muted"}`}>59 {href === "/admin/sheets/new" ? <span className="grid h-9 w-9 place-items-center rounded-full bg-accent text-accent-ink"><I d={d} /></span> : <><I d={d} />{label}</>}60 </Link>61 ))}62 </nav>63 </div>64 );65}66