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__emotion_css__ from "@emotion/css";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__icon_index_mjs__ from "../../icon/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__blockSettings_mjs__ from "./blockSettings.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n                    .ant-list-item-meta-avatar {\n                      margin-inline-end: 0px !important;\n                    }\n                    .ant-list-item-meta-title {\n                      overflow: hidden;\n                      text-overflow: ellipsis;\n                    }\n                    .ant-list-item-meta-title button {\n                      font-size: 16px;\n                      overflow: hidden;\n                      text-overflow: ellipsis;\n                      width: 100%;\n                      text-align: left;\n                    }\n                  "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const ConfigureActionsButton = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)(()=>{
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { render } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerRender)(fieldSchema['x-initializer']);
    return render();
}, {
    displayName: 'QuickAccessConfigureActionsButton'
});
const InternalIcons = ()=>{
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { designable } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
    const { layout = __WEBPACK_EXTERNAL_MODULE__blockSettings_mjs__.QuickAccessLayout.Grid } = fieldSchema.parent['x-component-props'] || {};
    const [gap, setGap] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(8);
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        const calculateGap = ()=>{
            const container = document.getElementsByClassName('mobile-page-content')[0];
            if (container) {
                const containerWidth = container.offsetWidth - 48;
                const itemWidth = 100;
                const itemsPerRow = Math.floor(containerWidth / itemWidth);
                const totalItemWidth = itemsPerRow * itemWidth;
                const totalAvailableWidth = containerWidth;
                const totalGapsWidth = totalAvailableWidth - totalItemWidth;
                totalGapsWidth > 0 ? setGap(totalGapsWidth / (itemsPerRow - 1)) : setGap(0);
            }
        };
        window.addEventListener('resize', calculateGap);
        calculateGap();
        return ()=>{
            window.removeEventListener('resize', calculateGap);
        };
    }, [
        Object.keys((null == fieldSchema ? void 0 : fieldSchema.properties) || {}).length
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        style: {
            marginBottom: designable ? '1rem' : 0
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.DndContext, {
            children: layout === __WEBPACK_EXTERNAL_MODULE__blockSettings_mjs__.QuickAccessLayout.Grid ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                wrap: true,
                size: gap,
                children: fieldSchema.mapProperties((s, key)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                        name: key,
                        schema: s
                    }, key))
            }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.List, {
                itemLayout: "horizontal",
                children: fieldSchema.mapProperties((s, key)=>{
                    var _s_xcomponentprops, _s_xcomponentprops1;
                    const icon = null === (_s_xcomponentprops = s['x-component-props']) || void 0 === _s_xcomponentprops ? void 0 : _s_xcomponentprops['icon'];
                    const backgroundColor = null === (_s_xcomponentprops1 = s['x-component-props']) || void 0 === _s_xcomponentprops1 ? void 0 : _s_xcomponentprops1['iconColor'];
                    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.List.Item, {
                        className: (0, __WEBPACK_EXTERNAL_MODULE__emotion_css__.css)(_templateObject()),
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.List.Item.Meta, {
                            avatar: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Avatar, {
                                style: {
                                    backgroundColor
                                },
                                icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
                                    type: icon
                                })
                            }),
                            title: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                                name: key,
                                schema: s
                            }, key)
                        })
                    }, key);
                })
            })
        })
    });
};
const QuickAccessBlockContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({
    layout: 'grid'
});
const QuickAccessBlock = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.withDynamicSchemaProps)((props)=>{
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { layout = 'grid' } = fieldSchema['x-component-props'] || {};
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(QuickAccessBlockContext.Provider, {
        value: {
            layout
        },
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.DataSourceContext.Provider, {
            value: void 0,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.CollectionContext.Provider, {
                value: void 0,
                children: props.children
            })
        })
    });
}, {
    displayName: 'QuickAccessBlock'
});
QuickAccessBlock.ActionBar = ()=>/*#__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__.jsx)(InternalIcons, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(ConfigureActionsButton, {})
        ]
    });
export { QuickAccessBlock, QuickAccessBlockContext };
