Liferay.Loader.define("data-engine-taglib@3.3.26/data_layout_builder/js/components/rules/RuleEditorModal",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/data-provider","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/modal","data-engine-js-components-web","frontend-js-web","liferay!frontend-js-react-web$react","./editor/Editor.es"],(function(e,t,a){var r;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function({onClose:t,onSaveRule:a,rule:r,showModal:n}){const{observer:l,onClose:o}=(0,u.useModal)({onClose:t});if(!n)return null;return d.default.createElement(u.default,{className:"data-layout-builder-editor-modal",observer:l,size:"full-screen"},d.default.createElement(e,{onClose:o,onSaveRule:a,rule:r}))};var n=(r=a("@frontend-taglib-clay$clayui/button"))&&r.__esModule?r:{default:r},l=a("@frontend-taglib-clay$clayui/data-provider"),o=a("@frontend-taglib-clay$clayui/form"),u=p(a("@frontend-taglib-clay$clayui/modal")),i=a("data-engine-js-components-web"),c=a("frontend-js-web"),d=p(a("liferay!frontend-js-react-web$react")),f=a("./editor/Editor.es");function s(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return s=function(){return e},e}function p(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=s();if(t&&t.has(e))return t.get(e);var a={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=r?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(a,n,l):a[n]=e[n]}return a.default=e,t&&t.set(e,a),a}function g(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function y(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?g(Object(a),!0).forEach((function(t){b(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):g(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function b(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const e=({onClose:e,onSaveRule:t,rule:a})=>{var r;const{ruleSettings:{functionsMetadata:s,functionsURL:p}}=(0,i.useConfig)(),{pages:g}=(0,i.useFormState)(),[b,m]=(0,d.useState)(!0),[v,j]=(0,d.useState)(null!==(r=null==a?void 0:a.name[themeDisplay.getDefaultLanguageId()])&&void 0!==r?r:""),w=(0,d.useRef)(a),{resource:O}=(0,l.useResource)({fetch:c.fetch,link:"".concat(window.location.origin,"/o/headless-admin-user/v1.0/roles")}),E=(0,d.useMemo)((()=>null==O?void 0:O.items.map((({id:e,name:t})=>({id:"".concat(e),label:t,name:t,value:t})))),[O]),L=(0,d.useMemo)((()=>function(e){return e.map((({title:e},t)=>({label:"".concat(t+1," ").concat(e||Liferay.Language.get("page-title")),name:t.toString(),value:t.toString()})))}(g)),[g]),h=(0,d.useMemo)((()=>function(e){const t=[];return new i.PagesVisitor(e).mapFields(((e,a,r,n,l)=>{"fieldset"!==e.type&&t.push(y(y({},e),{},{pageIndex:l,value:e.fieldName}))}),!0,!0),t}(g)),[g]);return d.default.createElement(d.default.Fragment,null,d.default.createElement(u.default.Header,null,a?Liferay.Language.get("edit-rule"):Liferay.Language.get("create-new-rule")),d.default.createElement(u.default.Header,{withTitle:!1},d.default.createElement(o.ClayInput.Group,{className:"pl-4 pr-4"},d.default.createElement(o.ClayInput.GroupItem,null,d.default.createElement(o.ClayInput,{"aria-label":Liferay.Language.get("rule-title"),className:"form-control-inline",onChange:({target:{value:e}})=>j(e),placeholder:Liferay.Language.get("untitled-rule"),type:"text",value:v})))),d.default.createElement(u.default.Body,null,d.default.createElement(f.Editor,{allowActions:["show","enable","require","calculate","jump-to-page"],className:"pl-4 pr-4",dataProvider:[],fields:h,functionsURL:p,onChange:e=>{w.current=e},onValidator:e=>m(!e),operatorsByType:s,pages:L,roles:E,rule:a})),d.default.createElement(u.default.Footer,{last:d.default.createElement(n.default.Group,{spaced:!0},d.default.createElement(n.default,{displayType:"secondary",onClick:e},Liferay.Language.get("cancel")),d.default.createElement(n.default,{disabled:b||!v,onClick:()=>{t(y(y({},w.current),{},{name:v})),e()}},Liferay.Language.get("save")))}))}}}));
//# sourceMappingURL=RuleEditorModal.js.map