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