"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    RoleConfigure: ()=>RoleConfigure
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const uniq_namespaceObject = require("lodash/uniq");
var uniq_default = /*#__PURE__*/ __webpack_require__.n(uniq_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const index_js_namespaceObject = require("../../../api-client/index.js");
const external_schema_component_index_js_namespaceObject = require("../../../schema-component/index.js");
const external_PermisionProvider_js_namespaceObject = require("./PermisionProvider.js");
const SnippetCheckboxGroup = (0, schema_namespaceObject.connect)((props)=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Checkbox.Group, {
        style: {
            width: '100%',
            display: 'block'
        },
        value: props.value,
        onChange: (values)=>{
            const snippets = [
                'ui.*',
                'pm',
                'pm.*',
                'app'
            ];
            const disallowSnippets = snippets.map((key)=>"!".concat(key));
            const value = uniq_default()([
                ...props.value || [],
                ...values
            ]).filter((key)=>key && !disallowSnippets.includes(key)).map((key)=>{
                if (!snippets.includes(key) || (null == values ? void 0 : values.includes(key))) return key;
                return "!".concat(key);
            });
            for (const key of snippets)if (!value.includes(key) && !value.includes("!".concat(key))) value.push("!".concat(key));
            props.onChange(value);
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    marginTop: 16
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
                    value: "ui.*",
                    children: t('Allows to configure interface')
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    marginTop: 8
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
                    value: "pm",
                    children: t('Allows to install, activate, disable plugins')
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    marginTop: 8
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
                    value: "pm.*",
                    children: t('Allows to configure plugins')
                })
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                style: {
                    marginTop: 8
                },
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Checkbox, {
                    value: "app",
                    children: t('Allows to clear cache, reboot application')
                })
            })
        ]
    });
});
const RoleConfigure = ()=>{
    const { update, currentRecord } = (0, external_react_namespaceObject.useContext)(external_PermisionProvider_js_namespaceObject.PermissionContext);
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_schema_component_index_js_namespaceObject.SchemaComponent, {
        components: {
            SnippetCheckboxGroup
        },
        schema: {
            type: 'void',
            name: 'form',
            'x-component': 'Form',
            'x-component-props': {
                useValues: (options)=>{
                    const api = (0, index_js_namespaceObject.useAPIClient)();
                    return (0, index_js_namespaceObject.useRequest)(()=>api.resource('roles').get({
                            filterByTk: currentRecord.name
                        }).then((res)=>{
                            var _res_data, _record_snippets;
                            const record = null == res ? void 0 : null === (_res_data = res.data) || void 0 === _res_data ? void 0 : _res_data.data;
                            null === (_record_snippets = record.snippets) || void 0 === _record_snippets || _record_snippets.forEach((key)=>{
                                record[key] = true;
                            });
                            return {
                                data: record
                            };
                        }), options);
                },
                effects () {
                    (0, schema_namespaceObject.onFieldChange)('*', async (field, form)=>{
                        if (!form.modified) return;
                        await update(field, form);
                    });
                }
            },
            properties: {
                snippets: {
                    title: t('Configure permissions'),
                    type: 'boolean',
                    'x-decorator': 'FormItem',
                    'x-component': 'SnippetCheckboxGroup'
                },
                allowNewMenu: {
                    title: t('Menu permissions'),
                    'x-decorator': 'FormItem',
                    'x-component': 'Checkbox',
                    'x-content': t('New menu items are allowed to be accessed by default.')
                }
            }
        }
    });
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
