"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const material_1 = require("@mui/material");
const react_core_1 = require("@selfcommunity/react-core");
const react_1 = require("react");
const Category_1 = tslib_1.__importDefault(require("../Category"));
const react_intl_1 = require("react-intl");
const utils_1 = require("@selfcommunity/utils");
const styles_1 = require("@mui/material/styles");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const system_1 = require("@mui/system");
const PREFIX = 'SCDefaultDrawerContent';
const classes = {
    root: `${PREFIX}-root`
};
const Root = (0, styles_1.styled)(material_1.Box, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (_, styles) => styles.root
})(() => ({}));
function DefaultDrawerContent(inProps) {
    const props = (0, system_1.useThemeProps)({
        props: inProps,
        name: PREFIX
    });
    const { className, CategoryItemProps = { showTooltip: true } } = props, rest = tslib_1.__rest(props, ["className", "CategoryItemProps"]);
    // HOOKS
    const { categories } = (0, react_core_1.useSCFetchCategories)();
    const [categoriesOrdered, setCategoriesOrdered] = (0, react_1.useState)([]);
    // ROUTING
    const scRoutingContext = (0, react_core_1.useSCRouting)();
    //STATE
    const [isHovered, setIsHovered] = (0, react_1.useState)({});
    // HANDLERS
    const handleMouseEnter = (index) => {
        setIsHovered((prevState) => {
            return Object.assign(Object.assign({}, prevState), { [index]: true });
        });
    };
    const handleMouseLeave = (index) => {
        setIsHovered((prevState) => {
            return Object.assign(Object.assign({}, prevState), { [index]: false });
        });
    };
    // Order categories
    (0, react_1.useEffect)(() => {
        setCategoriesOrdered((0, utils_1.sortByAttr)(categories, 'order'));
    }, [categories]);
    const getMouseEvents = (mouseEnter, mouseLeave) => ({
        onMouseEnter: mouseEnter,
        onMouseLeave: mouseLeave,
        onTouchStart: mouseEnter,
        onTouchMove: mouseLeave
    });
    //order
    return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ className: (0, classnames_1.default)(className, classes.root) }, rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, Object.assign({ variant: "subtitle1" }, { children: [(0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.navigationMenuIconButton.defaultDrawerContent.category.title", defaultMessage: "ui.navigationMenuIconButton.defaultDrawerContent.category.title" }) }), ' ', (0, jsx_runtime_1.jsx)(material_1.Button, Object.assign({ variant: "text", component: react_core_1.Link, color: "secondary", to: scRoutingContext.url(react_core_1.SCRoutes.CATEGORIES_LIST_ROUTE_NAME, {}) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.navigationMenuIconButton.defaultDrawerContent.category.seeAll", defaultMessage: "ui.navigationMenuIconButton.defaultDrawerContent.category.seeAll" }) }))] })), (0, jsx_runtime_1.jsx)(material_1.List, { children: categoriesOrdered.map((c, index) => ((0, jsx_runtime_1.jsx)(material_1.Zoom, Object.assign({ in: true, style: { transform: isHovered[c.id] && 'scale(1.05)' } }, { children: (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(Category_1.default, Object.assign({ ButtonBaseProps: { component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.CATEGORY_ROUTE_NAME, c) }, elevation: 0, category: c, actions: null }, CategoryItemProps, getMouseEvents(() => handleMouseEnter(c.id), () => handleMouseLeave(c.id)))) }, c.id) }), index))) })] })));
}
exports.default = DefaultDrawerContent;
