import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_settings_SchemaSettings_mjs__ from "../../../../application/schema-settings/SchemaSettings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__common_useFieldComponentName_mjs__ from "../../../../common/useFieldComponentName.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_association_field_util_mjs__ from "../../../../schema-component/antd/association-field/util.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_form_item_FormItem_Settings_mjs__ from "../../../../schema-component/antd/form-item/FormItem.Settings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__ from "../../../../schema-component/antd/table-v2/Table.Column.Decorator.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_hooks_useIsShowMultipleSwitch_mjs__ from "../../../../schema-settings/hooks/useIsShowMultipleSwitch.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__Select_selectComponentFieldSettings_mjs__ from "../Select/selectComponentFieldSettings.mjs";
const fieldComponent = {
    name: 'fieldComponent',
    type: 'select',
    useComponentProps () {
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
        const isAddNewForm = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useIsAddNewForm)();
        const fieldComponentName = (0, __WEBPACK_EXTERNAL_MODULE__common_useFieldComponentName_mjs__.useFieldComponentName)();
        const { fieldSchema: tableColumnSchema, collectionField } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
        const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
        const fieldSchema = tableColumnSchema || schema;
        const fieldModeOptions = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useFieldModeOptions)({
            fieldSchema: tableColumnSchema,
            collectionField
        });
        const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
        return {
            title: t('Field component'),
            options: fieldModeOptions,
            value: fieldComponentName,
            onChange (mode) {
                const schema = {
                    ['x-uid']: fieldSchema['x-uid']
                };
                fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                fieldSchema['x-component-props']['mode'] = mode;
                schema['x-component-props'] = fieldSchema['x-component-props'];
                field.componentProps = field.componentProps || {};
                field.componentProps.mode = mode;
                if ((0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_association_field_util_mjs__.isSubMode)(fieldSchema) && isAddNewForm) {
                    schema.default = null;
                    fieldSchema.default = null;
                    field.setInitialValue(null);
                    field.setValue(null);
                }
                dn.emit('patch', {
                    schema
                });
                dn.refresh();
            }
        };
    }
};
const fileManagerComponentFieldSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_SchemaSettings_mjs__.SchemaSettings({
    name: 'fieldSettings:component:FileManager',
    items: [
        fieldComponent,
        {
            name: 'quickUpload',
            type: 'switch',
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
                const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const fieldSchema = tableColumnSchema || schema;
                const { dn, refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Quick upload'),
                    checked: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.quickUpload) !== false,
                    onChange (value) {
                        const schema = {
                            ['x-uid']: fieldSchema['x-uid']
                        };
                        field.componentProps.quickUpload = value;
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props'].quickUpload = value;
                        schema['x-component-props'] = fieldSchema['x-component-props'];
                        dn.emit('patch', {
                            schema
                        });
                        refresh();
                    }
                };
            },
            useVisible () {
                const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
                const isReadPretty = (null == tableColumnSchema ? void 0 : tableColumnSchema['x-read-pretty']) || field.readPretty || form.readPretty;
                return !isReadPretty;
            }
        },
        {
            name: 'selectFile',
            type: 'switch',
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
                const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const fieldSchema = tableColumnSchema || schema;
                const { dn, refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Select file'),
                    checked: (null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.selectFile) !== false,
                    onChange (value) {
                        const schema = {
                            ['x-uid']: fieldSchema['x-uid']
                        };
                        field.componentProps.selectFile = value;
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props'].selectFile = value;
                        schema['x-component-props'] = fieldSchema['x-component-props'];
                        dn.emit('patch', {
                            schema
                        });
                        refresh();
                    }
                };
            },
            useVisible () {
                const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
                const isReadPretty = (null == tableColumnSchema ? void 0 : tableColumnSchema['x-read-pretty']) || field.readPretty || form.readPretty;
                return !isReadPretty;
            }
        },
        {
            name: 'size',
            type: 'select',
            useVisible () {
                const readPretty = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_form_item_FormItem_Settings_mjs__.useIsFieldReadPretty)();
                const { fieldSchema: tableColumnSchema } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_table_v2_Table_Column_Decorator_mjs__.useColumnSchema)();
                return readPretty && !tableColumnSchema;
            },
            useComponentProps () {
                var _field_componentProps;
                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 { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Size'),
                    options: [
                        {
                            label: t('Large'),
                            value: 'large'
                        },
                        {
                            label: t('Default'),
                            value: 'default'
                        },
                        {
                            label: t('Small'),
                            value: 'small'
                        }
                    ],
                    value: (null == field ? void 0 : null === (_field_componentProps = field.componentProps) || void 0 === _field_componentProps ? void 0 : _field_componentProps.size) || 'default',
                    onChange (size) {
                        const schema = {
                            ['x-uid']: fieldSchema['x-uid']
                        };
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['size'] = size;
                        schema['x-component-props'] = fieldSchema['x-component-props'];
                        field.componentProps = field.componentProps || {};
                        field.componentProps.size = size;
                        dn.emit('patch', {
                            schema
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            ...__WEBPACK_EXTERNAL_MODULE__Select_selectComponentFieldSettings_mjs__.allowMultiple,
            useVisible () {
                const isAssociationField = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_antd_form_item_FormItem_Settings_mjs__.useIsAssociationField)();
                const IsShowMultipleSwitch = (0, __WEBPACK_EXTERNAL_MODULE__schema_settings_hooks_useIsShowMultipleSwitch_mjs__.useIsShowMultipleSwitch)();
                return isAssociationField && IsShowMultipleSwitch();
            }
        }
    ]
});
export { fileManagerComponentFieldSettings };
