'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useEffect, useState } from 'react'; import { useT } from '@/components/locale-provider'; export type NavItem = { label: { en: string; sv: string }; href: string }; const CUSTOMER_NAV: NavItem[] = [ { label: { en: 'Overview', sv: 'Översikt' }, href: '/portal' }, { label: { en: 'Subscriptions', sv: 'Prenumerationer' }, href: '/portal/subscriptions' }, { label: { en: 'Documents', sv: 'Dokument' }, href: '/portal/dokument' }, { label: { en: 'Credits', sv: 'Krediter' }, href: '/portal/krediter' }, { label: { en: 'Integrations', sv: 'Integrationer' }, href: '/portal/integrationer' }, { label: { en: 'Settings', sv: 'Inställningar' }, href: '/portal/settings' }, ]; const ADMIN_NAV: NavItem[] = [ { label: { en: 'Overview', sv: 'Översikt' }, href: '/admin' }, { label: { en: 'Sources', sv: 'Källor' }, href: '/admin/sources' }, { label: { en: 'Jobs', sv: 'Jobb' }, href: '/admin/jobs' }, { label: { en: 'Tools', sv: 'Verktyg' }, href: '/admin/verktyg' }, { label: { en: 'Customers', sv: 'Kunder' }, href: '/admin/customers' }, ]; export function PortalShell({ variant, title, children, }: { variant: 'customer' | 'admin'; title: string; children: React.ReactNode; }) { const t = useT(); const pathname = usePathname(); const nav = variant === 'admin' ? ADMIN_NAV : CUSTOMER_NAV; const [email, setEmail] = useState(null); useEffect(() => { fetch('/api/auth/me') .then((r) => r.json()) .then((d) => setEmail(d?.user?.email ?? null)) .catch(() => {}); }, []); async function logout() { await fetch('/api/auth/logout', { method: 'POST' }).catch(() => {}); setEmail(null); } return (
{/* top bar */}
0pt {variant === 'admin' ? 'admin' : 'portal'}
{email ? ( <> {email} ) : ( {t({ en: 'Log in', sv: 'Logga in' })} )}
{/* sidebar */} {/* content */}

{title}

{children}
); } export function StatusPill({ status }: { status: string }) { const color = status === 'delivered' || status === 'accepted' ? 'var(--prov-3)' : status === 'in_production' || status === 'review' ? 'var(--accent-red)' : 'var(--muted-foreground)'; return ( {status} ); }