import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollection_deprecated_mjs__ from "../../../../collection-manager/hooks/useCollection_deprecated.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../../schema-settings/index.mjs";
const setDataLoadingModeSettingsItem = {
    name: 'setDataLoadingMode',
    Component: SetDataLoadingMode
};
function useDataLoadingMode() {
    const { dataLoadingMode } = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useDataBlockProps)() || {};
    return dataLoadingMode || 'auto';
}
function SetDataLoadingMode() {
    var _fieldSchema_xdecoratorprops;
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_hooks_useCollection_deprecated_mjs__.useCollection_deprecated)();
    const { getEnableFieldTree, getOnLoadData } = (0, __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.useCollectionState)(name);
    const request = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useDataBlockRequest)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsModalItem, {
        title: t('Set data loading mode'),
        scope: {
            getEnableFieldTree,
            name,
            getOnLoadData
        },
        schema: {
            type: 'object',
            title: t('Data loading mode'),
            properties: {
                dataLoadingMode: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Radio.Group',
                    default: (null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.dataLoadingMode) || 'auto',
                    enum: [
                        {
                            value: 'auto',
                            label: t('Automatically load data')
                        },
                        {
                            value: 'manual',
                            label: t('Load data after filtering')
                        }
                    ]
                }
            }
        },
        onSubmit: (param)=>{
            let { dataLoadingMode } = param;
            __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.dataLoadingMode', dataLoadingMode);
            field.decoratorProps.dataLoadingMode = dataLoadingMode;
            dn.emit('patch', {
                schema: {
                    ['x-uid']: fieldSchema['x-uid'],
                    'x-decorator-props': {
                        ...fieldSchema['x-decorator-props']
                    }
                }
            });
            dn.refresh();
            if ('auto' === dataLoadingMode) request.run();
            else request.mutate(void 0);
        }
    });
}
export { SetDataLoadingMode, setDataLoadingModeSettingsItem, useDataLoadingMode };
