"use client";
import {
Box,
useMantineTheme
} from "@mantine/core";
import { useAtom } from "jotai";
import { useRouter } from "next/navigation";
import React, { useState } from "react";
import { MODEL_USER } from "../home/model/interface";
import { MODEL_NOTIFIKASI } from "../notifikasi/model/interface";
import {
gs_admin_hotMenu,
gs_admin_subMenu,
gs_layout_admin_isNavbarOpen,
} from "./global_state";
export default function AdminLayout({
children,
listNotif,
dataUser,
countNotifikasi,
}: {
children: React.ReactNode;
listNotif: MODEL_NOTIFIKASI[];
dataUser: MODEL_USER;
countNotifikasi: number;
}) {
const theme = useMantineTheme();
const [opened, setOpened] = useState(false);
const router = useRouter();
const [activeId, setActiveId] = useAtom(gs_admin_hotMenu);
const [activeChild, setActiveChild] = useAtom(gs_admin_subMenu);
const [loading, setLoading] = useState(false);
const [user, setUser] = useState(dataUser);
const userRoleId = user.masterUserRoleId;
const [isNotif, setIsNotif] = useState(false);
const [dataNotif, setDataNotif] = useState(listNotif);
const [countNotif, setCountNotif] = useState(countNotifikasi);
const [isNavbarOpen, setIsNavbarOpen] = useAtom(gs_layout_admin_isNavbarOpen);
// const developerNavbar = listAdminPage.map((e, i) => (
//
// : e.icon : e.icon
// e.icon
// }
// label={{e.name}}
// onClick={() => {
// setLoading(true);
// setActiveId(e.id);
// setActiveChild(null);
// e.path === "" ? router.push(e.child[0].path) : router.push(e.path);
// e.path === "" ? setActiveChild(e.child[0].id) : "";
// }}
// >
// {_.isEmpty(e.child) ? (
// ""
// ) : (
//
// {e.child.map((v, ii) => (
//
// {v.name}}
// icon={
// activeChild === v.id ? (
//
// ) : (
//
// )
// }
// onClick={() => {
// setActiveId(e.id);
// setActiveChild(v.id);
// router.push(v.path);
// }}
// />
//
// ))}
//
// )}
//
//
// ));
// const bukanDeveloper = listAdminPage.slice(0, -1);
// const adminNavbar = bukanDeveloper.map((e) => (
//
// {e.name}}
// onClick={() => {
// setLoading(true);
// setActiveId(e.id);
// setActiveChild(null);
// e.path === "" ? router.push(e.child[0].path) : router.push(e.path);
// e.path === "" ? setActiveChild(e.child[0].id) : "";
// setIsNavbarOpen(true);
// }}
// >
// {_.isEmpty(e.child) ? (
// ""
// ) : (
//
// {e.child.map((v, ii) => (
//
// {v.name}}
// icon={
// activeChild === v.id ? (
//
// ) : (
//
// )
// }
// onClick={() => {
// setActiveId(e.id);
// setActiveChild(v.id);
// router.push(v.path);
// }}
// />
//
// ))}
//
// )}
//
//
// ));
// async function onLoadNotifikasi() {
// const loadNotif = await adminNotifikasi_getByUserId();
// setDataNotif(loadNotif as any);
// }
// useEffect(() => {
// mqtt_client.subscribe("ADMIN");
// mqtt_client.on("message", (topic: any, message: any) => {
// const data = JSON.parse(message.toString());
// // console.log(data);
// setCountNotif(countNotif + data.count);
// });
// }, [countNotif]);
return (
<>
{children}
{/*
padding="md"
navbarOffsetBreakpoint="md"
asideOffsetBreakpoint="sm"
header={
Dashboard Admin
{
setIsNotif(true);
// onLoadNotifikasi();
}}
>
{countNotif}}
>
{user?.username}
setOpened((o) => !o)}
size="sm"
color={theme.colors.gray[6]}
mr="xl"
/>
Dashboard Admin
}
navbar={
{userRoleId === "3" ? developerNavbar : adminNavbar}
V 1.0.0
}
>
{children}
*/}
{/* Drawer Mobile View */}
{/* setOpened(false)} size={"50%"}>
{listAdminPage.map((e) => (
router.push(e.path)}>
{e.name}
))}
*/}
{/* Drawer Notifikasi */}
{/*
Notifikasi
}
opened={isNotif}
onClose={() => setIsNotif(false)}
position="right"
size={"xs"}
>
{
setDataNotif(val);
}}
onChangeNavbar={(val: any) => {
setActiveId(val.id);
setActiveChild(val.childId);
}}
onToggleNavbar={setIsNavbarOpen}
onLoadCountNotif={(val: any) => {
setCountNotif(val);
}}
/>
*/}
>
);
}