import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_lodash_pick__ from "lodash/pick";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__ from "../../../../record-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__ from "../../../../schema-component/index.mjs";
const collection = {
    name: 'roles',
    filterTargetKey: 'name',
    targetKey: 'name',
    fields: [
        {
            type: 'integer',
            name: 'title',
            interface: 'input',
            uiSchema: {
                title: '{{t("Role display name")}}',
                type: 'number',
                'x-component': 'Input',
                required: true
            }
        },
        {
            type: 'string',
            name: 'name',
            interface: 'input',
            uiSchema: {
                title: '{{t("Role UID")}}',
                type: 'string',
                'x-component': 'Input'
            }
        },
        {
            type: 'boolean',
            name: 'default',
            interface: 'boolean',
            uiSchema: {
                title: '{{t("Default role")}}',
                type: 'boolean',
                'x-component': 'Checkbox'
            }
        }
    ]
};
const roleSchema = {
    type: 'object',
    properties: {
        block1: {
            type: 'void',
            'x-decorator': 'ResourceActionProvider',
            'x-decorator-props': {
                collection,
                resourceName: 'roles',
                request: {
                    resource: 'roles',
                    action: 'list',
                    params: {
                        pageSize: 50,
                        filter: {
                            'name.$ne': 'root'
                        },
                        showAnonymous: true,
                        sort: [
                            'createdAt'
                        ],
                        appends: []
                    }
                }
            },
            'x-component': 'CollectionProvider_deprecated',
            'x-component-props': {
                collection
            },
            properties: {
                actions: {
                    type: 'void',
                    'x-component': 'ActionBar',
                    'x-component-props': {
                        style: {
                            marginBottom: 16
                        }
                    },
                    properties: {
                        delete: {
                            type: 'void',
                            title: '{{ t("Delete") }}',
                            'x-component': 'Action',
                            'x-component-props': {
                                useAction: '{{ cm.useBulkDestroyAction }}',
                                confirm: {
                                    title: "{{t('Delete role')}}",
                                    content: "{{t('Are you sure you want to delete it?')}}"
                                }
                            }
                        },
                        create: {
                            type: 'void',
                            title: '{{t("Add role")}}',
                            'x-component': 'Action',
                            'x-component-props': {
                                type: 'primary'
                            },
                            properties: {
                                drawer: {
                                    type: 'void',
                                    'x-component': 'Action.Drawer',
                                    'x-decorator': 'Form',
                                    'x-decorator-props': {
                                        useValues (options) {
                                            const ctx = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useActionContext)();
                                            return (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(()=>Promise.resolve({
                                                    data: {
                                                        name: "r_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)()),
                                                        snippets: [
                                                            '!ui.*',
                                                            '!pm',
                                                            '!pm.*'
                                                        ]
                                                    }
                                                }), {
                                                ...options,
                                                refreshDeps: [
                                                    ctx.visible
                                                ]
                                            });
                                        }
                                    },
                                    title: '{{t("Add role")}}',
                                    properties: {
                                        title: {
                                            'x-component': 'CollectionField',
                                            'x-decorator': 'FormItem'
                                        },
                                        name: {
                                            'x-component': 'CollectionField',
                                            'x-decorator': 'FormItem',
                                            description: '{{t("Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.")}}'
                                        },
                                        default: {
                                            'x-component': 'CollectionField',
                                            'x-decorator': 'FormItem',
                                            title: '',
                                            'x-content': '{{t("Default role")}}'
                                        },
                                        footer: {
                                            type: 'void',
                                            'x-component': 'Action.Drawer.Footer',
                                            properties: {
                                                cancel: {
                                                    title: '{{t("Cancel")}}',
                                                    'x-component': 'Action',
                                                    'x-component-props': {
                                                        useAction: '{{ cm.useCancelAction }}'
                                                    }
                                                },
                                                submit: {
                                                    title: '{{t("Submit")}}',
                                                    'x-component': 'Action',
                                                    'x-component-props': {
                                                        type: 'primary',
                                                        useAction: '{{ cm.useCreateAction }}'
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                table: {
                    type: 'void',
                    'x-uid': 'input',
                    'x-component': 'Table.Void',
                    'x-component-props': {
                        rowKey: 'name',
                        rowSelection: {
                            type: 'checkbox'
                        },
                        useDataSource: '{{ cm.useDataSourceFromRAC }}'
                    },
                    properties: {
                        column1: {
                            type: 'void',
                            'x-decorator': 'Table.Column.Decorator',
                            'x-component': 'Table.Column',
                            properties: {
                                title: {
                                    type: 'number',
                                    'x-component': 'CollectionField',
                                    'x-read-pretty': true
                                }
                            }
                        },
                        column2: {
                            type: 'void',
                            'x-decorator': 'Table.Column.Decorator',
                            'x-component': 'Table.Column',
                            properties: {
                                name: {
                                    type: 'string',
                                    'x-component': 'CollectionField',
                                    'x-read-pretty': true
                                }
                            }
                        },
                        column3: {
                            type: 'void',
                            'x-decorator': 'Table.Column.Decorator',
                            'x-component': 'Table.Column',
                            properties: {
                                default: {
                                    type: 'string',
                                    'x-component': 'CollectionField',
                                    'x-read-pretty': true
                                }
                            }
                        },
                        column4: {
                            type: 'void',
                            title: '{{t("Actions")}}',
                            'x-component': 'Table.Column',
                            properties: {
                                actions: {
                                    type: 'void',
                                    'x-component': 'Space',
                                    'x-component-props': {
                                        split: '|'
                                    },
                                    properties: {
                                        view: {
                                            type: 'void',
                                            title: '{{t("Configure")}}',
                                            'x-component': 'Action.Link',
                                            'x-decorator': 'ACLActionProvider',
                                            'x-acl-action': 'roles:update',
                                            'x-component-props': {},
                                            properties: {
                                                drawer: {
                                                    type: 'void',
                                                    'x-component': 'Action.Drawer',
                                                    'x-decorator': 'PermissionProvider',
                                                    title: '{{t("Configure permissions")}}',
                                                    properties: {
                                                        tabs1: {
                                                            type: 'void',
                                                            'x-component': 'Tabs',
                                                            'x-component-props': {},
                                                            properties: {
                                                                tab1: {
                                                                    type: 'void',
                                                                    title: '{{t("General permissions")}}',
                                                                    'x-component': 'Tabs.TabPane',
                                                                    'x-component-props': {},
                                                                    properties: {
                                                                        role: {
                                                                            'x-component': 'RoleConfigure'
                                                                        }
                                                                    }
                                                                },
                                                                tab3: {
                                                                    type: 'void',
                                                                    title: '{{t("Menu permissions")}}',
                                                                    'x-component': 'Tabs.TabPane',
                                                                    'x-component-props': {},
                                                                    properties: {
                                                                        menu: {
                                                                            'x-decorator': 'MenuItemsProvider',
                                                                            'x-component': 'MenuConfigure'
                                                                        }
                                                                    }
                                                                },
                                                                tab4: {
                                                                    type: 'void',
                                                                    title: '{{t("Plugin settings permissions")}}',
                                                                    'x-decorator': 'SettingCenterPermissionProvider',
                                                                    'x-component': 'Tabs.TabPane',
                                                                    'x-component-props': {},
                                                                    properties: {
                                                                        menu: {
                                                                            'x-decorator': 'SettingCenterProvider',
                                                                            'x-component': 'SettingsCenterConfigure'
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        update: {
                                            type: 'void',
                                            title: '{{t("Edit")}}',
                                            'x-decorator': 'ACLActionProvider',
                                            'x-acl-action': 'roles:update',
                                            'x-component': 'Action.Link',
                                            'x-component-props': {
                                                type: 'primary'
                                            },
                                            properties: {
                                                drawer: {
                                                    type: 'void',
                                                    'x-component': 'Action.Drawer',
                                                    'x-decorator': 'Form',
                                                    'x-decorator-props': {
                                                        useValues: (options)=>{
                                                            const record = (0, __WEBPACK_EXTERNAL_MODULE__record_provider_index_mjs__.useRecord)();
                                                            const result = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(()=>Promise.resolve({
                                                                    data: (0, __WEBPACK_EXTERNAL_MODULE_lodash_pick__["default"])(record, [
                                                                        'title',
                                                                        'name',
                                                                        'default'
                                                                    ])
                                                                }), {
                                                                ...options,
                                                                manual: true
                                                            });
                                                            const ctx = (0, __WEBPACK_EXTERNAL_MODULE__schema_component_index_mjs__.useActionContext)();
                                                            (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
                                                                if (ctx.visible) result.run();
                                                            }, [
                                                                ctx.visible
                                                            ]);
                                                            return result;
                                                        }
                                                    },
                                                    title: '{{t("Edit role")}}',
                                                    properties: {
                                                        title: {
                                                            'x-component': 'CollectionField',
                                                            'x-decorator': 'FormItem'
                                                        },
                                                        name: {
                                                            'x-component': 'CollectionField',
                                                            'x-decorator': 'FormItem',
                                                            'x-disabled': true
                                                        },
                                                        default: {
                                                            title: '',
                                                            'x-component': 'CollectionField',
                                                            'x-decorator': 'FormItem',
                                                            'x-content': '{{t("Default role")}}'
                                                        },
                                                        footer: {
                                                            type: 'void',
                                                            'x-component': 'Action.Drawer.Footer',
                                                            properties: {
                                                                cancel: {
                                                                    title: '{{t("Cancel")}}',
                                                                    'x-component': 'Action',
                                                                    'x-component-props': {
                                                                        useAction: '{{ cm.useCancelAction }}'
                                                                    }
                                                                },
                                                                submit: {
                                                                    title: '{{t("Submit")}}',
                                                                    'x-component': 'Action',
                                                                    'x-component-props': {
                                                                        type: 'primary',
                                                                        useAction: '{{ cm.useUpdateAction }}'
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        },
                                        delete: {
                                            type: 'void',
                                            title: '{{ t("Delete") }}',
                                            'x-acl-action': 'roles:destroy',
                                            'x-decorator': 'ACLActionProvider',
                                            'x-component': 'Action.Link',
                                            'x-component-props': {
                                                confirm: {
                                                    title: "{{t('Delete role')}}",
                                                    content: "{{t('Are you sure you want to delete it?')}}"
                                                },
                                                useAction: '{{cm.useDestroyAction}}'
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
};
export { roleSchema };
