import { useCallback, useMemo, useState } from 'react';
import { getSuggestionsCount } from '../helpers/common';
var DEFAULT_VISIBLE_ITEMS_COUNT = 3;
export var useCollapsibleList = function (items, limit) {
    if (limit === void 0) { limit = DEFAULT_VISIBLE_ITEMS_COUNT; }
    var _a = useState(false), isExpanded = _a[0], setIsExpanded = _a[1];
    var onToggle = useCallback(function () { return setIsExpanded(function (value) { return !value; }); }, []);
    var collapsedItems = useMemo(function () { return items.slice(0, limit); }, [items, limit]);
    var suggestionsCount = useMemo(function () { return getSuggestionsCount(items); }, [items]);
    var visibleSuggestionsCount = useMemo(function () { return getSuggestionsCount(collapsedItems); }, [collapsedItems]);
    var itemsToShow = isExpanded ? items : collapsedItems;
    var collapsedSuggestionsCount = suggestionsCount - visibleSuggestionsCount;
    return { isExpanded: isExpanded, onToggle: onToggle, itemsToShow: itemsToShow, collapsedSuggestionsCount: collapsedSuggestionsCount };
};
