import { Box, Loader, Text, TextButton } from '@wix/design-system';
import React from 'react';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { useDropdownTranslationContext } from '../providers';
export function useFilterCollectionStates(params) {
    const { collection, fixedFooter } = params;
    const { errorHandler } = useWixPatternsContainer();
    const { translate } = useDropdownTranslationContext();
    const getEmptyStateText = () => {
        if (collection.hasAvailableItems) {
            return translate('noResultsState');
        }
        return translate('emptyState');
    };
    const getFixedFooter = (dataHook, content, paramsFixedFooter) => (React.createElement(Box, { align: "left", direction: "vertical" },
        React.createElement(Box, { dataHook: dataHook, verticalAlign: "middle", align: "center", direction: "vertical", width: "100%" },
            React.createElement(Box, { padding: "SP2" }, content)),
        paramsFixedFooter));
    if (collection.showInitialLoader ||
        collection.result.status.isLoading ||
        collection.showRefreshLoader) {
        return {
            showInitialLoader: true,
            fixedFooter: getFixedFooter('initial-loader', React.createElement(Loader, { size: "small" })),
        };
    }
    if (collection.showEmptyState) {
        return {
            fixedFooter: getFixedFooter('empty-state', React.createElement(Text, { dataHook: "empty-state-text", secondary: true, size: "small" }, getEmptyStateText()), params.fixedFooter),
        };
    }
    if (collection.showErrorState) {
        const resolvedError = errorHandler.getResolvedError?.(collection.result.errorStatus?.error);
        if (resolvedError) {
            return {
                fixedFooter: getFixedFooter('filter-error-state', React.createElement(Box, { direction: "vertical", gap: "SP1", verticalAlign: "middle", align: "center" },
                    React.createElement(Text, { dataHook: "filter-error-state-text", secondary: true, align: "center", weight: "thin", size: "small" },
                        resolvedError.message,
                        resolvedError.action && (React.createElement(TextButton, { onClick: async () => {
                                await resolvedError.action?.onClick?.();
                            } }, resolvedError.action.text))),
                    resolvedError.action && (React.createElement(TextButton, { size: "small", weight: "thin", onClick: async () => {
                            await resolvedError.action?.onClick?.();
                        } }, resolvedError.action.text)))),
            };
        }
    }
    return {
        fixedFooter,
    };
}
//# sourceMappingURL=useFilterCollectionStates.js.map