"use client"; import { Box, Burger, Button, Divider, Drawer, Stack, Text } from '@mantine/core'; import { usePathname } from 'next/navigation'; import Link from 'next/link'; import React, { useEffect, useState } from 'react'; import { useRouter } from "next/navigation"; import { useMediaQuery } from '@mantine/hooks'; import Image from "next/image"; import logo from "@/app/image/logo1.jpg"; export default function Layout({ children }: { children: React.ReactNode }) { const [authorized, SetAuthorized] = useState(null); const router = useRouter(); const pathname = usePathname(); const isMobile = useMediaQuery("(max-width: 768px)"); const [drawerOpened, setDrawerOpened] = useState(false); const links = [ { label: "View Profile", href: "/settings" }, { label: "Change Login Password", href: "/settings/change_login_password" }, { label: "Change transaction Password", href: "/settings/change_txn_password" }, { label: "Set transaction Password", href: "/settings/set_txn_password" }, { label: "Set userId", href: "/settings/user_id" }, ]; useEffect(() => { const token = localStorage.getItem("access_token"); if (!token) { SetAuthorized(false); router.push("/login"); } else { SetAuthorized(true); } }, []); if (authorized) { return ( {/* Desktop Sidebar */} {!isMobile && ( Settings {links.map((link) => { const isActive = pathname === link.href; return ( {link.label} ); })} )} {/* Mobile: Burger & Drawer */} {isMobile && ( <> {/* Top header with burger and title */} setDrawerOpened(!drawerOpened)} size="sm" color="white" /> Settings setDrawerOpened(false)} padding="md" size="75%" overlayProps={{ color: "black", opacity: 0.55, blur: 3 }} styles={{ root: { backgroundColor: "#e6f5ff", // soft background for drawer }, }} > {/* Logo and Drawer Header */} <> KCCB Logo Settings {/* Menu Items */} {links.map((link) => { const isActive = pathname === link.href; return ( ); })} )} {/* Content Area */} {children} ); } }