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_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE_react_router_dom__ from "react-router-dom";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__modules_menu_GroupItem_mjs__ from "../../../modules/menu/GroupItem.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__modules_menu_LinkMenuItem_mjs__ from "../../../modules/menu/LinkMenuItem.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__modules_menu_PageMenuItem_mjs__ from "../../../modules/menu/PageMenuItem.mjs";
const AddNewButtonComponent = ()=>{
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Popover, {
        trigger: "click",
        content: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(PopverContent, {}),
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
            type: "primary",
            children: t('Add Entry')
        })
    });
};
const PopverContent = (props)=>{
    const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const navigate = (0, __WEBPACK_EXTERNAL_MODULE_react_router_dom__.useNavigate)();
    const apiClient = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const insertSchema = async (schema)=>{
        var _newSchema_data;
        const { data: newSchema } = await apiClient.request({
            resource: 'uiSchemas',
            action: 'insertAdjacent/default-admin-menu',
            params: {
                position: 'beforeEnd',
                values: schema
            }
        });
        if (null == newSchema ? void 0 : null === (_newSchema_data = newSchema.data) || void 0 === _newSchema_data ? void 0 : _newSchema_data['x-uid']) {
            navigate("/admin/".concat(newSchema.data['x-uid']));
            window.location.reload();
        }
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__application_index_mjs__.SchemaInitializerContext.Provider, {
        value: {
            visible,
            setVisible,
            insert: insertSchema,
            options: props
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__modules_menu_GroupItem_mjs__.GroupItem, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__modules_menu_LinkMenuItem_mjs__.LinkMenuItem, {}),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__modules_menu_PageMenuItem_mjs__.PageMenuItem, {})
        ]
    });
};
export { AddNewButtonComponent };
