import useEntities from "@/hooks/useEntities";
import { EntityWithRoles } from "@/interfaces/entity";
import { User } from "@/interfaces/user";
import clsx from "clsx";
import { useRouter } from "next/router";
import { ToastContainer } from "react-toastify";
import Navbar from "../Navbar";
import Sidebar from "../Sidebar";

interface Props {
	user: User;
	entities?: EntityWithRoles[]
	children: React.ReactNode;
	className?: string;
	navDisabled?: boolean;
	focusMode?: boolean;
	hideSidebar?: boolean
	bgColor?: string;
	onFocusLayerMouseEnter?: () => void;
}

export default function Layout({
	user,
	children,
	className,
	bgColor = "bg-white",
	hideSidebar,
	navDisabled = false,
	focusMode = false,
	onFocusLayerMouseEnter
}: Props) {
	const router = useRouter();
	const { entities } = useEntities()

	return (
		<main className={clsx("w-full min-h-full h-screen flex flex-col bg-mti-gray-smoke relative")}>
			<ToastContainer />
			{!hideSidebar && user && (
				<Navbar
					path={router.pathname}
					user={user}
					navDisabled={navDisabled}
					focusMode={focusMode}
					onFocusLayerMouseEnter={onFocusLayerMouseEnter}
				/>
			)}
			<div className={clsx("h-full w-full flex gap-2")}>
				{!hideSidebar && user && (
					<Sidebar
						path={router.pathname}
						navDisabled={navDisabled}
						focusMode={focusMode}
						onFocusLayerMouseEnter={onFocusLayerMouseEnter}
						className="-md:hidden"
						user={user}
						entities={entities}
					/>
				)}
				<div
					className={clsx(
						`w-full min-h-full ${bgColor} shadow-md rounded-2xl p-4 xl:p-10 pb-8 flex flex-col gap-8 relative overflow-hidden mt-2`,
						bgColor !== "bg-white" ? "justify-center" : "h-fit",
						hideSidebar ? "md:mx-8" : "md:mr-8",
						className,
					)}>
					{children}
				</div>
			</div>
		</main>
	);
}
