import React, { useState, useEffect } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { useIsMobile } from '@/hooks/use-mobile'; import { ModernSidebar, SidebarBody } from '@/components/ui/modern-sidebar'; import { VerticalLimelightNav } from '@/components/ui/limelight-nav'; import OnboardingTour from '@/components/onboarding/OnboardingTour'; import HelpIcon from '@/components/help/HelpIcon'; import { useOnboardingTour } from '@/hooks/useOnboardingTour'; import { Home, Receipt, CreditCard, ListFilter, Target, Calendar, Crown, MessageSquareText, Users, Settings, LogOut, User } from 'lucide-react'; import { motion } from 'framer-motion'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Button } from '@/components/ui/button'; import { supabase } from '@/integrations/supabase/client'; import { useToast } from '@/hooks/use-toast'; import { useNavigate } from 'react-router-dom'; interface ModernLayoutProps { children: React.ReactNode; } const Logo = () => { return ( Finance Home Logo Finance Home ); }; const LogoIcon = () => { return ( Finance Home Logo ); }; export default function ModernLayout({ children }: ModernLayoutProps) { const [open, setOpen] = useState(false); const location = useLocation(); const isMobile = useIsMobile(); const { toast } = useToast(); const navigate = useNavigate(); const [userEmail, setUserEmail] = useState(''); const [dropdownOpen, setDropdownOpen] = useState(false); const { isOpen: tourOpen, currentStep, nextStep, skipTour, closeTour } = useOnboardingTour(); useEffect(() => { // Buscar dados do usuário logado const getUserData = async () => { const { data: { user } } = await supabase.auth.getUser(); if (user?.email) { setUserEmail(user.email); } }; getUserData(); }, []); const handleLogout = async () => { try { const { error } = await supabase.auth.signOut(); if (error) throw error; // Limpar localStorage localStorage.removeItem('userEmail'); toast({ title: "Logout realizado", description: "Você foi desconectado com sucesso" }); navigate('/auth'); } catch (error) { console.error('Erro no logout:', error); toast({ title: "Erro no logout", description: "Ocorreu um erro ao sair da conta", variant: "destructive" }); } }; const mainLinks = [ { id: "dashboard", label: "Dashboard", href: "/", icon: , }, { id: "transacoes", label: "Transações", href: "/transacoes", icon: , }, { id: "cartoes", label: "Cartões de Crédito", href: "/cartoes", icon: , }, { id: "categorias", label: "Categorias", href: "/categorias", icon: , }, { id: "metas", label: "Metas", href: "/metas", icon: , }, { id: "calendario", label: "Calendário", href: "/calendario", icon: , }, { id: "assinatura", label: "Assinatura", href: "/assinatura", icon: , } ]; const whatsappLinks = [ { id: "whatsapp", label: "Conectar WhatsApp", href: "/whatsapp", icon: , }, { id: "grupos", label: "Grupos", href: "/grupos-whatsapp", icon: , } ]; const configLinks = [ { id: "configuracoes", label: "Configurações", href: "/configuracoes", icon: , } ]; // Determine active index based on current route const getActiveIndex = () => { const allLinks = [...mainLinks, ...whatsappLinks, ...configLinks]; const activeIndex = allLinks.findIndex(link => link.href === location.pathname); return activeIndex >= 0 ? activeIndex : 0; }; return (
{open ? : }
{/* Main Navigation */}
{/* WhatsApp Section */}
{open && ( WhatsApp )} = mainLinks.length && getActiveIndex() < mainLinks.length + whatsappLinks.length ? getActiveIndex() - mainLinks.length : -1} showLabels={open} className="space-y-1" iconContainerClassName={!open ? "justify-center" : ""} />
{/* Config Section */}
{open && ( Configurações )} = mainLinks.length + whatsappLinks.length ? getActiveIndex() - mainLinks.length - whatsappLinks.length : -1} showLabels={open} className="space-y-1" iconContainerClassName={!open ? "justify-center" : ""} /> {/* User Profile */}
{ e.preventDefault(); e.stopPropagation(); setDropdownOpen(false); handleLogout(); }} className="flex items-center gap-2 text-red-600 hover:text-red-700 hover:bg-red-50 cursor-pointer" > Sair
{/* Main content */}
{children}
{/* Help Icon */} {/* Tour de Onboarding */}
); }