import { _ as __rest } from './tslib.es6-es.js';
import React__default, { useContext, cloneElement } from 'react';
import { D as DataListContext } from './DataListContext-es.js';
import { T as Text } from './Text-es.js';
import { B as Button } from './Button-es.js';
import 'classnames';
import { E as EMPTY_FILTER_RESULTS_MESSAGE, c as EMPTY_RESULTS_MESSAGE, d as EMPTY_STATE_ACTION_BUTTON_ONLY_ERROR } from './DataList.const-es.js';

var styles = {"emptyStateWrapper":"R0MWvfTO9vg-","spinning":"hVJ2XoR6bR0-"};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function DataListEmptyState(_) {
    return null;
}
function InternalDataListEmptyState() {
    const { emptyStateComponents: components, filtered } = useContext(DataListContext);
    const _a = getEmptyStateContent(), { customRender } = _a, contentProps = __rest(_a, ["customRender"]);
    return (React__default.createElement("div", { className: styles.emptyStateWrapper }, customRender ? (customRender(Object.assign({}, contentProps))) : (React__default.createElement(React__default.Fragment, null,
        React__default.createElement(Text, { align: "center" }, contentProps.message),
        renderButton(contentProps.action)))));
    function getEmptyStateContent() {
        const { defaultEmptyState, filteredEmptyState } = getEmptyStates(components);
        if (filtered) {
            return {
                message: (filteredEmptyState === null || filteredEmptyState === void 0 ? void 0 : filteredEmptyState.props.message) || EMPTY_FILTER_RESULTS_MESSAGE,
                action: filteredEmptyState === null || filteredEmptyState === void 0 ? void 0 : filteredEmptyState.props.action,
                customRender: filteredEmptyState === null || filteredEmptyState === void 0 ? void 0 : filteredEmptyState.props.customRender,
            };
        }
        return {
            message: (defaultEmptyState === null || defaultEmptyState === void 0 ? void 0 : defaultEmptyState.props.message) || EMPTY_RESULTS_MESSAGE,
            action: defaultEmptyState === null || defaultEmptyState === void 0 ? void 0 : defaultEmptyState.props.action,
            customRender: defaultEmptyState === null || defaultEmptyState === void 0 ? void 0 : defaultEmptyState.props.customRender,
        };
    }
}
function renderButton(action) {
    if (action) {
        if (action.type === Button) {
            return cloneElement(action, {
                variation: action.props.variation || "subtle",
            });
        }
        throw new Error(EMPTY_STATE_ACTION_BUTTON_ONLY_ERROR);
    }
    return;
}
function getEmptyStates(components) {
    const defaultEmptyState = components === null || components === void 0 ? void 0 : components.find(es => es.props.type === "empty" || es.props.type === undefined);
    const filteredEmptyState = components === null || components === void 0 ? void 0 : components.find(es => es.props.type === "filtered");
    return { defaultEmptyState, filteredEmptyState };
}

export { DataListEmptyState as D, InternalDataListEmptyState as I };
