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__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
const PluginUrlForm = (param)=>{
    let { onClose, pluginData, isUpgrade } = param;
    const { message } = __WEBPACK_EXTERNAL_MODULE_antd__.App.useApp();
    const useSaveValues = ()=>{
        const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
        return {
            async run () {
                const compressedFileUrl = form.values.compressedFileUrl;
                if (!compressedFileUrl) return;
                await form.submit();
                const data = {
                    compressedFileUrl
                };
                if (null == pluginData ? void 0 : pluginData.packageName) data['packageName'] = pluginData.packageName;
                api.request({
                    url: "pm:".concat(isUpgrade ? 'update' : 'add'),
                    method: 'post',
                    data
                });
                onClose(true);
            }
        };
    };
    const useValuesFromProps = (options)=>(0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(()=>Promise.resolve({
                data: {
                    compressedFileUrl: pluginData.compressedFileUrl
                }
            }), options);
    const useCancel = ()=>({
            run () {
                onClose();
            }
        });
    const schema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
            type: 'object',
            properties: {
                [(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)()]: {
                    'x-decorator': 'Form',
                    'x-component': 'div',
                    type: 'void',
                    'x-decorator-props': {
                        useValues: '{{ useValuesFromProps }}'
                    },
                    properties: {
                        compressedFileUrl: {
                            type: 'string',
                            'x-decorator': 'FormItem',
                            'x-component': 'Input',
                            required: true
                        },
                        footer: {
                            type: 'void',
                            'x-component': 'ActionBar',
                            'x-component-props': {
                                layout: 'one-column',
                                style: {
                                    justifyContent: 'right'
                                }
                            },
                            properties: {
                                cancel: {
                                    title: 'Cancel',
                                    'x-component': 'Action',
                                    'x-component-props': {
                                        useAction: '{{ useCancel }}'
                                    }
                                },
                                submit: {
                                    title: '{{t("Submit")}}',
                                    'x-component': 'Action',
                                    'x-component-props': {
                                        type: 'primary',
                                        htmlType: 'submit',
                                        useAction: '{{ useSaveValues }}'
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }), []);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.SchemaComponent, {
        scope: {
            useCancel,
            useValuesFromProps,
            useSaveValues
        },
        schema: schema
    });
};
export { PluginUrlForm };
