import{v as b}from"./chunk-LVABW27A.js";import{Ld as T,a as w,b as K}from"./chunk-VQ6IH7OA.js";function x(){return{ids:[],entities:{}}}function C(){function u(l={}){return Object.assign(x(),l)}return{getInitialState:u}}function V(){function u(l){let a=y=>y.ids,h=y=>y.entities,p=b(a,h,(y,B)=>y.map(E=>B[E])),M=b(a,y=>y.length);return l?{selectIds:b(l,a),selectEntities:b(l,h),selectAll:b(l,p),selectTotal:b(l,M)}:{selectIds:a,selectEntities:h,selectAll:p,selectTotal:M}}return{getSelectors:u}}var r=function(u){return u[u.EntitiesOnly=0]="EntitiesOnly",u[u.Both=1]="Both",u[u.None=2]="None",u}(r||{});function d(u){return function(a,h){let p={ids:[...h.ids],entities:w({},h.entities)},M=u(a,p);return M===r.Both?Object.assign({},h,p):M===r.EntitiesOnly?K(w({},h),{entities:p.entities}):h}}function m(u,l){let a=l(u);return T()&&a===void 0&&console.warn("@ngrx/entity: The entity passed to the `selectId` implementation returned undefined.","You should probably provide your own `selectId` implementation.","The entity that was passed:",u,"The `selectId` implementation:",l.toString()),a}function F(u){function l(s,t){let e=m(s,u);return e in t.entities?r.None:(t.ids.push(e),t.entities[e]=s,r.Both)}function a(s,t){let e=!1;for(let n of s)e=l(n,t)!==r.None||e;return e?r.Both:r.None}function h(s,t){return t.ids=[],t.entities={},a(s,t),r.Both}function p(s,t){let e=m(s,u);return e in t.entities?(t.entities[e]=s,r.EntitiesOnly):(t.ids.push(e),t.entities[e]=s,r.Both)}function M(s,t){let e=s.map(n=>p(n,t));switch(!0){case e.some(n=>n===r.Both):return r.Both;case e.some(n=>n===r.EntitiesOnly):return r.EntitiesOnly;default:return r.None}}function y(s,t){return B([s],t)}function B(s,t){let n=(s instanceof Array?s:t.ids.filter(i=>s(t.entities[i]))).filter(i=>i in t.entities).map(i=>delete t.entities[i]).length>0;return n&&(t.ids=t.ids.filter(i=>i in t.entities)),n?r.Both:r.None}function E(s){return Object.assign({},s,{ids:[],entities:{}})}function I(s,t,e){let n=e.entities[t.id],i=Object.assign({},n,t.changes),o=m(i,u),c=o!==t.id;return c&&(s[t.id]=o,delete e.entities[t.id]),e.entities[o]=i,c}function v(s,t){return N([s],t)}function N(s,t){let e={};return s=s.filter(i=>i.id in t.entities),s.length>0?s.filter(o=>I(e,o,t)).length>0?(t.ids=t.ids.map(o=>e[o]||o),r.Both):r.EntitiesOnly:r.None}function A(s,t){let n=t.ids.reduce((i,o)=>{let c=s(t.entities[o]);return c!==t.entities[o]&&i.push({id:o,changes:c}),i},[]).filter(({id:i})=>i in t.entities);return N(n,t)}function j({map:s,id:t},e){let n=e.entities[t];if(!n)return r.None;let i=s(n);return v({id:t,changes:i},e)}function k(s,t){return S([s],t)}function S(s,t){let e=[],n=[];for(let c of s){let f=m(c,u);f in t.entities?n.push({id:f,changes:c}):e.push(c)}let i=N(n,t),o=a(e,t);switch(!0){case(o===r.None&&i===r.None):return r.None;case(o===r.Both||i===r.Both):return r.Both;default:return r.EntitiesOnly}}return{removeAll:E,addOne:d(l),addMany:d(a),setAll:d(h),setOne:d(p),setMany:d(M),updateOne:d(v),updateMany:d(N),upsertOne:d(k),upsertMany:d(S),removeOne:d(y),removeMany:d(B),map:d(A),mapOne:d(j)}}function Y(u,l){let{removeOne:a,removeMany:h,removeAll:p}=F(u);function M(e,n){return y([e],n)}function y(e,n){let i=e.filter(o=>!(m(o,u)in n.entities));return i.length===0?r.None:(t(i,n),r.Both)}function B(e,n){return n.entities={},n.ids=[],y(e,n),r.Both}function E(e,n){let i=m(e,u);return i in n.entities?(n.ids=n.ids.filter(o=>o!==i),t([e],n),r.Both):M(e,n)}function I(e,n){let i=e.map(o=>E(o,n));switch(!0){case i.some(o=>o===r.Both):return r.Both;case i.some(o=>o===r.EntitiesOnly):return r.EntitiesOnly;default:return r.None}}function v(e,n){return A([e],n)}function N(e,n,i){if(!(n.id in i.entities))return!1;let o=i.entities[n.id],c=Object.assign({},o,n.changes),f=m(c,u);return delete i.entities[n.id],e.push(c),f!==n.id}function A(e,n){let i=[],o=e.filter(c=>N(i,c,n)).length>0;if(i.length===0)return r.None;{let c=n.ids,f=[];return n.ids=n.ids.filter((O,g)=>O in n.entities?!0:(f.push(g),!1)),t(i,n),!o&&f.every(O=>n.ids[O]===c[O])?r.EntitiesOnly:r.Both}}function j(e,n){let i=n.ids.reduce((o,c)=>{let f=e(n.entities[c]);return f!==n.entities[c]&&o.push({id:c,changes:f}),o},[]);return A(i,n)}function k({map:e,id:n},i){let o=i.entities[n];if(!o)return r.None;let c=e(o);return v({id:n,changes:c},i)}function S(e,n){return s([e],n)}function s(e,n){let i=[],o=[];for(let O of e){let g=m(O,u);g in n.entities?o.push({id:g,changes:O}):i.push(O)}let c=A(o,n),f=y(i,n);switch(!0){case(f===r.None&&c===r.None):return r.None;case(f===r.Both||c===r.Both):return r.Both;default:return r.EntitiesOnly}}function t(e,n){e.sort(l);let i=[],o=0,c=0;for(;o<e.length&&c<n.ids.length;){let f=e[o],O=m(f,u),g=n.ids[c],U=n.entities[g];l(f,U)<=0?(i.push(O),o++):(i.push(g),c++)}o<e.length?n.ids=i.concat(e.slice(o).map(u)):n.ids=i.concat(n.ids.slice(c)),e.forEach((f,O)=>{n.entities[u(f)]=f})}return{removeOne:a,removeMany:h,removeAll:p,addOne:d(M),updateOne:d(v),upsertOne:d(S),setAll:d(B),setOne:d(E),setMany:d(I),addMany:d(y),updateMany:d(A),upsertMany:d(s),map:d(j),mapOne:d(k)}}function G(u={}){let{selectId:l,sortComparer:a}={selectId:u.selectId??(y=>y.id),sortComparer:u.sortComparer??!1},h=C(),p=V(),M=a?Y(l,a):F(l);return w(w(w({selectId:l,sortComparer:a},h),p),M)}export{G as a};