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