import LogOutButton from "@Front/Components/DesignSystem/LogOutButton";
import Module from "@Front/Config/Module";
import React from "react";

import NavigationLink from "../../NavigationLink";
import classes from "./classes.module.scss";
import { AppRuleActions, AppRuleNames } from "@Front/Api/Entities/rule";
import BurgerModalSubmenu from "./BurgerModalSubmenu";
import Rules, { RulesMode } from "@Front/Components/Elements/Rules";

type IProps = {
	isOpen: boolean;
	closeModal: () => void;
};
type IState = {};

export default class BurgerModal extends React.Component<IProps, IState> {
	// TODO isEnabled depending on role given by DB
	public override render(): JSX.Element | null {
		if (!this.props.isOpen) return null;
		return (
			<>
				<div className={classes["background"]} onClick={this.props.closeModal} />
				<div className={classes["root"]}>
					<Rules
						mode={RulesMode.OPTIONAL}
						rules={[
							{
								action: AppRuleActions.read,
								name: AppRuleNames.officeFolders,
							},
						]}>
						<>
							<NavigationLink
								path={Module.getInstance().get().modules.pages.Folder.props.path}
								text="Dossiers en cours"
								routesActive={[
									Module.getInstance().get().modules.pages.Folder.pages.FolderInformation.props.path,
									Module.getInstance().get().modules.pages.Folder.pages.CreateFolder.props.path,
								]}
							/>
							<NavigationLink
								path={Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.props.path}
								text="Dossiers archivés"
								routesActive={[Module.getInstance().get().modules.pages.Folder.pages.FolderArchived.props.path]}
							/>
							<div className={classes["separator"]} />
						</>
					</Rules>

					<BurgerModalSubmenu
						text={"Espace super admin"}
						links={[
							{
								text: "Gestion des utilisateurs",
								path: Module.getInstance().get().modules.pages.Users.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.Users.pages.UsersInformations.props.path,
									Module.getInstance().get().modules.pages.Users.props.path,
								],
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.offices,
									},
								],
							},
							{
								text: "Gestion des offices",
								path: Module.getInstance().get().modules.pages.Offices.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.Offices.pages.OfficesInformations.props.path,
									Module.getInstance().get().modules.pages.Offices.props.path,
								],
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.offices,
									},
								],
							},
						]}
					/>
					<BurgerModalSubmenu
						text="Espace office"
						links={[
							{
								text: "Collaborateurs",
								path: Module.getInstance().get().modules.pages.Collaborators.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.Collaborators.pages.CollaboratorInformations.props.path,
									Module.getInstance().get().modules.pages.Collaborators.props.path,
								],
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.users,
									},
								],
							},
							{
								text: "Gestion des rôles",
								path: Module.getInstance().get().modules.pages.Roles.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.Roles.pages.Create.props.path,
									Module.getInstance().get().modules.pages.Roles.pages.RolesInformations.props.path,
									Module.getInstance().get().modules.pages.Roles.props.path,
								],
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.officeRoles,
									},
								],
							},
							{
								text: "Paramétrage des listes de pièces",
								path: Module.getInstance().get().modules.pages.DeedTypes.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.DeedTypes.pages.Create.props.path,
									Module.getInstance().get().modules.pages.DeedTypes.pages.Edit.props.path,
									Module.getInstance().get().modules.pages.DeedTypes.props.path,
									Module.getInstance().get().modules.pages.DocumentTypes.props.path,
									Module.getInstance().get().modules.pages.DocumentTypes.pages.Create.props.path,
									Module.getInstance().get().modules.pages.DocumentTypes.pages.Edit.props.path,
									Module.getInstance().get().modules.pages.DocumentTypes.pages.DocumentTypesInformations.props.path,
								],
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.deedTypes,
									},
								],
							},
							{
								text: "RIB Office",
								path: Module.getInstance().get().modules.pages.OfficesRib.props.path,
								rules: [
									{
										action: AppRuleActions.update,
										name: AppRuleNames.rib,
									},
								],
							},
							{
								text: "Abonnement",
								path: Module.getInstance().get().modules.pages.Subscription.pages.Manage.props.path,
								routesActive: [
									Module.getInstance().get().modules.pages.Subscription.pages.Error.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.Success.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.Invite.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.Manage.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.ManageCollaborators.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.New.props.path,
									Module.getInstance().get().modules.pages.Subscription.pages.Subscribe.props.path,
								],
							},
						]}
					/>
					<div className={classes["separator"]} />
					<NavigationLink path={Module.getInstance().get().modules.pages.MyAccount.props.path} text="Mon compte" />
					<NavigationLink target="_blank" path="/CGU_LeCoffre_io.pdf" text="CGU" />
					<LogOutButton />
				</div>
			</>
		);
	}
}
