import { jsx } from "react/jsx-runtime";
import "react";
import { useField, useFieldSchema } from "@tachybase/schema";
import { useTranslation } from "react-i18next";
import { useDesignable } from "../../../index.mjs";
import { useSchemaToolbar } from "../../../application/index.mjs";
import { SchemaSettings } from "../../../application/schema-settings/SchemaSettings.mjs";
import { RemoveButton } from "../../../schema-component/antd/action/Action.Designer.mjs";
import { SchemaSettingsModalItem } from "../../../schema-settings/index.mjs";
function ButtonEditor() {
    var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1;
    const field = useField();
    const fieldSchema = useFieldSchema();
    const { dn } = useDesignable();
    const { t } = useTranslation();
    const { titleExpand, titleCollapse, iconExpand, iconCollapse } = fieldSchema['x-component-props'] || {};
    return /*#__PURE__*/ jsx(SchemaSettingsModalItem, {
        title: t('Edit button'),
        schema: {
            type: 'object',
            title: t('Edit button'),
            properties: {
                titleExpand: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Input',
                    title: "".concat(t('Button title'), " - ").concat(t('Expand all')),
                    default: titleExpand
                },
                titleCollapse: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Input',
                    title: "".concat(t('Button title'), " - ").concat(t('Collapse all')),
                    default: titleCollapse
                },
                iconExpand: {
                    'x-decorator': 'FormItem',
                    'x-component': 'IconPicker',
                    title: "".concat(t('Button icon'), " - ").concat(t('Expand all')),
                    default: iconExpand
                },
                iconCollapse: {
                    'x-decorator': 'FormItem',
                    'x-component': 'IconPicker',
                    title: "".concat(t('Button icon'), " - ").concat(t('Collapse all')),
                    default: iconCollapse
                },
                type: {
                    'x-decorator': 'FormItem',
                    'x-component': 'Radio.Group',
                    title: t('Button background color'),
                    default: (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops.danger) ? 'danger' : (null == fieldSchema ? void 0 : null == (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) ? void 0 : _fieldSchema_xcomponentprops1.type) === 'primary' ? 'primary' : 'default',
                    enum: [
                        {
                            value: 'default',
                            label: '{{t("Default")}}'
                        },
                        {
                            value: 'primary',
                            label: '{{t("Highlight")}}'
                        },
                        {
                            value: 'danger',
                            label: '{{t("Danger red")}}'
                        }
                    ]
                }
            }
        },
        onSubmit: (param)=>{
            let { titleExpand, titleCollapse, iconExpand, iconCollapse, type } = param;
            fieldSchema.title = t('Expand/Collapse');
            field.title = t('Expand/Collapse');
            field.componentProps.icon = iconExpand;
            field.componentProps.danger = 'danger' === type;
            field.componentProps.type = type;
            fieldSchema['x-component-props'] = {
                ...fieldSchema['x-component-props'] || {},
                titleExpand,
                titleCollapse,
                iconExpand,
                iconCollapse,
                type,
                danger: 'danger' === type
            };
            dn.emit('patch', {
                schema: {
                    'x-uid': fieldSchema['x-uid'],
                    'x-component-props': fieldSchema['x-component-props'],
                    title: fieldSchema.title
                }
            });
            dn.refresh();
        }
    });
}
const expendableActionSettings = new SchemaSettings({
    name: 'actionSettings:expendable',
    items: [
        {
            name: 'editButton',
            Component: ButtonEditor,
            useComponentProps () {
                const { buttonEditorProps } = useSchemaToolbar();
                return buttonEditorProps;
            }
        },
        {
            name: 'remove',
            sort: 100,
            Component: RemoveButton,
            useComponentProps () {
                const { removeButtonProps } = useSchemaToolbar();
                return removeButtonProps;
            }
        }
    ]
});
export { expendableActionSettings };
