"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ActionBar: ()=>ActionBar,
    ActionBarProvider: ()=>ActionBarProvider,
    useActionBarContext: ()=>useActionBarContext
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_react_dom_namespaceObject = require("react-dom");
const index_js_namespaceObject = require("../../../application/index.js");
const withDynamicSchemaProps_js_namespaceObject = require("../../../application/hoc/withDynamicSchemaProps.js");
const external_common_index_js_namespaceObject = require("../../common/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const ActionBarContext = /*#__PURE__*/ external_react_default().createContext({
    container: null
});
const ActionBarProvider = (param)=>{
    let { children, ...props } = param;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ActionBarContext.Provider, {
        value: props,
        children: children
    });
};
const useActionBarContext = ()=>(0, external_react_namespaceObject.useContext)(ActionBarContext);
const Portal = (props)=>{
    const filedSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { container, parentComponents = [
        'BlockItem',
        'CardItem'
    ] } = useActionBarContext();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
        children: container && parentComponents.includes(filedSchema.parent['x-component']) ? /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(props.children, container) : props.children
    });
};
const ActionBar = (0, withDynamicSchemaProps_js_namespaceObject.withDynamicSchemaProps)((0, schema_namespaceObject.observer)((props)=>{
    const { forceProps = {} } = useActionBarContext();
    const { layout = 'tow-columns', style, spaceProps, ...others } = {
        ...(0, external_hooks_index_js_namespaceObject.useProps)(props),
        ...forceProps
    };
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { render } = (0, index_js_namespaceObject.useSchemaInitializerRender)(fieldSchema['x-initializer'], fieldSchema['x-initializer-props']);
    const { designable } = (0, external_hooks_index_js_namespaceObject.useDesignable)();
    if ('one-column' === layout) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Portal, {
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_common_index_js_namespaceObject.DndContext, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
                style: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 8,
                    ...style
                },
                ...others,
                className: external_classnames_default()(others.className, 'tb-action-bar'),
                children: [
                    props.children && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                            ...spaceProps,
                            style: {
                                flexWrap: 'wrap'
                            },
                            children: fieldSchema.mapProperties((schema, key)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                                    name: key,
                                    schema: schema
                                }, key))
                        })
                    }),
                    render({
                        style: {
                            margin: '0 !important'
                        }
                    })
                ]
            })
        })
    });
    var _fieldSchema_properties;
    const hasActions = Object.keys(null !== (_fieldSchema_properties = fieldSchema.properties) && void 0 !== _fieldSchema_properties ? _fieldSchema_properties : {}).length > 0;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        style: designable || hasActions ? {
            display: 'flex',
            justifyContent: 'space-between',
            alignItems: 'center',
            overflowX: 'auto',
            flexShrink: 0,
            ...style
        } : void 0,
        ...others,
        className: external_classnames_default()(others.className, 'tb-action-bar'),
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    display: 'flex',
                    justifyContent: 'space-between',
                    alignItems: 'center',
                    width: '100%',
                    overflow: 'hidden',
                    flexWrap: 'wrap'
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_common_index_js_namespaceObject.DndContext, {
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                            ...spaceProps,
                            children: fieldSchema.mapProperties((schema, key)=>{
                                if ('left' !== schema['x-align']) return null;
                                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                                    name: key,
                                    schema: schema
                                }, key);
                            })
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                            ...spaceProps,
                            children: fieldSchema.mapProperties((schema, key)=>{
                                if ('left' === schema['x-align']) return null;
                                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                                    name: key,
                                    schema: schema
                                }, key);
                            })
                        })
                    ]
                })
            }),
            render()
        ]
    });
}), {
    displayName: 'ActionBar'
});
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
