"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    QuickAccessBlock: ()=>QuickAccessBlock,
    QuickAccessBlockContext: ()=>QuickAccessBlockContext
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const css_namespaceObject = require("@emotion/css");
const external_antd_namespaceObject = require("antd");
const index_js_namespaceObject = require("../../application/index.js");
const external_data_source_index_js_namespaceObject = require("../../data-source/index.js");
const external_icon_index_js_namespaceObject = require("../../icon/index.js");
const external_schema_component_index_js_namespaceObject = require("../../schema-component/index.js");
const external_blockSettings_js_namespaceObject = require("./blockSettings.js");
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, schema_namespaceObject.observer)(()=>{
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { render } = (0, index_js_namespaceObject.useSchemaInitializerRender)(fieldSchema['x-initializer']);
    return render();
}, {
    displayName: 'QuickAccessConfigureActionsButton'
});
const InternalIcons = ()=>{
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { designable } = (0, external_schema_component_index_js_namespaceObject.useDesignable)();
    const { layout = external_blockSettings_js_namespaceObject.QuickAccessLayout.Grid } = fieldSchema.parent['x-component-props'] || {};
    const [gap, setGap] = (0, external_react_namespaceObject.useState)(8);
    (0, external_react_namespaceObject.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, jsx_runtime_namespaceObject.jsx)("div", {
        style: {
            marginBottom: designable ? '1rem' : 0
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.DndContext, {
            children: layout === external_blockSettings_js_namespaceObject.QuickAccessLayout.Grid ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                wrap: true,
                size: gap,
                children: fieldSchema.mapProperties((s, key)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                        name: key,
                        schema: s
                    }, key))
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.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, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.List.Item, {
                        className: (0, css_namespaceObject.css)(_templateObject()),
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.List.Item.Meta, {
                            avatar: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Avatar, {
                                style: {
                                    backgroundColor
                                },
                                icon: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_icon_index_js_namespaceObject.Icon, {
                                    type: icon
                                })
                            }),
                            title: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(schema_namespaceObject.RecursionField, {
                                name: key,
                                schema: s
                            }, key)
                        })
                    }, key);
                })
            })
        })
    });
};
const QuickAccessBlockContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)({
    layout: 'grid'
});
const QuickAccessBlock = (0, index_js_namespaceObject.withDynamicSchemaProps)((props)=>{
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { layout = 'grid' } = fieldSchema['x-component-props'] || {};
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(QuickAccessBlockContext.Provider, {
        value: {
            layout
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_data_source_index_js_namespaceObject.DataSourceContext.Provider, {
            value: void 0,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_data_source_index_js_namespaceObject.CollectionContext.Provider, {
                value: void 0,
                children: props.children
            })
        })
    });
}, {
    displayName: 'QuickAccessBlock'
});
QuickAccessBlock.ActionBar = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalIcons, {}),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ConfigureActionsButton, {})
        ]
    });
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
});
