(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../ListHeader", "../ListItem", "../../../hooks/useStateProps", "./styles"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var ListHeader_1 = (0, tslib_1.__importDefault)(require("../ListHeader"));
    var ListItem_1 = (0, tslib_1.__importDefault)(require("../ListItem"));
    var useStateProps_1 = require("../../../hooks/useStateProps");
    var styles_1 = require("./styles");
    var List = (0, react_1.forwardRef)(function (_a, ref) {
        var header = _a.header, dataSource = _a.dataSource, viewType = _a.viewType, className = _a.className, classNameItem = _a.classNameItem, onClickItem = _a.onClickItem, style = _a.style, styleItem = _a.styleItem, renderItem = _a.renderItem, renderSelectAllItems = _a.renderSelectAllItems, _b = _a.isSelected, isSelected = _b === void 0 ? false : _b, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, _d = _a.isShowSelectAll, isShowSelectAll = _d === void 0 ? false : _d, onDoubleClickItem = _a.onDoubleClickItem, width = _a.width, height = _a.height, _e = _a.size, size = _e === void 0 ? "l" : _e, children = _a.children, props = (0, tslib_1.__rest)(_a, ["header", "dataSource", "viewType", "className", "classNameItem", "onClickItem", "style", "styleItem", "renderItem", "renderSelectAllItems", "isSelected", "isDisabled", "isShowSelectAll", "onDoubleClickItem", "width", "height", "size", "children"]);
        var _f = (0, tslib_1.__read)((0, useStateProps_1.useStateProps)(isSelected), 2), isExpand = _f[0], setIsExpand = _f[1];
        var handleClickHeader = function (event) {
            var _a;
            setIsExpand(!isExpand);
            (_a = header === null || header === void 0 ? void 0 : header.onClick) === null || _a === void 0 ? void 0 : _a.call(header, event);
        };
        var renderItems = function () {
            if (!children) {
                if (renderItem) {
                    return dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item, index) { return renderItem(item, index); });
                }
                return dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (item) { return (react_1.default.createElement(ListItem_1.default, (0, tslib_1.__assign)({}, item, { size: size, key: item.label, className: classNameItem, style: styleItem, isSelected: item.isSelected, isDisabled: isDisabled || item.isDisabled, onDoubleClick: onDoubleClickItem, onClick: onClickItem }), item.label)); });
            }
            return children;
        };
        return (react_1.default.createElement(styles_1.ListStyled, (0, tslib_1.__assign)({ className: className, style: style, ref: ref, width: width, height: height }, props),
            header && (react_1.default.createElement(ListHeader_1.default, { size: size, viewType: viewType, isDisabled: isDisabled, onClick: handleClickHeader, isSelectedDefault: isExpand, leadIcon: header.leadIcon, trailIcon: header.trailIcon, className: header.className, style: header.style, avatar: header.avatar }, header.content)),
            react_1.default.createElement(styles_1.ListItemsWrapper, { isExpand: isExpand, isHeader: Boolean(header), type: viewType },
                react_1.default.createElement(react_1.default.Fragment, null,
                    isShowSelectAll && renderSelectAllItems && renderSelectAllItems(),
                    renderItems()))));
    });
    List.displayName = "List";
    exports.default = List;
});
