"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 } = useAuth() const [isSigningOut, setIsSigningOut] = useState(false) const initials = useMemo(() => { const name = session?.user.name || session?.user.email || "Cliente" return name .split(" ") .slice(0, 2) .map((part) => part.charAt(0).toUpperCase()) .join("") }, [session?.user.name, session?.user.email]) 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 Sistema de chamados
{initials}
{session?.user.name ?? "Cliente"} {session?.user.email ?? ""}
{null} {children}
) }