import { useState } from 'react';
import { useDisclosure } from '@chakra-ui/react';

var drawerHandlerFactory = function (_a) {
    var nodeName = _a.nodeName, drawerNodeItems = _a.drawerNodeItems, isOpen = _a.isOpen, onOpen = _a.onOpen, onClose = _a.onClose, drawer = _a.drawer, setDrawer = _a.setDrawer;
    return function () {
        if (!isOpen) {
            setDrawer({
                nodes: drawerNodeItems[nodeName],
                current: nodeName,
            });
            onOpen();
            return;
        }
        if ((drawer === null || drawer === void 0 ? void 0 : drawer.current) !== nodeName) {
            onClose();
            // Note: can be wrapped in a set timeout for slideup and down variations
            setDrawer({
                nodes: drawerNodeItems[nodeName],
                current: nodeName,
            });
            onOpen();
            return;
        }
        onClose();
    };
};
var useNavigationDrawer = function (_a) {
    var drawerNodeItems = _a.drawerNodeItems;
    var _b = useState(null), drawer = _b[0], setDrawer = _b[1];
    var _c = useDisclosure(), isOpen = _c.isOpen, onOpen = _c.onOpen, onClose = _c.onClose;
    var createDrawerHandler = function (_a) {
        var nodeName = _a.nodeName;
        return drawerHandlerFactory({
            nodeName: nodeName,
            drawerNodeItems: drawerNodeItems,
            isOpen: isOpen,
            onOpen: onOpen,
            onClose: onClose,
            drawer: drawer,
            setDrawer: setDrawer,
        });
    };
    return { drawer: drawer, createDrawerHandler: createDrawerHandler, isOpen: isOpen, onOpen: onOpen, onClose: onClose };
};

export { drawerHandlerFactory, useNavigationDrawer };
//# sourceMappingURL=useNavigationDrawer.js.map
