import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
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";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__ from "../../hooks/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__ResourceActionProvider_mjs__ from "../../ResourceActionProvider.mjs";
const xlsxImportAction = ()=>{
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useActionContext)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__ResourceActionProvider_mjs__.useResourceActionContext)();
    const { refreshCM } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_index_mjs__.useCollectionManager_deprecated)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    return {
        async onClick () {
            field.data = field.data || {};
            field.data.loading = true;
            try {
                await form.submit();
                const values = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(form.values);
                const { collectionData, ...collections } = values;
                if (!collections.autoCreateReverseField) delete collections.reverseField;
                delete collections.autoCreateReverseField;
                await api.resource('collections').create({
                    values: {
                        logging: true,
                        ...collections
                    }
                });
                api.resource("".concat(collections.name)).create({
                    values: collectionData
                });
                ctx.setVisible(false);
                null == refresh || refresh();
                await refreshCM();
                field.data.loading = false;
            } catch (error) {
                field.data.loading = false;
                __WEBPACK_EXTERNAL_MODULE_antd__.message.error(t('Operation failed'));
            }
        }
    };
};
export { xlsxImportAction };
