"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { motion, AnimatePresence } from "framer-motion"; import { Inbox, Send, FileText, Archive, AlertTriangle, Trash2, Settings, PenSquare, LogOut, Mail, ShieldCheck, Menu, X, } from "lucide-react"; import { useTranslations } from "../../../i18n/provider"; import { LanguageSwitcher } from "../../../i18n/LanguageSwitcher"; interface FolderCount { special_use: string; name: string; unread_count: number; } export default function UserWebmailLayout({ children }: { children: React.ReactNode }) { const t = useTranslations(); const pathname = usePathname(); const [folders, setFolders] = useState([]); const [mobileOpen, setMobileOpen] = useState(false); useEffect(() => { void fetch("/api/v1/mail/folders") .then((res) => (res.ok ? res.json() : [])) .then(setFolders) .catch(() => undefined); }, []); const unreadFor = (role: string) => folders.find((f) => f.special_use === role || f.name.toLowerCase() === role)?.unread_count ?? 0; const navItems = [ { href: "/user/mail/inbox", label: t("mail.inbox"), icon: Inbox, role: "inbox" }, { href: "/user/mail/sent", label: t("mail.sent"), icon: Send, role: "sent" }, { href: "/user/mail/drafts", label: t("mail.drafts"), icon: FileText, role: "drafts" }, { href: "/user/mail/archive", label: "Archive", icon: Archive, role: "archive" }, { href: "/user/mail/junk", label: "Spam", icon: AlertTriangle, role: "junk" }, { href: "/user/mail/trash", label: "Trash", icon: Trash2, role: "trash" }, ]; const handleLogout = () => { void fetch("/api/v1/auth/logout", { method: "POST" }).finally(() => { window.location.href = "/user/login"; }); }; const SidebarContent = (
{/* Webmail Surface Branding */}
LambdaMail
{t("common.userPortal")}
{/* Compose Floating Button */} {t("mail.compose")} {/* Folder Navigation List */}
{/* Footer Controls & User Settings */}
U
user@lambdamail.local
2FA Ativo
); return (
{/* Mobile Top Header */}
LambdaMail
{/* Desktop Sidebar */} {/* Mobile Overlay Menu */} {mobileOpen && ( {SidebarContent} )} {/* Main Content Area */}
{children}
); }