"use client" import { type ReactNode, useMemo, useState } from "react" import Link from "next/link" import { usePathname, useRouter } from "next/navigation" import { LogOut, PlusCircle } from "lucide-react" import { toast } from "sonner" import { Button } from "@/components/ui/button" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { cn } from "@/lib/utils" import { useAuth, signOut } from "@/lib/auth-client" interface PortalShellProps { children: ReactNode } const navItems = [ { label: "Meus chamados", href: "/portal/tickets" }, { label: "Abrir chamado", href: "/portal/tickets/new", icon: PlusCircle }, ] export function PortalShell({ children }: PortalShellProps) { const pathname = usePathname() const router = useRouter() const { session, machineContext } = useAuth() const [isSigningOut, setIsSigningOut] = useState(false) const displayName = machineContext?.assignedUserName ?? session?.user.name ?? session?.user.email ?? "Cliente" const displayEmail = machineContext?.assignedUserEmail ?? session?.user.email ?? "" const personaLabel = machineContext?.persona === "manager" ? "Gestor" : "Colaborador" const initials = useMemo(() => { const name = displayName || displayEmail || "Cliente" return name .split(" ") .slice(0, 2) .map((part) => part.charAt(0).toUpperCase()) .join("") }, [displayName, displayEmail]) async function handleSignOut() { if (isSigningOut) return setIsSigningOut(true) toast.loading("Encerrando sessão...", { id: "portal-signout" }) try { await signOut() toast.success("Sessão encerrada", { id: "portal-signout" }) router.replace("/login") } catch (error) { console.error(error) toast.error("Não foi possível encerrar a sessão", { id: "portal-signout" }) } finally { setIsSigningOut(false) } } return (
Portal do cliente Raven
{initials}
{displayName} {displayEmail} {machineContext ? ( {personaLabel} ) : null}
{null} {children}
) }