"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
    default: ()=>/* binding */ Accordion_rslib_entry_
});
const react_namespaceObject = require("@chakra-ui/react");
const external_react_namespaceObject = require("react");
const external_AccordionIcon_js_namespaceObject = require("./AccordionIcon.js");
var external_AccordionIcon_js_default = /*#__PURE__*/ __webpack_require__.n(external_AccordionIcon_js_namespaceObject);
const Button_js_namespaceObject = require("../Button/Button.js");
var Button_js_default = /*#__PURE__*/ __webpack_require__.n(Button_js_namespaceObject);
function isMultiAccordion(openItems, allowMultiple) {
    return Array.isArray(openItems) && allowMultiple;
}
function isSingleAccordion(openItems, allowMultiple) {
    return 'number' == typeof openItems || void 0 === openItems || !allowMultiple;
}
const Accordion = ({ items = [], defaultIndex, allowToggle = true, allowMultiple = false, showCompleteStep, nextStepText = 'Next', completedSteps = [], omitNextButton = false, ...rest })=>{
    const [completedItems, setCompletedItems] = (0, external_react_namespaceObject.useState)(completedSteps);
    const [openItems, setOpenItems] = (0, external_react_namespaceObject.useState)(defaultIndex);
    (0, external_react_namespaceObject.useEffect)(()=>{
        setCompletedItems(completedSteps);
    }, [
        completedSteps?.length
    ]);
    return /*#__PURE__*/ React.createElement(react_namespaceObject.Box, {
        borderWidth: "1px",
        borderRadius: "lg",
        overflow: "hidden"
    }, /*#__PURE__*/ React.createElement(react_namespaceObject.Accordion, {
        index: openItems,
        allowMultiple: allowMultiple,
        allowToggle: allowToggle,
        ...rest
    }, items.map((item, index)=>/*#__PURE__*/ React.createElement(react_namespaceObject.AccordionItem, {
            key: `accordion-item-${index}`
        }, /*#__PURE__*/ React.createElement(react_namespaceObject.Heading, {
            as: "h2"
        }, /*#__PURE__*/ React.createElement(react_namespaceObject.AccordionButton, {
            "data-testid": `accordion-button-${index}`,
            onClick: ()=>{
                if (isMultiAccordion(openItems, allowMultiple)) setOpenItems(openItems?.includes(index) ? openItems.filter((item)=>item !== index) : [
                    ...new Set([
                        ...openItems,
                        index
                    ])
                ]);
                else if (isSingleAccordion(openItems, allowMultiple)) setOpenItems(openItems === index ? -1 : index); // When there is no item to be open, set to -1
            }
        }, /*#__PURE__*/ React.createElement(react_namespaceObject.Box, {
            "data-testid": `accordion-item-heading-${index}`,
            as: "span",
            flex: "1",
            textAlign: "left",
            fontWeight: "semibold",
            py: 2
        }, item.heading), showCompleteStep && index !== items.length - 1 && /*#__PURE__*/ React.createElement(external_AccordionIcon_js_default(), {
            isComplete: completedItems.includes(index)
        }), !showCompleteStep && /*#__PURE__*/ React.createElement(react_namespaceObject.AccordionIcon, null))), /*#__PURE__*/ React.createElement(react_namespaceObject.AccordionPanel, {
            pb: 4
        }, /*#__PURE__*/ React.createElement(react_namespaceObject.Box, {
            "data-testid": `accordion-item-description-${index}`
        }, item.description), showCompleteStep && !omitNextButton && index !== items.length - 1 && /*#__PURE__*/ React.createElement(Button_js_default(), {
            "data-testid": `accordion-complete-button-${index}`,
            mt: 6,
            isDisabled: isMultiAccordion(openItems, allowMultiple) ? openItems.includes(index + 1) : openItems === index + 1,
            variant: "outline",
            onClick: ()=>{
                setCompletedItems([
                    ...new Set([
                        ...completedItems,
                        index
                    ])
                ]);
                if (isMultiAccordion(openItems, allowMultiple)) setOpenItems([
                    ...new Set([
                        ...openItems,
                        index + 1
                    ])
                ]);
                else if (isSingleAccordion(openItems, allowMultiple)) setOpenItems(index + 1);
            }
        }, nextStepText))))));
};
/* ESM default export */ const Accordion_rslib_entry_ = Accordion;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
