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_react_router__ from "react-router";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__ from "../../../application/schema-settings/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_schema_toolbar_index_mjs__ from "../../../application/schema-toolbar/index.mjs";
function useNotDisableHeader() {
    var _fieldSchema_xcomponentprops;
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    return !(null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.disablePageHeader);
}
const pageSettings = new __WEBPACK_EXTERNAL_MODULE__application_schema_settings_index_mjs__.SchemaSettings({
    name: 'PageSettings',
    items: [
        {
            name: 'enablePageHeader',
            type: 'switch',
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return {
                    title: t('Enable page header'),
                    checked: !(null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.disablePageHeader),
                    onChange (v) {
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['disablePageHeader'] = !v;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                ['x-component-props']: fieldSchema['x-component-props']
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'enablesharePage',
            type: 'switch',
            useVisible () {
                const isShare = (0, __WEBPACK_EXTERNAL_MODULE_react_router__.useMatch)('/share/:name');
                return !isShare;
            },
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const { title } = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_toolbar_index_mjs__.useSchemaToolbar)();
                return {
                    title: t('Enable Share page'),
                    checked: null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.enableSharePage,
                    onChange (v) {
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['enableSharePage'] = v;
                        if (!fieldSchema.title) fieldSchema.title = title;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                ['x-component-props']: fieldSchema['x-component-props'],
                                title: fieldSchema.title
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'divider',
            type: 'divider',
            useVisible: useNotDisableHeader
        },
        {
            name: 'displayPageTitle',
            type: 'switch',
            useVisible: useNotDisableHeader,
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return {
                    title: t('Display page title'),
                    checked: !(null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.hidePageTitle),
                    onChange (v) {
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['hidePageTitle'] = !v;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                ['x-component-props']: fieldSchema['x-component-props']
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        },
        {
            name: 'editPageTitle',
            type: 'modal',
            useVisible () {
                var _fieldSchema_xcomponentprops;
                const notDisablePageHeader = useNotDisableHeader();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                const notHidePageTitle = !(null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.hidePageTitle);
                return notDisablePageHeader && notHidePageTitle;
            },
            useComponentProps () {
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__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 { title } = (0, __WEBPACK_EXTERNAL_MODULE__application_schema_toolbar_index_mjs__.useSchemaToolbar)();
                return {
                    hide: true,
                    title: t('Edit page title'),
                    schema: {
                        type: 'object',
                        title: t('Edit page title'),
                        properties: {
                            title: {
                                title: t('Title'),
                                required: true,
                                'x-decorator': 'FormItem',
                                'x-component': 'Input',
                                'x-component-props': {}
                            }
                        }
                    },
                    initialValues: {
                        title
                    },
                    onSubmit (param) {
                        let { title } = param;
                        field.title = title;
                        fieldSchema['title'] = title;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                title
                            }
                        });
                    }
                };
            }
        },
        {
            name: 'enablePageTabs',
            type: 'switch',
            useVisible: useNotDisableHeader,
            useComponentProps () {
                var _fieldSchema_xcomponentprops;
                const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
                const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
                const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
                return {
                    title: t('Enable page tabs'),
                    checked: null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.enablePageTabs,
                    onChange (v) {
                        fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
                        fieldSchema['x-component-props']['enablePageTabs'] = v;
                        dn.emit('patch', {
                            schema: {
                                ['x-uid']: fieldSchema['x-uid'],
                                ['x-component-props']: fieldSchema['x-component-props']
                            }
                        });
                        dn.refresh();
                    }
                };
            }
        }
    ]
});
export { pageSettings };
