import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_react_dom__ from "react-dom";
import * as __WEBPACK_EXTERNAL_MODULE__Action_Area_style_mjs__ from "./Action.Area.style.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
const ActionAreaContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({});
const ActionAreaProvider = (param)=>{
    let { children } = param;
    const [component, setComponent] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>{});
    const [prevSetVisible, setPrevSetVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>{});
    const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ActionAreaContext.Provider, {
        value: {
            component,
            setComponent,
            prevSetVisible,
            setPrevSetVisible,
            ref
        },
        children: children
    });
};
const useActionAreaStub = ()=>{
    const { component } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ActionAreaContext);
    return component;
};
const ActionAreaStub = ()=>{
    const { ref } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ActionAreaContext);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        ref: ref
    });
};
const ActionAreaPlayer = (param)=>{
    let { children } = param;
    const { visible, setVisible } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useActionContext)();
    const { prevSetVisible, setPrevSetVisible, ref } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ActionAreaContext);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (visible) null == setPrevSetVisible || setPrevSetVisible(()=>{
            null == prevSetVisible || prevSetVisible(false);
            setVisible(true);
            return setVisible;
        });
    }, [
        visible
    ]);
    return visible && ref.current ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_dom__.createPortal)(children, ref.current) : null;
};
const ActionArea = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { footerNodeName = 'ActionArea.Footer' } = props;
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { styles } = (0, __WEBPACK_EXTERNAL_MODULE__Action_Area_style_mjs__.useStyles)();
    const Current = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                    className: styles.footer,
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            className: "title",
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("strong", {
                                children: field.title
                            })
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                            basePath: field.address,
                            schema: schema,
                            onlyRenderProperties: true,
                            filterProperties: (s)=>s['x-component'] === footerNodeName
                        })
                    ]
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                    className: styles.container,
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                        basePath: field.address,
                        schema: schema,
                        onlyRenderProperties: true,
                        filterProperties: (s)=>s['x-component'] !== footerNodeName
                    })
                })
            ]
        });
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ActionAreaPlayer, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Current, {})
    });
}, {
    displayName: 'ActionArea'
});
ActionArea.Footer = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
        basePath: field.address,
        schema: schema,
        onlyRenderProperties: true
    });
}, {
    displayName: 'ActionArea.Footer'
});
const Action_Area_rslib_entry_ = ActionArea;
export { ActionArea, ActionAreaPlayer, ActionAreaProvider, ActionAreaStub, Action_Area_rslib_entry_ as default, useActionAreaStub };
