/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import t from"../Accessor.js";import e from"../Collection.js";import{getProperties as n}from"./utils.js";const o=new Set(["esri.Color","esri.portal.Portal","esri.symbols.support.Symbol3DAnchorPosition2D","esri.symbols.support.Symbol3DAnchorPosition3D"]);function r(e){return e instanceof t}function f(t){return t instanceof e?Object.keys(t.items):r(t)?n(t).keys():t?Object.keys(t):[]}function i(t,n){return t instanceof e?t.items[n]:t[n]}function l(t,e){return!(!Array.isArray(t)||!Array.isArray(e))&&t.length!==e.length}function u(t){return t?t.declaredClass:null}function c(t,e){const n=t.diff;if(n&&"function"==typeof n)return n(t,e);const s=f(t),p=f(e);if(0===s.length&&0===p.length)return;if(!s.length||!p.length||l(t,e))return{type:"complete",oldValue:t,newValue:e};const a=p.filter(t=>!s.includes(t)),y=s.filter(t=>!p.includes(t)),d=s.filter(n=>p.includes(n)&&i(t,n)!==i(e,n)).concat(a,y).sort(),m=u(t);if(m&&o.has(m)&&d.length)return{type:"complete",oldValue:t,newValue:e};let h;const b=r(t)&&r(e);for(const o of d){const r=i(t,o),f=i(e,o);let l;if((b||"function"!=typeof r&&"function"!=typeof f)&&(r!==f&&(null!=r||null!=f))){if(n&&n[o]&&"function"==typeof n[o])l=n[o]?.(r,f);else if(r instanceof Date&&f instanceof Date){if(r.getTime()===f.getTime())continue;l={type:"complete",oldValue:r,newValue:f}}else l="object"==typeof r&&"object"==typeof f&&u(r)===u(f)?c(r,f):{type:"complete",oldValue:r,newValue:f};null!=l&&(null!=h?h.diff[o]=l:h={type:"partial",diff:{[o]:l}})}}return h}function s(t,e){return p(t,e)}function p(t,e){if(null==t)return!1;const n=e.split(".");let o=t;for(const r of n){if("complete"===o.type)return!0;if("partial"!==o.type)return!1;{const t=o.diff[r];if(!t)return!1;o=t}}return!0}function a(t,e){if(!t)return!1;if("partial"===t.type){const n=Object.keys(t.diff);return 1===n.length&&n[0]===e}return!1}function y(t,e){if("function"!=typeof t&&"function"!=typeof e&&(null!=t||null!=e))return null==t||null==e||"object"==typeof t&&"object"==typeof e&&u(t)!==u(e)?{type:"complete",oldValue:t,newValue:e}:c(t,e)}function d(t){if(null==t)return!0;switch(t.type){case"complete":return!1;case"collection":{const e=t;for(const t of e.added)if(!d(t))return!1;for(const t of e.removed)if(!d(t))return!1;for(const t of e.changed)if(!d(t))return!1;return!0}case"partial":for(const e in t.diff){if(!d(t.diff[e]))return!1}return!0}}export{y as diff,p as hasDiff,s as hasRootDiff,a as hasRootDiffOnly,d as isEmpty};
