/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/js-tree-operator@0.5.0/dist/index.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __assign=function(){return __assign=Object.assign||function(r){for(var t,e=1,i=arguments.length;e<i;e++)for(var n in t=arguments[e])Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r},__assign.apply(this,arguments)};function __spreadArray(r,t,e){if(e||2===arguments.length)for(var i,n=0,s=t.length;n<s;n++)!i&&n in t||(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return r.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var config={childrenName:"children",pidName:"pid",primaryKeyName:"id"},globalConfig=function(r){config=Object.assign(config,r)},T=function(){function r(r){var t=this;this.deepClone=function(r){if("object"!=typeof r||null===r)return r;if(Array.isArray(r)){var e=[];return r.forEach((function(r){e.push(t.deepClone(r))})),e}var i={};for(var n in r)r.hasOwnProperty(n)&&(i[n]=t.deepClone(r[n]));return i},r&&(this.treeData=r,this.result=r);var e=config.childrenName,i=config.primaryKeyName,n=config.pidName;this.childrenName=e,this.primaryKeyName=i,this.pidName=n}return r.prototype.matchCondition=function(r,t,e){for(var i in t)if(null==e?void 0:e.useLike){if(r[i].indexOf(t[i])<0)return!1}else if(r[i]!==t[i])return!1;return!0},r.prototype.removeArrayItem=function(r,t){return r.splice(t,1),r},r.prototype.getCurrentIndex=function(){var r=this.result,t=this.parent().result,e=t[this.childrenName]||t;return this.result=r,{index:e.findIndex((function(t){return t===r})),children:e}},r.prototype.setConfig=function(r){var t=r.childrenName,e=r.primaryKeyName,i=r.pidName;return t&&(this.childrenName=t),e&&(this.primaryKeyName=e),i&&(this.pidName=i),this},r.prototype.showConfig=function(){return console.log(this.childrenName,this.primaryKeyName,this.pidName),this},r.prototype.current=function(r){return this.result=r,this},r.prototype.getAll=function(r,t){var e=this,i=[],n=function(s){for(var a=0,h=s;a<h.length;a++){var o=h[a];e.matchCondition(o,r,t)&&i.push(o),o[e.childrenName]&&o[e.childrenName].length>0&&n(o[e.childrenName])}};return n(this.treeData),this.result=i,this},r.prototype.getFirst=function(r,t){var e=this,i=null,n=function(s){for(var a=0,h=s;a<h.length;a++){var o=h[a];if(e.matchCondition(o,r,t))return i=o;o[e.childrenName]&&o[e.childrenName].length>0&&n(o[e.childrenName])}};return n(this.treeData),this.result=i,this},r.prototype.getByKeys=function(r,t,e){var i=null==e?void 0:e.useLike,n=[];return i?this.forEach((function(e){t.forEach((function(t){e[r].indexOf(t)>=0&&n.push(e)}))})):this.forEach((function(e){t.includes(e[r])&&n.push(e)})),this.result=n,this},r.prototype.first=function(){return this.result=this.result[0],this},r.prototype.parents=function(){var r=this,t=[],e=function(i,n,s){void 0===s&&(s=[]);for(var a=0,h=n;a<h.length;a++){var o=h[a];if(o[r.childrenName]){var l=o;o[r.childrenName].some((function(r){return r===i}))&&t.push.apply(t,__spreadArray(__spreadArray([],s,!1),[l],!1)),e(i,o[r.childrenName],__spreadArray(__spreadArray([],s,!0),[l],!1))}}};return Array.isArray(this.result)?this.result.forEach((function(t){e(t,r.treeData)})):e(this.result,this.treeData),this.result=t,this},r.prototype.parent=function(){var r=this,t=null,e=function(i,n){for(var s=0,a=n;s<a.length;s++){var h=a[s];if(h===i)return t=n;if(h[r.childrenName]){if(h[r.childrenName].some((function(r){return r===i})))return t=h;e(i,h[r.childrenName])}}};return e(this.result,this.treeData),this.result=t,this},r.prototype.flat=function(){var r=this,t=[],e=function(i){t.push(i),i[r.childrenName]&&i[r.childrenName].forEach((function(r){e(r)}))};return e(this.result),this.result=t,this},r.prototype.forEach=function(r){var t=this,e=function(i,n){for(var s=Array.isArray(i)?i:[i],a=0;a<s.length;a++){var h=s[a],o=a,l=0===o,u=o===s.length-1;r&&r(h,{index:o,isFirst:l,isLast:u}),h[t.childrenName]&&h[t.childrenName].length>0&&e(h[t.childrenName])}};return e(this.result),this},r.prototype.next=function(){var r=this.result,t=this.parent().result;if(t){var e=t[this.childrenName]||t,i=0;e.forEach((function(t,e){t===r&&(i=e)})),this.result=i<e.length-1?e[i+1]:null}else this.result=null;return this},r.prototype.nextAll=function(){var r=this.result,t=this.parent().result;if(t){for(var e=t[this.childrenName]||t,i=!1,n=[],s=0;s<e.length;s++){var a=e[s];a!==r?i&&n.push(a):i=!0}this.result=n}else this.result=[];return this},r.prototype.prev=function(){var r=this.result,t=this.parent().result;if(t){var e=t[this.childrenName]||t,i=0;e.forEach((function(t,e){t===r&&(i=e)})),this.result=i>0?e[i-1]:null}else this.result=null;return this},r.prototype.prevAll=function(){var r=this.result,t=this.parent().result;if(t){for(var e=t[this.childrenName]||t,i=!0,n=[],s=0;s<e.length;s++){var a=e[s];a!==r?i&&n.push(a):i=!1}this.result=n}else this.result=[];return this},r.prototype.siblings=function(){var r=this.result,t=this.parent().result;if(t){for(var e=t[this.childrenName]||t,i=[],n=0;n<e.length;n++){var s=e[n];s!==r&&i.push(s)}this.result=i}else this.result=[];return this},r.prototype.remove=function(r){var t=this,e=r||this.result;return e===this.treeData?(this.result=[],this):((Array.isArray(e)?e:[e]).forEach((function(r){t.result=r;var e=t.parent().result;if(e){var i=e[t.childrenName]||e,n=i.findIndex((function(t){return t===r}));-1!==n&&i.splice(n,1)}})),this.result=this.treeData,this)},r.prototype.prepend=function(r){var t=this.getCurrentIndex(),e=t.index,i=t.children;return i.splice.apply(i,__spreadArray([e,0],r,!1)),this.result=i,this},r.prototype.append=function(r){var t=this.getCurrentIndex(),e=t.index,i=t.children;return i.splice.apply(i,__spreadArray([e+1,0],r,!1)),this.result=i,this},r.prototype.clone=function(){return this.result=this.deepClone(this.result),this},r.prototype.listToTree=function(r){var t=this.primaryKeyName,e=this.pidName;if(!Array.isArray(this.treeData))throw new Error("list must be an array");for(var i={},n=[],s=0,a=this.treeData;s<a.length;s++){i[(l=a[s])[t]]=__assign({},l)}for(var h=0,o=this.treeData;h<o.length;h++){var l,u=i[(l=o[h])[t]],c=l[e],p=i[c];void 0!==r&&c===r||void 0===r&&(!p||null==c)?n.push(u):p&&(p[this.childrenName]||(p[this.childrenName]=[]),p[this.childrenName].push(u))}if(0===n.length)throw new Error("cannot find tree root!");return this.result=n,this.treeData=n,this},r.prototype.treeToList=function(){var r=this,t=[],e=function(i,n){void 0===n&&(n=null),i.forEach((function(i){var s={};for(var a in i)a!==r.childrenName&&(s[a]=i[a],s[r.pidName]=n||i[r.pidName]);t.push(s);var h=i[r.childrenName];h&&h.length>0&&e(h,i[r.primaryKeyName])}))};return e(this.treeData),this.result=t,this},r.prototype.siblingsLength=function(){return this.parent().result[this.childrenName].length-1},r.prototype.toFieldArray=function(r,t){void 0===t&&(t=!0);var e=[];return t?this.forEach((function(t){return e.push(t[r])})):e=this.result.map((function(t){return t[r]})),e},r.prototype.addDepth=function(r){var t=this;void 0===r&&(r="depth");var e=function(i,n){void 0===n&&(n=0);for(var s=0,a=Array.isArray(i)?i:[i];s<a.length;s++){var h=a[s];h[r]=n,h[t.childrenName]&&h[t.childrenName].length>0&&e(h[t.childrenName],n+1)}};return e(this.result),this},r.prototype.getRightNodes=function(r){for(var t=[],e=Array.isArray(this.result)?this.result:[this.result];e.length>0;){var i=e[e.length-1];if(!i)break;t.push(i),null==r||r(i),e=i[this.childrenName]||[]}return this.result=t,this},r.prototype.filter=function(r){var t=this,e=function(i){if(!Array.isArray(i))return i;for(var n=[],s=0,a=i;s<a.length;s++){var h=a[s];if(r(h))(o=t.deepClone(h))[t.childrenName]&&Array.isArray(o[t.childrenName])&&o[t.childrenName].length>0&&(o[t.childrenName]=e(o[t.childrenName])),n.push(o);else if(h[t.childrenName]&&Array.isArray(h[t.childrenName])&&h[t.childrenName].length>0){var o,l=e(h[t.childrenName]);if(l.length>0)(o=t.deepClone(h))[t.childrenName]=l,n.push(o)}}return n},i=e(this.treeData);return this.result=i,this},r}(),index=function(r){return new T(r)};exports.default=index,exports.globalConfig=globalConfig;
//# sourceMappingURL=/sm/837dcb798e18d646d741db2e5368285694137749c970661aee5a575b5cf9ff03.map