import { AnimatePresence, motion } from "framer-motion";
import { useEffect, useState } from "react";
import { MenuList } from "@features/sidebar";
import { MakeOrderButton, PersonalAccount } from "@entities/sidebar";
import { LogotypeIcon } from "@shared/images";
import { useScreenResolution } from "@shared/libs/global";
import { BurgerIcon, HorizontalLine } from "@shared/ui";
import classes from "./Sidebar.module.scss";
const initialSidebarAnimate = {
x: -100,
opacity: 0,
};
const animateSidebarAnimate = {
x: 0,
opacity: 1,
};
const exitSidebarAnimate = {
x: -100,
opacity: 0,
};
const transitionSidebarAnimate = {
x: -100,
opacity: 0,
};
export const Sidebar = () => {
const [active, setActive] = useState<boolean>(false);
const [isMobile, setIsMobile] = useState(false);
const mobile = useScreenResolution();
const handlerBurgerMenu = () => setActive((state) => !state);
useEffect(() => {
setIsMobile(mobile);
}, [mobile]);
return (
<>
<BurgerIcon onClick={handlerBurgerMenu} active={active} />
<AnimatePresence>
{(!isMobile || (isMobile && active)) && (
<motion.header
transition={transitionSidebarAnimate}
initial={initialSidebarAnimate}
animate={animateSidebarAnimate}
exit={exitSidebarAnimate}
className={classes.headerSidebar}
>
<LogotypeIcon className={classes.logotypeSidebar} />
<MakeOrderButton className={classes.orderButton} />
<HorizontalLine />
<MenuList className={classes.menuList} />
<HorizontalLine />
<PersonalAccount className={classes.personalAccount} />
</motion.header>
)}
</AnimatePresence>
</>
);
};