import { jsx } from "react/jsx-runtime";
import { createContext, useContext } from "react";
import { Spin } from "antd";
import { useRequest } from "../../../api-client/index.mjs";
import { useAdminSchemaUid } from "../../../hooks/index.mjs";
const MenuItemsContext = /*#__PURE__*/ 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 = ()=>useContext(MenuItemsContext);
const MenuItemsProvider = (props)=>{
    var _service_data_data, _service_data;
    const adminSchemaUid = useAdminSchemaUid();
    const options = {
        url: "uiSchemas:getProperties/".concat(adminSchemaUid)
    };
    const service = useRequest(options);
    if (service.loading) return /*#__PURE__*/ jsx(Spin, {});
    const items = toItems(null == (_service_data = service.data) ? void 0 : null == (_service_data_data = _service_data.data) ? void 0 : _service_data_data.properties);
    return /*#__PURE__*/ jsx(MenuItemsContext.Provider, {
        value: {
            service: service,
            items
        },
        children: props.children
    });
};
export { MenuItemsProvider, toItems, useMenuItems };
