import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_components__ from "@tachybase/components";
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__application_schema_settings_SchemaSettings_mjs__ from "../../../../application/schema-settings/SchemaSettings.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__ from "../../../../collection-manager/index.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_component_antd_grid_card_options_mjs__ from "../../../../schema-component/antd/grid-card/options.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__ from "../../../../schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__ from "../../../../schema-settings/SchemaSettingsDataScope.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__details_multi_setDataLoadingModeSettingsItem_mjs__ from "../details-multi/setDataLoadingModeSettingsItem.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__utils_mjs__ from "./utils.mjs";
const gridCardBlockSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_SchemaSettings_mjs__.SchemaSettings({
    name: 'blockSettings:gridCard',
    items: [
        {
            name: 'SetTheCountOfColumnsDisplayedInARow',
            type: 'modal',
            useComponentProps () {
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                const columnCount = field.decoratorProps.columnCount || __WEBPACK_EXTERNAL_MODULE__schema_component_antd_grid_card_options_mjs__.defaultColumnCount;
                const columnCountSchema = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
                        'x-component': 'Slider',
                        'x-decorator': 'FormItem',
                        'x-component-props': {
                            min: 1,
                            max: 24,
                            marks: __WEBPACK_EXTERNAL_MODULE__utils_mjs__.columnCountMarks,
                            tooltip: {
                                formatter: (value)=>"".concat(value).concat(t('Column'))
                            },
                            step: null
                        }
                    }), [
                    t
                ]);
                const columnCountProperties = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>__WEBPACK_EXTERNAL_MODULE__schema_component_antd_grid_card_options_mjs__.gridSizes.reduce((o, k)=>{
                        o[k] = {
                            ...columnCountSchema,
                            title: t(__WEBPACK_EXTERNAL_MODULE__schema_component_antd_grid_card_options_mjs__.screenSizeTitleMaps[k]),
                            description: "".concat(t('Screen size'), " ").concat(__WEBPACK_EXTERNAL_MODULE__schema_component_antd_grid_card_options_mjs__.screenSizeMaps[k], " ").concat(t('pixels'))
                        };
                        return o;
                    }, {}), [
                    columnCountSchema,
                    t
                ]);
                return {
                    title: t('Set the count of columns displayed in a row'),
                    initialValues: columnCount,
                    schema: {
                        type: 'object',
                        title: t('Set the count of columns displayed in a row'),
                        properties: columnCountProperties
                    },
                    onSubmit: (columnCount)=>{
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.columnCount', columnCount);
                        field.decoratorProps.columnCount = columnCount;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'SetTheDataScope',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_SchemaSettingsDataScope_mjs__.SchemaSettingsDataScope,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const { form } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useFormBlockContext)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    collectionName: name,
                    defaultFilter: (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_params = _fieldSchema_xdecoratorprops.params) || void 0 === _fieldSchema_xdecoratorprops_params ? void 0 : _fieldSchema_xdecoratorprops_params.filter) || {},
                    form: form,
                    onSubmit: (param)=>{
                        let { filter } = param;
                        filter = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.removeNullCondition)(filter);
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.filter', filter);
                        field.decoratorProps.params = {
                            ...fieldSchema['x-decorator-props'].params
                        };
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'SetDefaultSortingRules',
            type: 'modal',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops_params, _fieldSchema_xdecoratorprops;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                const sortFields = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useSortFields)(name);
                const defaultSort = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_params = _fieldSchema_xdecoratorprops.params) || void 0 === _fieldSchema_xdecoratorprops_params ? void 0 : _fieldSchema_xdecoratorprops_params.sort) || [];
                const sort = null == defaultSort ? void 0 : defaultSort.map((item)=>item.startsWith('-') ? {
                        field: item.substring(1),
                        direction: 'desc'
                    } : {
                        field: item,
                        direction: 'asc'
                    });
                return {
                    title: t('Set default sorting rules'),
                    components: {
                        ArrayItems: __WEBPACK_EXTERNAL_MODULE__tachybase_components__.ArrayItems
                    },
                    schema: {
                        type: 'object',
                        title: t('Set default sorting rules'),
                        properties: {
                            sort: {
                                type: 'array',
                                default: sort,
                                'x-component': 'ArrayItems',
                                'x-decorator': 'FormItem',
                                items: {
                                    type: 'object',
                                    properties: {
                                        space: {
                                            type: 'void',
                                            'x-component': 'Space',
                                            properties: {
                                                sort: {
                                                    type: 'void',
                                                    'x-decorator': 'FormItem',
                                                    'x-component': 'ArrayItems.SortHandle'
                                                },
                                                field: {
                                                    type: 'string',
                                                    enum: sortFields,
                                                    required: true,
                                                    'x-decorator': 'FormItem',
                                                    'x-component': 'Select',
                                                    'x-component-props': {
                                                        style: {
                                                            width: 260
                                                        }
                                                    }
                                                },
                                                direction: {
                                                    type: 'string',
                                                    'x-decorator': 'FormItem',
                                                    'x-component': 'Radio.Group',
                                                    'x-component-props': {
                                                        optionType: 'button'
                                                    },
                                                    enum: [
                                                        {
                                                            label: t('ASC'),
                                                            value: 'asc'
                                                        },
                                                        {
                                                            label: t('DESC'),
                                                            value: 'desc'
                                                        }
                                                    ]
                                                },
                                                remove: {
                                                    type: 'void',
                                                    'x-decorator': 'FormItem',
                                                    'x-component': 'ArrayItems.Remove'
                                                }
                                            }
                                        }
                                    }
                                },
                                properties: {
                                    add: {
                                        type: 'void',
                                        title: t('Add sort field'),
                                        'x-component': 'ArrayItems.Addition'
                                    }
                                }
                            }
                        }
                    },
                    onSubmit: (param)=>{
                        let { sort } = param;
                        const sortArr = sort.map((item)=>'desc' === item.direction ? "-".concat(item.field) : item.field);
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.sort', sortArr);
                        field.decoratorProps.params = {
                            ...fieldSchema['x-decorator-props'].params
                        };
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'setDataLoadingMode',
            Component: __WEBPACK_EXTERNAL_MODULE__details_multi_setDataLoadingModeSettingsItem_mjs__.SetDataLoadingMode
        },
        {
            name: 'RecordsPerPage',
            type: 'select',
            useComponentProps () {
                var _field_decoratorProps_params, _field_decoratorProps;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Records per page'),
                    value: (null === (_field_decoratorProps = field.decoratorProps) || void 0 === _field_decoratorProps ? void 0 : null === (_field_decoratorProps_params = _field_decoratorProps.params) || void 0 === _field_decoratorProps_params ? void 0 : _field_decoratorProps_params.pageSize) || 20,
                    options: __WEBPACK_EXTERNAL_MODULE__schema_component_antd_grid_card_options_mjs__.pageSizeOptions.map((v)=>({
                            value: v
                        })),
                    onChange: (pageSize)=>{
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.params.pageSize', pageSize);
                        field.decoratorProps.params = {
                            ...fieldSchema['x-decorator-props'].params,
                            page: 1
                        };
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'LayoutDirection',
            type: 'select',
            useComponentProps () {
                var _field_decoratorProps;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Layout Direction'),
                    value: (null === (_field_decoratorProps = field.decoratorProps) || void 0 === _field_decoratorProps ? void 0 : _field_decoratorProps.layoutDirection) || 'column',
                    options: [
                        {
                            value: 'row'
                        },
                        {
                            value: 'column'
                        }
                    ],
                    onChange: (layoutDirection)=>{
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.layoutDirection', layoutDirection);
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(field, 'decoratorProps.layoutDirection', layoutDirection);
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'setLinkable',
            type: 'switch',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                var _fieldSchema_xdecoratorprops_isLinkable;
                return {
                    title: t('Set Linkable'),
                    checked: null !== (_fieldSchema_xdecoratorprops_isLinkable = null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops['isLinkable']) && void 0 !== _fieldSchema_xdecoratorprops_isLinkable && _fieldSchema_xdecoratorprops_isLinkable,
                    onChange: (isLinkable)=>{
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.isLinkable', isLinkable);
                        field.decoratorProps.isLinkable = isLinkable;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            },
            useVisible () {
                var _fieldSchema_xdecoratorprops_linkConfig, _fieldSchema_xdecoratorprops;
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : null === (_fieldSchema_xdecoratorprops_linkConfig = _fieldSchema_xdecoratorprops['linkConfig']) || void 0 === _fieldSchema_xdecoratorprops_linkConfig ? void 0 : _fieldSchema_xdecoratorprops_linkConfig['link'];
            }
        },
        {
            name: 'setInfiniteScroll',
            type: 'switch',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                return {
                    title: t('Set InfiniteScroll'),
                    checked: null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops['needInfiniteScroll'],
                    onChange: (needInfiniteScroll)=>{
                        __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(fieldSchema, 'x-decorator-props.needInfiniteScroll', needInfiniteScroll);
                        field.decoratorProps.needInfiniteScroll = needInfiniteScroll;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'setLinkConfig',
            type: 'modal',
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops_linkConfig, _fieldSchema_xdecoratorprops1, _fieldSchema_xdecoratorprops_linkConfig1, _fieldSchema_xdecoratorprops2;
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const fields = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useSortFields)((null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops['collection']) || collection.name);
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
                const dataSource = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useDataSource)();
                return {
                    title: t('Set LinkConfig'),
                    schema: {
                        type: 'object',
                        title: 'Set LinkConfig',
                        properties: {
                            link: {
                                type: 'string',
                                title: t('Link'),
                                required: true,
                                'x-decorator': 'FormItem',
                                'x-component': 'Input',
                                default: (null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : null === (_fieldSchema_xdecoratorprops_linkConfig = _fieldSchema_xdecoratorprops1['linkConfig']) || void 0 === _fieldSchema_xdecoratorprops_linkConfig ? void 0 : _fieldSchema_xdecoratorprops_linkConfig['link']) || ''
                            },
                            fields: {
                                type: 'object',
                                title: t('Field'),
                                'x-decorator': 'FormItem',
                                'x-component': 'Select',
                                enum: fields,
                                default: (null === (_fieldSchema_xdecoratorprops2 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops2 ? void 0 : null === (_fieldSchema_xdecoratorprops_linkConfig1 = _fieldSchema_xdecoratorprops2['linkConfig']) || void 0 === _fieldSchema_xdecoratorprops_linkConfig1 ? void 0 : _fieldSchema_xdecoratorprops_linkConfig1['fields']) || null,
                                'x-component-props': {
                                    multiple: true
                                }
                            }
                        }
                    },
                    onSubmit: (value)=>{
                        var _fieldSchema_xdecoratorprops;
                        fieldSchema['x-decorator-props']['linkConfig'] = {
                            ...null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops['linkConfig'],
                            link: value.link,
                            fields: value.fields,
                            linkDataSource: dataSource.key,
                            linkCollection: collection.name
                        };
                        dn.emit('patch', {
                            schema: {
                                'x-uid': fieldSchema['x-uid'],
                                'x-decorator-props': fieldSchema['x-decorator-props']
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'ConvertReferenceToDuplicate',
            Component: __WEBPACK_EXTERNAL_MODULE__schema_settings_index_mjs__.SchemaSettingsTemplate,
            useComponentProps () {
                var _fieldSchema_xdecoratorprops, _fieldSchema_xdecoratorprops1;
                const { name } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollection_deprecated)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const defaultResource = (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops ? void 0 : _fieldSchema_xdecoratorprops.resource) || (null == fieldSchema ? void 0 : null === (_fieldSchema_xdecoratorprops1 = fieldSchema['x-decorator-props']) || void 0 === _fieldSchema_xdecoratorprops1 ? void 0 : _fieldSchema_xdecoratorprops1.association);
                return {
                    componentName: 'GridCard',
                    collectionName: name,
                    resourceName: defaultResource
                };
            }
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            name: 'delete',
            type: 'remove',
            useComponentProps () {
                return {
                    removeParentsIfNoChildren: true,
                    breakRemoveOn: {
                        'x-component': 'Grid'
                    }
                };
            }
        }
    ]
});
export { gridCardBlockSettings };
