'use strict';

var React = require('react');
var DataListContext = require('./DataListContext-cjs.js');
var DataListLayoutContext = require('./DataListLayoutContext-cjs.js');
var DataListItemActionsOverflow = require('./DataListItemActionsOverflow-cjs.js');
var Glimmer = require('./Glimmer-cjs.js');

var styles = {"hidden":"CwWlXTKCPUg-","spinning":"JD9H0C1ehv0-"};

function DataListLayoutActions() {
    const { itemActionComponent, loadingState } = DataListContext.useDataListContext();
    const { setHasInLayoutActions } = DataListLayoutContext.useDataListLayoutContext();
    const { children: actionsChildren } = (itemActionComponent === null || itemActionComponent === void 0 ? void 0 : itemActionComponent.props) || {};
    const actions = React.Children.toArray(actionsChildren);
    const hasActions = actions.length > 0;
    React.useEffect(() => {
        setHasInLayoutActions(hasActions);
        return () => {
            setHasInLayoutActions(false);
        };
    }, []);
    if (loadingState === "initial") {
        return React.createElement(Glimmer.Glimmer, { shape: "square", size: "large" });
    }
    if (!hasActions)
        return null;
    return (React.createElement(DataListLayoutActionsWrapper, null,
        React.createElement(DataListItemActionsOverflow.DataListItemActionsOverflow, { actions: actions })));
}
function DataListLayoutActionsWrapper({ children }) {
    const { isInLayoutProvider } = DataListLayoutContext.useDataListLayoutContext();
    if (isInLayoutProvider)
        return React.createElement(React.Fragment, null, children);
    return React.createElement("div", { className: styles.hidden }, children);
}

exports.DataListLayoutActions = DataListLayoutActions;
