"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Accordion = void 0;
const react_1 = __importStar(require("react"));
const components_1 = require("../../components");
const icons_1 = require("../../icons");
const utils_1 = require("../../utils");
const inlines_1 = require("inlines");
const varsUtilities_1 = require("../../varsUtilities");
// todo, make onclick onclose props.onclick forgot how
const AccordionItem = ({ title, active, children, style, onClick, onClose, }) => {
    const [render, setRender] = (0, react_1.useState)(active);
    (0, react_1.useEffect)(() => {
        if (active) {
            setRender(true);
        }
        if (!active) {
            const timer = setTimeout(() => setRender(false), 300);
            clearTimeout(timer);
        }
    }, [active]);
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            height: 'auto',
            maxHeight: active ? '1000px' : '40px',
            minHeight: 40,
            transition: active ? '0.16s' : '0.16s',
            overflow: 'hidden',
            borderBottom: `1px solid ${(0, varsUtilities_1.color)('border', 'default', 'subtle')}`,
            '&:hover': {
                borderBottom: `1px solid ${(0, varsUtilities_1.color)('inputBorder', 'neutralHover', 'default')}`,
            },
            marginBottom: 8,
            [utils_1.BpTablet]: {
                '&:hover': null,
            },
            ...style,
        } },
        react_1.default.createElement(inlines_1.styled.div, { onClick: active ? onClose : onClick, style: {
                height: '40px',
                width: '100%',
                //   marginTop: '8px',
                padding: '10px 8px',
                //  paddingBottom: '18px',
                display: 'flex',
                alignItems: 'center',
                // userSelect: 'none',
                // WebkitUserSelect: 'none',
                backgroundColor: active
                    ? (0, varsUtilities_1.color)('action', 'neutral', 'subtleHover')
                    : 'inherit',
                gap: 8,
                cursor: 'pointer',
                '&:hover': {
                    backgroundColor: active
                        ? (0, varsUtilities_1.color)('action', 'neutral', 'subtleActive')
                        : (0, varsUtilities_1.color)('action', 'neutral', 'subtleHover'),
                },
                [utils_1.BpTablet]: {
                    '&:hover': null,
                },
                // '&:active': {
                //   backgroundColor: genColor('action', 'neutral', 'subtleHover'),
                // },
            } },
            react_1.default.createElement(icons_1.IconChevronDown, { style: {
                    transform: active ? 'rotate(180deg)' : 'rotate(0deg)',
                    transition: 'none',
                } }),
            react_1.default.createElement(components_1.Text, { selectable: "none" }, title ?? 'No titles???')),
        render && (react_1.default.createElement(components_1.ScrollArea, { style: {
                padding: '16px',
                paddingLeft: '36px',
                maxHeight: '800px',
                // '& div': {
                //   backgroundColor: 'yellow',
                // },
            } }, children))));
};
const Accordion = ({ data, active: activeFromProps, style, }) => {
    const [active, setActive] = (0, react_1.useState)(activeFromProps);
    const multi = active instanceof Array;
    return (react_1.default.createElement(inlines_1.styled.div, { style: { display: 'flex', flexDirection: 'column', ...style } }, data?.map((v, i) => {
        return (react_1.default.createElement(AccordionItem, { onClick: multi ? () => setActive([...active, i]) : () => setActive(i), onClose: multi
                ? () => setActive(active.filter((v) => v !== i))
                : () => setActive(null), active: multi ? active.includes(i) : active === i, key: v.title, title: v.title }, v.children));
    })));
};
exports.Accordion = Accordion;
//# sourceMappingURL=index.js.map