"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = SubMenu;
const tslib_1 = require("tslib");
const react_1 = require("@headlessui/react");
const image_1 = tslib_1.__importDefault(require("next/image"));
const react_2 = tslib_1.__importStar(require("react"));
const Icon_1 = require("../assets/Icon");
const constant_1 = require("../constant");
const helper_1 = require("../helper");
const types_1 = require("../../types");
const constants_1 = require("../../../utils/constants");
const Skeleton_1 = require("../../Skeleton");
function SubMenu({ activityHistoryChild, currentMenuByPath, handleClickActivityHistoryChild, isActivityHistory, isShowSubmenu, loadingMenu, perCode, roleCodes, setShowSubMenu, sideBarType, subNavigation, subNavigationTriggerClicked, }) {
    const isIconWithLabelHorizontal = sideBarType === constant_1.SIDEBAR_TYPE.ICON_AND_LABEL_HORIZONTAL;
    const getCount = (count) => Number(count || 0);
    const shouldShowCount = (count) => getCount(count) > 0;
    const getCountText = (count) => (getCount(count) > 99 ? '99+' : getCount(count));
    const renderCountBadge = (count, className = '') => {
        if (!shouldShowCount(count))
            return null;
        return (react_2.default.createElement("span", { className: (0, types_1.classNames)('shadow-sm min-w-4 rounded-md bg-red-500 p-1 text-center text-[10px] font-semibold leading-none text-white', className) }, getCountText(count)));
    };
    const renderCountSlot = (count, className = '') => {
        if (!shouldShowCount(count))
            return null;
        return (react_2.default.createElement("span", { className: (0, types_1.classNames)('ml-auto inline-flex w-8 justify-end pr-1', className) }, renderCountBadge(count)));
    };
    return (react_2.default.createElement(react_1.Transition, { as: react_2.Fragment, enter: 'transform transition ease-in-out duration-[350ms]', enterFrom: '-translate-x-[10rem] opacity-0', enterTo: 'translate-x-0', leave: 'transform transition ease-in-out duration-[350ms]', leaveFrom: 'translate-x-0', leaveTo: '-translate-x-[10rem] opacity-0', show: isShowSubmenu },
        react_2.default.createElement("aside", { className: (0, types_1.classNames)('group hidden rounded-r-xl  px-2 pl-4 lg:block  lg:flex-shrink-0', isIconWithLabelHorizontal ? 'ml-[0.1rem]' : '-ml-[0.5rem]') },
            react_2.default.createElement("div", { className: (0, types_1.classNames)('relative flex h-full w-[12.4rem] flex-col overflow-y-auto overflow-x-hidden', isShowSubmenu ? 'block' : 'hidden') },
                react_2.default.createElement("div", { className: 'mt-4 flex w-full items-center justify-between px-2' },
                    react_2.default.createElement("h1", { className: 'text-sm font-semibold text-gray-900' }, isActivityHistory ? constants_1.TITLE_ACTIVITY_HISTORY : currentMenuByPath === null || currentMenuByPath === void 0 ? void 0 : currentMenuByPath.name),
                    ((isShowSubmenu && currentMenuByPath) || isActivityHistory) && (react_2.default.createElement("button", { className: 'group/child1 absolute -right-2 flex h-7 w-7 items-center justify-center rounded-md opacity-0 transition-all duration-300 hover:bg-white  group-hover:right-1.5 group-hover:opacity-100', onClick: () => setShowSubMenu(false), type: 'button' },
                        react_2.default.createElement(image_1.default, { alt: 'icon', className: 'group-hover/child1:brightness-50', height: 13, quality: 100, 
                            // @ts-ignore
                            src: Icon_1.IconV2.CLOSE_SIDEBAR, width: 13 })))),
                react_2.default.createElement("div", { className: 'mt-3 overflow-y-auto' },
                    subNavigation.map((item, subNavIndex) => {
                        const activeChildIndex = item.child.findIndex((c) => c.current);
                        const isChildActive = activeChildIndex !== -1;
                        return (react_2.default.createElement("div", { key: subNavIndex }, (roleCodes === null || roleCodes === void 0 ? void 0 : roleCodes.length) > 0 ? (react_2.default.createElement(react_2.default.Fragment, null, (0, helper_1.enablePer)(item.code, perCode) ? (react_2.default.createElement(react_2.default.Fragment, null,
                            (item === null || item === void 0 ? void 0 : item.isMicroservice) ? (react_2.default.createElement("a", { "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, "aria-hidden": true, className: (0, types_1.classNames)((item === null || item === void 0 ? void 0 : item.current)
                                    ? 'rounded-lg bg-white' // màu background menu cha khi active
                                    : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50', // màu background khi hover vào menu cha
                                'mx-3 flex cursor-pointer border-slate-200 p-2'), href: item.path }, !loadingMenu ? (react_2.default.createElement("div", { className: 'flex w-full items-center justify-between gap-x-2 text-xs' },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5', (item === null || item === void 0 ? void 0 : item.current) ? '' : 'font-normal text-[#353A44]') }, item === null || item === void 0 ? void 0 : item.name)),
                                renderCountSlot(item.requiredActionCount))) : (react_2.default.createElement(Skeleton_1.PHXSkeleton, { className: 'mr-3 flex-1', type: 'single' })))) : (react_2.default.createElement("div", { "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, "aria-hidden": true, className: (0, types_1.classNames)('rounded-lg', 'mb-1 flex cursor-pointer px-2 py-1.5', (item === null || item === void 0 ? void 0 : item.current) ? 'bg-white' : 'hover:bg-white'), onClick: () => subNavigationTriggerClicked(item) }, !loadingMenu ? (react_2.default.createElement("div", { className: 'flex w-full items-center justify-between gap-x-2 text-xs' },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-2' },
                                    react_2.default.createElement(image_1.default, { alt: 'icon', className: `${isChildActive || item.current ? ' brightness-[0.3]' : ''}`, height: 18, quality: 100, src: 
                                        // @ts-ignore
                                        Icon_1.IconV2[(0, helper_1.normalizeCode)(item.code)] ||
                                            // @ts-ignore
                                            Icon_1.IconV2[`${currentMenuByPath === null || currentMenuByPath === void 0 ? void 0 : currentMenuByPath.code}_OUTLINE`] ||
                                            Icon_1.IconV2.DASHBOARD_OUTLINE, width: 18 }),
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5', isChildActive || item.current
                                            ? 'font-medium text-gray-900'
                                            : 'font-normal text-gray-700') }, item === null || item === void 0 ? void 0 : item.name)),
                                renderCountSlot(item.requiredActionCount))) : (react_2.default.createElement(Skeleton_1.PHXSkeleton, { className: 'mr-3 flex-1', type: 'single' })))),
                            item.showChild && item.child && (react_2.default.createElement(react_2.default.Fragment, null, item.child.map((
                            // eslint-disable-next-line @typescript-eslint/no-shadow
                            children, childIndex) => (react_2.default.createElement("div", { key: childIndex, className: (0, types_1.classNames)('relative') },
                                childIndex <= activeChildIndex && (react_2.default.createElement("div", { className: `absolute  left-5 z-10  w-[1px] bg-gray-400 ${(children === null || children === void 0 ? void 0 : children.current) ? 'h-3' : 'bottom-0'} ${childIndex === 0 ? '-top-1' : ' top-0'}` })),
                                react_2.default.createElement("div", { className: `${childIndex === activeChildIndex ? 'block' : 'hidden'}` },
                                    react_2.default.createElement(image_1.default, { alt: 'icon', className: 'absolute left-5 top-0 h-6 w-3', height: 1, 
                                        // @ts-ignore
                                        src: Icon_1.IconV2.ARROW_RIGHT_SUB_MENU, width: 1 }),
                                    react_2.default.createElement("div", { className: 'absolute left-[21px]  top-0 z-10 h-4 w-[1px]  bg-white bg-opacity-50' })),
                                (children === null || children === void 0 ? void 0 : children.isMicroservice) ? (react_2.default.createElement("a", { "aria-hidden": true, className: (0, types_1.classNames)('my-0.5 block w-full rounded-lg px-2 text-[#353A44]', (children === null || children === void 0 ? void 0 : children.current) ? 'bg-white' : 'hover:bg-white', !(0, helper_1.enablePer)(children.code, perCode) ? 'bg-opacity-50 hover:bg-white/50' : ''), href: children.path, onClick: (0, helper_1.enablePer)(children.code, perCode) ? undefined : (e) => e.preventDefault() },
                                    react_2.default.createElement("div", { className: 'flex w-full flex-row items-center justify-between' },
                                        react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap py-[0.4375rem] pl-[2.4rem] pr-2 text-left text-xs', !(0, helper_1.enablePer)(children.code, perCode)
                                                ? 'cursor-not-allowed text-gray-400'
                                                : (children === null || children === void 0 ? void 0 : children.current)
                                                    ? 'font-medium text-gray-900'
                                                    : 'text-gray-700') }, children.name),
                                        renderCountSlot(children.requiredActionCount)))) : (react_2.default.createElement("button", { "aria-hidden": true, className: (0, types_1.classNames)('my-0.5 w-full rounded-lg px-2 text-[#353A44]', (children === null || children === void 0 ? void 0 : children.current) ? 'bg-white' : 'hover:bg-white', !(0, helper_1.enablePer)(children.code, perCode) ? 'bg-opacity-50 hover:bg-white/50' : ''), onClick: (0, helper_1.enablePer)(children.code, perCode)
                                        ? () => subNavigationTriggerClicked(children, item)
                                        : undefined, type: 'button' },
                                    react_2.default.createElement("div", { className: 'flex w-full flex-row items-center justify-between' },
                                        react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap py-[0.4375rem] pl-[2rem] pr-2 text-left text-xs', !(0, helper_1.enablePer)(children.code, perCode)
                                                ? 'cursor-not-allowed text-gray-400'
                                                : (children === null || children === void 0 ? void 0 : children.current)
                                                    ? 'font-medium text-gray-900'
                                                    : 'text-gray-700') }, children.name),
                                        renderCountSlot(children.requiredActionCount))))))))))) : (react_2.default.createElement("div", { "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, className: (0, types_1.classNames)((item === null || item === void 0 ? void 0 : item.current)
                                ? 'rounded-lg bg-white'
                                : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50', // hover:bg-white
                            'mb-1 flex cursor-not-allowed border-slate-200 px-2 py-1.5') }, !loadingMenu ? (react_2.default.createElement("div", { className: 'ml-1 flex min-w-0 items-center text-xs' },
                            react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-2' },
                                react_2.default.createElement(image_1.default, { alt: 'icon', className: 'brightness-0 invert-[70%]', height: 18, quality: 100, src: 
                                    // @ts-ignore
                                    Icon_1.IconV2[(0, helper_1.normalizeCode)(item.code)] ||
                                        // @ts-ignore
                                        Icon_1.IconV2[`${currentMenuByPath === null || currentMenuByPath === void 0 ? void 0 : currentMenuByPath.code}_OUTLINE`] ||
                                        Icon_1.IconV2.DASHBOARD_OUTLINE, width: 18 }),
                                react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5 text-gray-400') }, item === null || item === void 0 ? void 0 : item.name)),
                            react_2.default.createElement("p", { className: 'mt-1 text-slate-500' }, item === null || item === void 0 ? void 0 : item.description))) : (react_2.default.createElement(Skeleton_1.PHXSkeleton, { className: 'mr-3 flex-1', type: 'single' })))))) : (react_2.default.createElement(react_2.default.Fragment, null,
                            (item === null || item === void 0 ? void 0 : item.isMicroservice) ? (react_2.default.createElement("a", { "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, "aria-hidden": true, className: (0, types_1.classNames)((item === null || item === void 0 ? void 0 : item.current)
                                    ? 'rounded-lg bg-white' // màu background menu cha khi active
                                    : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50', // màu background khi hover vào menu cha
                                'mx-3 flex cursor-pointer border-slate-200 p-2'), href: item.path }, !loadingMenu ? (react_2.default.createElement("div", { className: 'flex w-full items-center justify-between gap-x-2 text-xs' },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5', (item === null || item === void 0 ? void 0 : item.current) ? '' : 'font-normal text-[#353A44]') }, item === null || item === void 0 ? void 0 : item.name)),
                                renderCountSlot(item.requiredActionCount))) : (react_2.default.createElement(Skeleton_1.PHXSkeleton, { className: 'mr-3 flex-1', type: 'single' })))) : (react_2.default.createElement("div", { "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, "aria-hidden": true, className: (0, types_1.classNames)((item === null || item === void 0 ? void 0 : item.current)
                                    ? 'rounded-lg bg-white' // màu background menu cha khi active
                                    : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50', // màu background khi hover vào menu cha
                                'mx-3 flex cursor-pointer border-slate-200 p-2'), onClick: () => subNavigationTriggerClicked(item) }, !loadingMenu ? (react_2.default.createElement("div", { className: 'flex w-full items-center justify-between gap-x-2 text-xs' },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5', (item === null || item === void 0 ? void 0 : item.current) ? '' : 'font-normal text-[#353A44]') }, item === null || item === void 0 ? void 0 : item.name)),
                                renderCountSlot(item.requiredActionCount))) : (react_2.default.createElement(Skeleton_1.PHXSkeleton, { className: 'mr-3 flex-1', type: 'single' })))),
                            item.showChild && item.child && (react_2.default.createElement(react_2.default.Fragment, null, item.child.map(
                            // eslint-disable-next-line @typescript-eslint/no-shadow
                            (children, index) => (react_2.default.createElement("div", { key: index, className: (0, types_1.classNames)('relative', (children === null || children === void 0 ? void 0 : children.current) && 'child-menu-active', (0, helper_1.checkChildBefore)(item.child, children) && 'child-menu-bef') }, (children === null || children === void 0 ? void 0 : children.isMicroservice) ? (react_2.default.createElement("a", { "aria-hidden": true, className: (0, types_1.classNames)('mx-3 flex cursor-pointer items-center justify-between border-slate-200 p-2 text-xs', (children === null || children === void 0 ? void 0 : children.current)
                                    ? 'rounded-lg bg-white text-gray-900 '
                                    : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50 hover:text-gray-900'), href: item.path },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("div", { className: 'w-3' }),
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('my-[0.05rem] ml-3 truncate whitespace-nowrap leading-5', (children === null || children === void 0 ? void 0 : children.current) ? 'font-semibold' : 'font-normal text-gray-600') }, children.name)),
                                renderCountSlot(children.requiredActionCount))) : (react_2.default.createElement("div", { "aria-hidden": true, className: (0, types_1.classNames)('mx-3 flex cursor-pointer items-center justify-between border-slate-200 p-2 text-xs', (children === null || children === void 0 ? void 0 : children.current)
                                    ? 'rounded-lg bg-white text-gray-900 '
                                    : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50 hover:text-gray-900'), onClick: () => subNavigationTriggerClicked(children, item) },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("div", { className: 'w-3' }),
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('my-[0.05rem] ml-3 truncate whitespace-nowrap leading-5', (children === null || children === void 0 ? void 0 : children.current) ? 'font-semibold' : 'font-normal text-gray-600') }, children.name)),
                                renderCountSlot(children.requiredActionCount))))))))))));
                    }),
                    !loadingMenu &&
                        activityHistoryChild.map((item, subNavIndex) => (react_2.default.createElement("div", { key: subNavIndex, "aria-current": (item === null || item === void 0 ? void 0 : item.current) ? 'page' : undefined, "aria-hidden": true, className: (0, types_1.classNames)((item === null || item === void 0 ? void 0 : item.current)
                                ? 'rounded-lg bg-white' // màu background menu cha khi active
                                : 'hover:rounded-lg hover:bg-white hover:bg-opacity-50', // màu background khi hover vào menu cha
                            'mx-3 mt-1 flex cursor-pointer border-slate-200 p-2'), onClick: () => {
                                handleClickActivityHistoryChild(item);
                                subNavigationTriggerClicked(item);
                            } },
                            react_2.default.createElement("div", { className: 'ml-1 flex min-w-0 items-center text-xs' },
                                react_2.default.createElement("div", { className: 'flex min-w-0 flex-1 items-center gap-x-3' },
                                    react_2.default.createElement("p", { className: (0, types_1.classNames)('truncate whitespace-nowrap leading-5', (item === null || item === void 0 ? void 0 : item.current) ? '' : 'font-normal text-[#353A44]') }, item === null || item === void 0 ? void 0 : item.name)),
                                react_2.default.createElement("p", { className: 'mt-1 text-slate-500' }, item === null || item === void 0 ? void 0 : item.description))))))))));
}
//# sourceMappingURL=submenu.js.map