import React, { Fragment } from 'react';
import TranslationProvider from '../translationProvider/index.js';
import GridItem from '../grid/GridItem.js';
import Grid from '../grid/index.js';
import { Divider } from '@chakra-ui/react';
import CheckboxWithFacet from './CheckboxWithFacet.js';
import CheckboxGroupCollapsibleWithChildren from './CheckboxGroupCollapsibleWithChildren.js';

var groupItems = function (items, numberOfColumns) {
    if (numberOfColumns === void 0) { numberOfColumns = 1; }
    var groupedItems = [];
    var itemsPerColumn = Math.ceil(items.length / numberOfColumns);
    for (var i = 0; i < numberOfColumns; i++) {
        var start = i * itemsPerColumn;
        var end = start + itemsPerColumn;
        groupedItems.push(items.slice(start, end));
    }
    return groupedItems;
};
function CheckboxFilter(_a) {
    var _b = _a.alwaysExpanded, alwaysExpanded = _b === void 0 ? false : _b, items = _a.items, onApply = _a.onApply, _c = _a.numberOfColumnsOnDesktop, numberOfColumnsOnDesktop = _c === void 0 ? 1 : _c, onToggleCheckboxGroup = _a.onToggleCheckboxGroup, language = _a.language;
    var hasGroups = items.some(function (item) { var _a; return ((_a = item.childCheckboxes) !== null && _a !== void 0 ? _a : []).length > 0; });
    var groupedItems = groupItems(items, numberOfColumnsOnDesktop);
    return (React.createElement(TranslationProvider, { language: language, scopes: ['checkboxFilter'] },
        React.createElement(Grid, { gridTemplateColumns: {
                base: '1fr',
                md: "repeat(".concat(numberOfColumnsOnDesktop, ", 1fr)"),
            }, gap: { md: '4xl' } }, groupedItems.map(function (columnItems, columnIndex) { return (React.createElement(GridItem, { key: columnIndex, "data-testid": "column", position: "relative" },
            groupedItems.length - 1 !== columnIndex && (React.createElement(Divider, { position: "absolute", top: 0, right: "-1.5rem", width: "1px", height: "full", bg: "gray.100" })),
            columnItems.map(function (item) { return (React.createElement(Fragment, { key: item.key }, item.childCheckboxes && item.childCheckboxes.length > 0 ? (React.createElement(CheckboxGroupCollapsibleWithChildren, { alwaysExpanded: alwaysExpanded, item: item, onApply: onApply, onToggleCheckboxGroup: onToggleCheckboxGroup })) : (React.createElement(CheckboxWithFacet, { item: item, onApply: onApply, indentFacet: hasGroups && !alwaysExpanded })))); }))); }))));
}

export { CheckboxFilter as default };
//# sourceMappingURL=index.js.map
