'use strict'; var u={ADDED:"added",EQUAL:"equal",DELETED:"deleted",UPDATED:"updated"},d={...u,MOVED:"moved"},y={BASIC:"basic",DEEP:"deep"};function p(e,t,i={ignoreArrayOrder:!1}){return typeof e!=typeof t?!1:Array.isArray(e)?e.length!==t.length?!1:i.ignoreArrayOrder?e.every(f=>t.some(s=>JSON.stringify(s)===JSON.stringify(f))):e.every((f,s)=>JSON.stringify(f)===JSON.stringify(t[s])):typeof e=="object"?JSON.stringify(e)===JSON.stringify(t):e===t}function D(e){return !!e&&typeof e=="object"&&!Array.isArray(e)}function O(e,t={statuses:[],granularity:y.BASIC}){let{statuses:i,granularity:f}=t;return e.reduce((s,r)=>{if(f===y.DEEP&&r.subPropertiesDiff){let n=O(r.subPropertiesDiff,t);if(n.length>0)return [...s,{...r,subPropertiesDiff:n}]}if(f===y.DEEP&&r.subDiff){let n=O(r.subDiff,t);if(n.length>0)return [...s,{...r,subDiff:n}]}return i.includes(r.status)?[...s,r]:s},[])}function E(e){return e.some(t=>t.status!==u.EQUAL)?u.UPDATED:u.EQUAL}function A(e,t,i={ignoreArrayOrder:!1,showOnly:{statuses:[],granularity:y.BASIC}}){if(!e)return {type:"object",status:u.EQUAL,diff:[]};let f=[];return Object.entries(e).forEach(([s,r])=>{if(D(r)){let n=[];return Object.entries(r).forEach(([o,c])=>{n.push({property:o,previousValue:t===u.ADDED?void 0:c,currentValue:t===u.ADDED?c:void 0,status:t});}),f.push({property:s,previousValue:t===u.ADDED?void 0:e[s],currentValue:t===u.ADDED?r:void 0,status:t,subPropertiesDiff:n})}return f.push({property:s,previousValue:t===u.ADDED?void 0:e[s],currentValue:t===u.ADDED?r:void 0,status:t})}),i.showOnly&&i.showOnly.statuses.length>0?{type:"object",status:t,diff:O(f,i.showOnly)}:{type:"object",status:t,diff:f}}function P(e,t,i){if(!e)return;let f=Object.entries(e).find(([s])=>p(s,t,i));return f?f[1]:void 0}function j(e,t,i){return p(e,t,i)?u.EQUAL:u.UPDATED}function U(e){return e.some(t=>t.status!==u.EQUAL)?u.UPDATED:u.EQUAL}function S(e,t){if(!e)return;let i=Object.keys(e),f=Object.keys(t),s=i.filter(r=>!f.includes(r));if(s.length>0)return s.map(r=>({property:r,value:e[r]}))}function g(e,t,i){let f=[],s,r=S(e,t);return r&&r.forEach(n=>{f.push({property:n.property,previousValue:n.value,currentValue:void 0,status:u.DELETED});}),Object.entries(t).forEach(([n,o])=>{let c=P(e,n,i);if(!c)return f.push({property:n,previousValue:c,currentValue:o,status:!e||!(n in e)?u.ADDED:c===o?u.EQUAL:u.UPDATED});if(D(o)){let a=g(c,o,i);a&&a.length>0&&(s=a);}c&&f.push({property:n,previousValue:c,currentValue:o,status:j(c,o,i),...!!s&&{subDiff:s}});}),f}function m(e,t,i={ignoreArrayOrder:!1,showOnly:{statuses:[],granularity:y.BASIC}}){if(!e&&!t)return {type:"object",status:u.EQUAL,diff:[]};if(!e)return A(t,u.ADDED,i);if(!t)return A(e,u.DELETED,i);let f=[];Object.entries(t).forEach(([r,n])=>{let o=e[r];if(!o)return f.push({property:r,previousValue:o,currentValue:n,status:r in e?o===n?u.EQUAL:u.UPDATED:u.ADDED});if(D(n)){let c=g(o,n,i),a=U(c);return f.push({property:r,previousValue:o,currentValue:n,status:a,...a!==u.EQUAL&&{subPropertiesDiff:c}})}return f.push({property:r,previousValue:o,currentValue:n,status:j(o,n,i)})});let s=S(e,t);return s&&s.forEach(r=>{f.push({property:r.property,previousValue:r.value,currentValue:void 0,status:u.DELETED});}),i.showOnly&&i.showOnly.statuses.length>0?{type:"object",status:E(f),diff:O(f,i.showOnly)}:{type:"object",status:E(f),diff:f}}function w(e,t=[]){return e.filter(i=>t?.includes(i.status))}function L(e,t,i={showOnly:[]}){let f=e.map((s,r)=>({value:s,prevIndex:t===d.ADDED?null:r,newIndex:t===d.ADDED?r:null,indexDiff:null,status:t}));return i.showOnly&&i.showOnly.length>0?{type:"list",status:t,diff:f.filter(s=>i.showOnly?.includes(s.status))}:{type:"list",status:t,diff:f}}function h(e){return e.some(t=>t.status!==d.EQUAL)?d.UPDATED:d.EQUAL}function T(e,t){return D(e)&&t?Object.hasOwn(e,t):!1}var I=(e,t,i={showOnly:[],referenceProperty:void 0,considerMoveAsUpdate:!1})=>{if(!e&&!t)return {type:"list",status:d.EQUAL,diff:[]};if(!e)return L(t,d.ADDED,i);if(!t)return L(e,d.DELETED,i);let f=[],s=[];return t.forEach((r,n)=>{let o=e.findIndex((a,b)=>T(a,i.referenceProperty)?D(r)?p(a[i.referenceProperty],r[i.referenceProperty])&&!s.includes(b):!1:p(a,r)&&!s.includes(b));o>-1&&s.push(o);let c=o===-1?null:n-o;if(c===0){let a=d.EQUAL;return T(r,i.referenceProperty)&&(p(e[o],r)||(a=d.UPDATED)),f.push({value:r,prevIndex:o,newIndex:n,indexDiff:c,status:a})}return o===-1?f.push({value:r,prevIndex:null,newIndex:n,indexDiff:c,status:d.ADDED}):f.push({value:r,prevIndex:o,newIndex:n,indexDiff:c,status:i.considerMoveAsUpdate?d.UPDATED:d.MOVED})}),e.forEach((r,n)=>{if(!s.includes(n))return f.splice(n,0,{value:r,prevIndex:n,newIndex:null,indexDiff:null,status:d.DELETED})}),i.showOnly&&i?.showOnly?.length>0?{type:"list",status:h(f),diff:w(f,i.showOnly)}:{type:"list",status:h(f),diff:f}}; exports.getListDiff = I; exports.getObjectDiff = m; exports.isEqual = p; exports.isObject = D;