import { jsx, jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { Button, Popover } from "antd";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { useAPIClient } from "../../../api-client/index.mjs";
import { SchemaInitializerContext } from "../../../application/index.mjs";
import { GroupItem } from "../../../modules/menu/GroupItem.mjs";
import { LinkMenuItem } from "../../../modules/menu/LinkMenuItem.mjs";
import { PageMenuItem } from "../../../modules/menu/PageMenuItem.mjs";
const AddNewButtonComponent = ()=>{
    const { t } = useTranslation();
    return /*#__PURE__*/ jsx(Popover, {
        trigger: "click",
        content: /*#__PURE__*/ jsx(PopverContent, {}),
        children: /*#__PURE__*/ jsx(Button, {
            type: "primary",
            children: t('Add Entry')
        })
    });
};
const PopverContent = (props)=>{
    const [visible, setVisible] = useState(false);
    const navigate = useNavigate();
    const apiClient = 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['x-uid']) {
            navigate("/admin/".concat(newSchema.data['x-uid']));
            window.location.reload();
        }
    };
    return /*#__PURE__*/ jsxs(SchemaInitializerContext.Provider, {
        value: {
            visible,
            setVisible,
            insert: insertSchema,
            options: props
        },
        children: [
            /*#__PURE__*/ jsx(GroupItem, {}),
            /*#__PURE__*/ jsx(LinkMenuItem, {}),
            /*#__PURE__*/ jsx(PageMenuItem, {})
        ]
    });
};
export { AddNewButtonComponent };
