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