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__ant_design_icons__ from "@ant-design/icons";
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__application_schema_initializer_components_SchemaInitializerActionModal_mjs__ from "../../../../application/schema-initializer/components/SchemaInitializerActionModal.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_components_SchemaInitializerItem_mjs__ from "../../../../application/schema-initializer/components/SchemaInitializerItem.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_context_index_mjs__ from "../../../../application/schema-initializer/context/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__ from "../../../../application/schema-initializer/SchemaInitializer.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_hooks_useGetAriaLabelOfDesigner_mjs__ from "../../../../schema-settings/hooks/useGetAriaLabelOfDesigner.mjs";
const Resizable = ()=>{
    var _fieldSchema_xcomponentprops;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_schema_initializer_components_SchemaInitializerActionModal_mjs__.SchemaInitializerActionModal, {
        title: t('Column width'),
        component: /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].forwardRef((props, ref)=>{
            const { children, onClick, ...others } = props;
            const { setVisible } = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_context_index_mjs__.useSchemaInitializer)();
            return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_schema_initializer_components_SchemaInitializerItem_mjs__.SchemaInitializerItem, {
                ref: ref,
                onClick: (param)=>{
                    let { event } = param;
                    setVisible(false);
                    onClick(event);
                },
                ...others,
                title: t('Column width')
            });
        }),
        schema: {
            type: 'object',
            title: t('Column width'),
            properties: {
                width: {
                    'x-decorator': 'FormItem',
                    'x-component': 'InputNumber',
                    'x-component-props': {},
                    default: (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.width) || 200
                }
            }
        },
        onSubmit: (param)=>{
            let { width } = param;
            const props = fieldSchema['x-component-props'] || {};
            props['width'] = width;
            const schema = {
                ['x-uid']: fieldSchema['x-uid']
            };
            schema['x-component-props'] = props;
            fieldSchema['x-component-props'] = props;
            dn.emit('patch', {
                schema
            });
            dn.refresh();
        }
    });
};
const commonOptions = {
    insertPosition: 'beforeEnd',
    useInsert: function() {
        const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useDesignable)();
        const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
        const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
        const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
        return function(schema) {
            const spaceSchema = fieldSchema.reduceProperties((buf, schema)=>{
                if ('Space' === schema['x-component']) return schema;
                return buf;
            }, null);
            if (!spaceSchema) return;
            __WEBPACK_EXTERNAL_MODULE_lodash__["default"].set(schema, 'x-designer-props.linkageAction', true);
            const dn = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.createDesignable)({
                t,
                api,
                refresh,
                current: spaceSchema
            });
            dn.loadAPIClientEvents();
            dn.insertBeforeEnd(schema);
        };
    },
    Component: (props)=>{
        const { getAriaLabel } = (0, __WEBPACK_EXTERNAL_MODULE__schema_settings_hooks_useGetAriaLabelOfDesigner_mjs__.useGetAriaLabelOfDesigner)();
        return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.MenuOutlined, {
            ...props,
            role: "button",
            "aria-label": getAriaLabel('schema-settings'),
            style: {
                cursor: 'pointer'
            }
        });
    },
    items: [
        {
            type: 'itemGroup',
            name: 'actions',
            title: '{{t("Enable actions")}}',
            children: [
                {
                    type: 'item',
                    title: '{{t("View")}}',
                    name: 'view',
                    Component: 'ViewActionInitializer',
                    schema: {
                        'x-component': 'Action.Link',
                        'x-action': 'view',
                        'x-decorator': 'ACLActionProvider'
                    }
                },
                {
                    type: 'item',
                    name: 'edit',
                    title: '{{t("Edit")}}',
                    Component: 'UpdateActionInitializer',
                    schema: {
                        'x-component': 'Action.Link',
                        'x-action': 'update',
                        'x-decorator': 'ACLActionProvider'
                    },
                    useVisible () {
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        return ('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template;
                    }
                },
                {
                    type: 'item',
                    title: '{{t("Delete")}}',
                    name: 'delete',
                    Component: 'DestroyActionInitializer',
                    schema: {
                        'x-component': 'Action.Link',
                        'x-action': 'destroy',
                        'x-decorator': 'ACLActionProvider'
                    },
                    useVisible () {
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        return ('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template;
                    }
                },
                {
                    type: 'item',
                    title: '{{t("Disassociate")}}',
                    name: 'disassociate',
                    Component: 'DisassociateActionInitializer',
                    schema: {
                        'x-component': 'Action.Link',
                        'x-action': 'disassociate',
                        'x-acl-action': 'destroy',
                        'x-decorator': 'ACLActionProvider'
                    },
                    useVisible () {
                        const props = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useDataBlockProps)();
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        return !!(null == props ? void 0 : props.association) && ('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template;
                    }
                },
                {
                    type: 'item',
                    title: '{{t("Add child")}}',
                    name: 'addChildren',
                    Component: 'CreateChildInitializer',
                    schema: {
                        'x-component': 'Action.Link',
                        'x-action': 'create',
                        'x-decorator': 'ACLActionProvider'
                    },
                    useVisible () {
                        var _fieldSchema_parent;
                        const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        const { treeTable } = (null == fieldSchema ? void 0 : null === (_fieldSchema_parent = fieldSchema.parent) || void 0 === _fieldSchema_parent ? void 0 : _fieldSchema_parent.parent['x-decorator-props']) || {};
                        return collection.tree && false !== treeTable;
                    }
                }
            ]
        },
        {
            name: 'divider',
            type: 'divider'
        },
        {
            type: 'subMenu',
            title: '{{t("Customize")}}',
            name: 'customize',
            children: [
                {
                    type: 'item',
                    title: '{{t("Popup")}}',
                    name: 'popup',
                    Component: 'PopupActionInitializer'
                },
                {
                    type: 'item',
                    title: '{{t("Update record")}}',
                    name: 'updateRecord',
                    Component: 'UpdateRecordActionInitializer',
                    useVisible () {
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        return ('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template;
                    }
                },
                {
                    name: 'customRequest',
                    title: '{{t("Custom request")}}',
                    Component: 'CustomRequestInitializer',
                    schema: {
                        'x-action': 'customize:table:request'
                    },
                    useVisible () {
                        const collection = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollection)();
                        return ('view' !== collection.template || (null == collection ? void 0 : collection.writableView)) && 'sql' !== collection.template;
                    }
                }
            ]
        },
        {
            name: 'divider2',
            type: 'divider'
        },
        {
            type: 'item',
            name: 'columnWidth',
            title: 't("Column width")',
            Component: Resizable
        }
    ]
};
const tableActionColumnInitializers = new __WEBPACK_EXTERNAL_MODULE__application_schema_initializer_SchemaInitializer_mjs__.SchemaInitializer({
    name: 'table:configureItemActions',
    ...commonOptions
});
export { Resizable, tableActionColumnInitializers };
