"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCollapsibleList = void 0;
var react_1 = require("react");
var common_1 = require("../helpers/common");
var DEFAULT_VISIBLE_ITEMS_COUNT = 3;
var useCollapsibleList = function (items, limit) {
    if (limit === void 0) { limit = DEFAULT_VISIBLE_ITEMS_COUNT; }
    var _a = (0, react_1.useState)(false), isExpanded = _a[0], setIsExpanded = _a[1];
    var onToggle = (0, react_1.useCallback)(function () { return setIsExpanded(function (value) { return !value; }); }, []);
    var collapsedItems = (0, react_1.useMemo)(function () { return items.slice(0, limit); }, [items, limit]);
    var suggestionsCount = (0, react_1.useMemo)(function () { return (0, common_1.getSuggestionsCount)(items); }, [items]);
    var visibleSuggestionsCount = (0, react_1.useMemo)(function () { return (0, common_1.getSuggestionsCount)(collapsedItems); }, [collapsedItems]);
    var itemsToShow = isExpanded ? items : collapsedItems;
    var collapsedSuggestionsCount = suggestionsCount - visibleSuggestionsCount;
    return { isExpanded: isExpanded, onToggle: onToggle, itemsToShow: itemsToShow, collapsedSuggestionsCount: collapsedSuggestionsCount };
};
exports.useCollapsibleList = useCollapsibleList;
