Liferay.Loader.define("dynamic-data-mapping-form-web@4.0.121/admin/js/pages/RuleBuilder.es",["module","exports","require","@frontend-taglib-clay$clayui/data-provider","@frontend-taglib-clay$clayui/layout","data-engine-js-components-web","frontend-js-web","liferay!frontend-js-react-web$react","dynamic-data-mapping-form-web$react-router-dom","../components/ManagementToolbar.es","../eventTypes.es","./RuleEditor.es","./RuleList.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=RuleBuilder;var a=r("@frontend-taglib-clay$clayui/data-provider"),n=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("@frontend-taglib-clay$clayui/layout")),o=r("data-engine-js-components-web"),l=r("frontend-js-web"),i=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 r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=a?Object.getOwnPropertyDescriptor(e,n):null;o&&(o.get||o.set)?Object.defineProperty(r,n,o):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),u=r("dynamic-data-mapping-form-web$react-router-dom"),c=r("../components/ManagementToolbar.es"),d=r("../eventTypes.es"),s=r("./RuleEditor.es"),p=r("./RuleList.es");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function RuleBuilder({history:e,location:t}){const{cache:r,dataProviderInstanceParameterSettingsURL:f,dataProviderInstancesURL:y,functionsMetadata:b,functionsURL:g,portletNamespace:m,rolesURL:E}=(0,o.useConfig)(),{currentRuleLoc:R,pages:j,rules:v}=(0,o.useFormState)(),P=(0,o.useForm)(),{resource:w}=(0,a.useResource)({fetch:l.fetch,link:window.location.origin+y,storage:r,variables:{languageId:themeDisplay.getLanguageId(),scopeGroupId:themeDisplay.getScopeGroupId()}}),{resource:O}=(0,a.useResource)({fetch:l.fetch,link:window.location.origin+E,storage:r}),_=(0,i.useMemo)((()=>{const e=[];return new o.PagesVisitor(j).mapFields(((t,r,a,n,o)=>{"fieldset"!==t.type&&e.push(_objectSpread(_objectSpread({},t),{},{pageIndex:o,value:t.fieldName}))}),!0,!0),e}),[j]),h=(0,i.useMemo)((()=>j.filter((({contentRenderer:e})=>"success"!==e)).map((({title:e},t)=>({label:"".concat(t+1," ").concat(e||Liferay.Language.get("page-title")),name:t.toString(),value:t.toString()})))),[j]),S=null==w?void 0:w.map((e=>_objectSpread(_objectSpread({},e),{},{label:e.name,value:e.id}))),T=null==O?void 0:O.map((e=>_objectSpread(_objectSpread({},e),{},{label:e.name,value:e.name}))),L=(0,i.useCallback)((t=>{(t===e.location.pathname?e.replace:e.push)(t)}),[e]);(0,i.useEffect)((()=>{null!==R&&L("/rules/editor")}),[R,L]);const D=(0,i.useCallback)((()=>{P({payload:{loc:void 0},type:d.EVENT_TYPES.RULE.EDIT}),L("/rules/editor")}),[P,L]);return i.default.createElement(n.default.Container,null,i.default.createElement(c.ManagementToolbar,{onPlusClick:"/rules"===t.pathname?D:null,portletNamespace:m,variant:"rules"}),i.default.createElement(u.Switch,null,i.default.createElement(u.Route,{exact:!0,path:"/rules"},i.default.createElement(p.RuleList,{dataProvider:S,fields:_,onDelete:e=>P({payload:e,type:d.EVENT_TYPES.RULE.DELETE}),onEdit:e=>{P({payload:{loc:e},type:d.EVENT_TYPES.RULE.EDIT}),L("/rules/editor")},operatorsByType:b,pages:h,rules:v})),i.default.createElement(u.Route,{path:"/rules/editor"},i.default.createElement(s.RuleEditor,{dataProvider:S,dataProviderInstanceParameterSettingsURL:f,fields:_,functionsURL:g,onCancel:()=>{L("/rules"),P({payload:{loc:null},type:d.EVENT_TYPES.RULE.EDIT})},onSave:e=>{P(void 0===R?{payload:e,type:d.EVENT_TYPES.RULE.ADD}:{payload:{loc:R,rule:e},type:d.EVENT_TYPES.RULE.CHANGE}),L("/rules")},operatorsByType:b,pages:h,roles:T,rule:v[R]}))))}RuleBuilder.displayName="RuleBuilder"}}));
//# sourceMappingURL=RuleBuilder.es.js.map