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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_classnames__ from "classnames";
import * as __WEBPACK_EXTERNAL_MODULE_react_dom__ from "react-dom";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__common_index_mjs__ from "../../common/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
const ActionBarContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({
    container: null
});
const ActionBarProvider = (param)=>{
    let { children, ...props } = param;
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ActionBarContext.Provider, {
        value: props,
        children: children
    });
};
const useActionBarContext = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(ActionBarContext);
const Portal = (props)=>{
    const filedSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { container, parentComponents = [
        'BlockItem',
        'CardItem'
    ] } = useActionBarContext();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: container && parentComponents.includes(filedSchema.parent['x-component']) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_dom__.createPortal)(props.children, container) : props.children
    });
};
const ActionBar = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { forceProps = {} } = useActionBarContext();
    const { layout = 'tow-columns', style, spaceProps, ...others } = {
        ...(0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useProps)(props),
        ...forceProps
    };
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { render } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerRender)(fieldSchema['x-initializer'], fieldSchema['x-initializer-props']);
    const { designable } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useDesignable)();
    if ('one-column' === layout) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(Portal, {
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__common_index_mjs__.DndContext, {
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                style: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 8,
                    ...style
                },
                ...others,
                className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(others.className, 'tb-action-bar'),
                children: [
                    props.children && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                            ...spaceProps,
                            style: {
                                flexWrap: 'wrap'
                            },
                            children: fieldSchema.mapProperties((schema, key)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        style: designable || hasActions ? {
            display: 'flex',
            justifyContent: 'space-between',
            alignItems: 'center',
            overflowX: 'auto',
            flexShrink: 0,
            ...style
        } : void 0,
        ...others,
        className: (0, __WEBPACK_EXTERNAL_MODULE_classnames__["default"])(others.className, 'tb-action-bar'),
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                style: {
                    display: 'flex',
                    justifyContent: 'space-between',
                    alignItems: 'center',
                    width: '100%',
                    overflow: 'hidden',
                    flexWrap: 'wrap'
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__common_index_mjs__.DndContext, {
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                            ...spaceProps,
                            children: fieldSchema.mapProperties((schema, key)=>{
                                if ('left' !== schema['x-align']) return null;
                                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                                    name: key,
                                    schema: schema
                                }, key);
                            })
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                            ...spaceProps,
                            children: fieldSchema.mapProperties((schema, key)=>{
                                if ('left' === schema['x-align']) return null;
                                return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                                    name: key,
                                    schema: schema
                                }, key);
                            })
                        })
                    ]
                })
            }),
            render()
        ]
    });
}), {
    displayName: 'ActionBar'
});
export { ActionBar, ActionBarProvider, useActionBarContext };
