Liferay.Loader.define("segments-web@3.0.68/js/components/criteria_builder/CriteriaBuilder.es",["module","exports","require","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utils/types.es","../../utils/utils.es","./CriteriaGroup.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;a(r("liferay!frontend-js-react-web$prop-types"));var i=function(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 r={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=i?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")),n=(r("../../utils/types.es"),r("../../utils/utils.es")),o=a(r("./CriteriaGroup.es"));function s(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return s=function(){return e},e}function a(e){return e&&e.__esModule?e:{default:e}}function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class e extends i.Component{constructor(...e){super(...e),c(this,"_handleCriteriaChange",(e=>{const t=this._cleanCriteriaMapItems([e],!0);this.props.onChange(t[t.length-1],this.props.propertyKey)})),c(this,"_handleCriterionMove",((...e)=>{const t=this._searchAndUpdateCriteria(this.props.criteria,...e);this._handleCriteriaChange(t)})),c(this,"_searchAndUpdateCriteria",((e,t,r,i,o,s,a)=>{let p=e.items;return e.groupId===i&&(p=a?(0,n.replaceAtIndex)(s,p,o):(0,n.insertAtIndex)(s,p,o)),e.groupId===t&&(p=(0,n.removeAtIndex)(p,i===t&&o<r&&!a?r+1:r)),u(u({},e),{},{items:p.map((e=>this._isGroupItem(e)?this._searchAndUpdateCriteria(e,t,r,i,o,s,a):e))})}))}_cleanCriteriaMapItems(e,t){return e.filter((({items:e})=>!e||e.length)).map((e=>{let r=e;if(e.items)if(1===e.items.length){const i=e.items[0];r=i.items?{conjunctionName:i.conjunctionName,groupId:i.groupId,items:this._cleanCriteriaMapItems(i.items)}:t?e:i}else r=u(u({},e),{},{items:this._cleanCriteriaMapItems(e.items)});return r}))}_isGroupItem(e){return e.items&&e.items.length}render(){const{criteria:e,editing:t,emptyContributors:r,entityName:s,modelLabel:a,propertyKey:p,renderEmptyValuesErrors:u,supportedConjunctions:c,supportedOperators:l,supportedProperties:d,supportedPropertyTypes:f}=this.props;return i.default.createElement("div",{className:"criteria-builder-root"},i.default.createElement("h4",{className:"sheet-subtitle"},(0,n.sub)(Liferay.Language.get("x-with-property-x"),[a,""],!1)),(!r||t)&&i.default.createElement(o.default,{criteria:e,editing:t,emptyContributors:r,entityName:s,groupId:e&&e.groupId,modelLabel:a,onChange:this._handleCriteriaChange,onMove:this._handleCriterionMove,propertyKey:p,renderEmptyValuesErrors:u,root:!0,supportedConjunctions:c,supportedOperators:l,supportedProperties:d,supportedPropertyTypes:f}))}}var l=e;t.default=l}}));
//# sourceMappingURL=CriteriaBuilder.es.js.map