import Module from "@Front/Config/Module";
import React, { useCallback, useEffect } from "react";

import HeaderLink from "../HeaderLink";
import classes from "./classes.module.scss";
import Rules, { RulesMode } from "@Front/Components/Elements/Rules";
import { AppRuleActions, AppRuleNames } from "@Front/Api/Entities/rule";
import { usePathname } from "next/navigation";
import Notifications from "@Front/Api/LeCoffreApi/Notary/Notifications/Notifications";
import Toasts from "@Front/Stores/Toasts";
export default function Navigation() {
	const pathname = usePathname();

	const getNotifications = useCallback(async () => {
		const notifications = await Notifications.getInstance().get({
			where: {
				read: false,
			},
		});
		notifications.forEach((notification) => {
			Toasts.getInstance().open({
				title: notification.notification.message,
				uid: notification.uid,
				redirectUrl: notification.notification.redirection_url,
			});
		});
	}, []);

	useEffect(() => {
		getNotifications();
	}, [pathname, getNotifications]);

	return (
		<div className={classes["root"]}>
			<HeaderLink
				text={"Dossiers en cours"}
				path={Module.getInstance().get().modules.pages.Folder.props.path}
				routesActive={[
					Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path,
					Module.getInstance().get().modules.pages.Folder.pages.CreateFolder.props.path,
				]}
			/>
			<HeaderLink
				text={"Dossiers archivés"}
				path={Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.props.path}
				routesActive={[Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.props.path]}
			/>
			<Rules
				mode={RulesMode.NECESSARY}
				rules={[
					{
						action: AppRuleActions.update,
						name: AppRuleNames.officeRoles,
					},
				]}>
				<HeaderLink
					text={"Collaborateurs"}
					path={Module.getInstance().get().modules.pages.Collaborators.props.path}
					routesActive={[Module.getInstance().get().modules.pages.Collaborators.props.path]}
				/>
			</Rules>
		</div>
	);
}
