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_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../../hooks/index.mjs";
const MenuItemsContext = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(null);
MenuItemsContext.displayName = 'MenuItemsContext';
const toItems = function() {
    let properties = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    const items = [];
    for(const key in properties)if (Object.prototype.hasOwnProperty.call(properties, key)) {
        const element = properties[key];
        const item = {
            title: element.title,
            uid: element['x-uid']
        };
        if (element.properties) item['children'] = toItems(element.properties);
        items.push(item);
    }
    return items;
};
const useMenuItems = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(MenuItemsContext);
const MenuItemsProvider = (props)=>{
    var _service_data_data, _service_data;
    const adminSchemaUid = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useAdminSchemaUid)();
    const options = {
        url: "uiSchemas:getProperties/".concat(adminSchemaUid)
    };
    const service = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(options);
    if (service.loading) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {});
    const items = toItems(null === (_service_data = service.data) || void 0 === _service_data ? void 0 : null === (_service_data_data = _service_data.data) || void 0 === _service_data_data ? void 0 : _service_data_data.properties);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(MenuItemsContext.Provider, {
        value: {
            service: service,
            items
        },
        children: props.children
    });
};
export { MenuItemsProvider, toItems, useMenuItems };
