"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const grid_1 = require("../../gravity-blocks/grid/index.js");
const sub_blocks_1 = require("../../sub-blocks/index.js");
const utils_1 = require("../../utils/index.js");
const FoldableListBlockItem_1 = require("./FoldableListBlockItem/FoldableListBlockItem.js");
const b = (0, utils_1.block)('FoldableList');
const FoldableListBlock = (props) => {
    const { title, text, additionalInfo, links, buttons, items, list } = props;
    const [opened, setOpened] = React.useState([0]);
    const toggleItem = (index) => {
        let newState;
        if (opened.includes(index)) {
            newState = opened.filter((itemIndex) => itemIndex !== index);
        }
        else {
            newState = [...opened, index];
        }
        setOpened(newState);
    };
    return ((0, jsx_runtime_1.jsx)("div", { className: b(), itemScope: true, children: (0, jsx_runtime_1.jsxs)(grid_1.Row, { children: [(0, jsx_runtime_1.jsx)(grid_1.Col, { sizes: { all: 12, md: 4 }, children: (0, jsx_runtime_1.jsx)("div", { className: b('title'), children: (0, jsx_runtime_1.jsx)(sub_blocks_1.Content, { title: title, text: text, additionalInfo: additionalInfo, links: links, list: list, buttons: buttons, colSizes: { all: 12, md: 12 } }) }) }), (0, jsx_runtime_1.jsx)(grid_1.Col, { sizes: { all: 12, md: 8 }, role: 'list', children: items.map(({ title: itemTitle, text: itemText, link, listStyle = 'dash' }, index) => {
                        const isOpened = opened.includes(index);
                        const onClick = () => toggleItem(index);
                        return ((0, jsx_runtime_1.jsx)(FoldableListBlockItem_1.FoldableListBlockItem, { title: itemTitle, text: itemText, link: link, listStyle: listStyle, isOpened: isOpened, onClick: onClick }, itemTitle));
                    }) })] }) }));
};
exports.default = FoldableListBlock;
//# sourceMappingURL=FoldableList.js.map
