var X = Symbol.for("immer-nothing"), K = Symbol.for("immer-draftable"), u = Symbol.for("immer-state"), L = process.env.NODE_ENV !== "production" ? [
  // All error codes, starting by 0:
  function(e) {
    return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
  },
  function(e) {
    return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`;
  },
  "This object has been frozen and should not be mutated",
  function(e) {
    return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + e;
  },
  "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
  "Immer forbids circular references",
  "The first or second argument to `produce` must be a function",
  "The third argument to `produce` must be a function or undefined",
  "First argument to `createDraft` must be a plain object, an array, or an immerable object",
  "First argument to `finishDraft` must be a draft returned by `createDraft`",
  function(e) {
    return `'current' expects a draft, got: ${e}`;
  },
  "Object.defineProperty() cannot be used on an Immer draft",
  "Object.setPrototypeOf() cannot be used on an Immer draft",
  "Immer only supports deleting array indices",
  "Immer only supports setting array indices and the 'length' property",
  function(e) {
    return `'original' expects a draft, got: ${e}`;
  }
  // Note: if more errors are added, the errorOffset in Patches.ts should be increased
  // See Patches.ts for additional errors
] : [];
function d(e, ...t) {
  if (process.env.NODE_ENV !== "production") {
    const r = L[e], n = typeof r == "function" ? r.apply(null, t) : r;
    throw new Error(`[Immer] ${n}`);
  }
  throw new Error(
    `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`
  );
}
var b = Object.getPrototypeOf;
function P(e) {
  return !!e && !!e[u];
}
function p(e) {
  return e ? q(e) || Array.isArray(e) || !!e[K] || !!e.constructor?.[K] || M(e) || N(e) : !1;
}
var V = Object.prototype.constructor.toString();
function q(e) {
  if (!e || typeof e != "object")
    return !1;
  const t = b(e);
  if (t === null)
    return !0;
  const r = Object.hasOwnProperty.call(t, "constructor") && t.constructor;
  return r === Object ? !0 : typeof r == "function" && Function.toString.call(r) === V;
}
function w(e, t) {
  F(e) === 0 ? Reflect.ownKeys(e).forEach((r) => {
    t(r, e[r], e);
  }) : e.forEach((r, n) => t(n, r, e));
}
function F(e) {
  const t = e[u];
  return t ? t.type_ : Array.isArray(e) ? 1 : M(e) ? 2 : N(e) ? 3 : 0;
}
function I(e, t) {
  return F(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
}
function Q(e, t, r) {
  const n = F(e);
  n === 2 ? e.set(t, r) : n === 3 ? e.add(r) : e[t] = r;
}
function ee(e, t) {
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
}
function M(e) {
  return e instanceof Map;
}
function N(e) {
  return e instanceof Set;
}
function _(e) {
  return e.copy_ || e.base_;
}
function k(e, t) {
  if (M(e))
    return new Map(e);
  if (N(e))
    return new Set(e);
  if (Array.isArray(e))
    return Array.prototype.slice.call(e);
  const r = q(e);
  if (t === !0 || t === "class_only" && !r) {
    const n = Object.getOwnPropertyDescriptors(e);
    delete n[u];
    let o = Reflect.ownKeys(n);
    for (let a = 0; a < o.length; a++) {
      const f = o[a], c = n[f];
      c.writable === !1 && (c.writable = !0, c.configurable = !0), (c.get || c.set) && (n[f] = {
        configurable: !0,
        writable: !0,
        // could live with !!desc.set as well here...
        enumerable: c.enumerable,
        value: e[f]
      });
    }
    return Object.create(b(e), n);
  } else {
    const n = b(e);
    if (n !== null && r)
      return { ...e };
    const o = Object.create(n);
    return Object.assign(o, e);
  }
}
function $(e, t = !1) {
  return A(e) || P(e) || !p(e) || (F(e) > 1 && (e.set = e.add = e.clear = e.delete = te), Object.freeze(e), t && Object.entries(e).forEach(([r, n]) => $(n, !0))), e;
}
function te() {
  d(2);
}
function A(e) {
  return Object.isFrozen(e);
}
var T = {};
function g(e) {
  const t = T[e];
  return t || d(0, e), t;
}
function re(e, t) {
  T[e] || (T[e] = t);
}
var z;
function D() {
  return z;
}
function ne(e, t) {
  return {
    drafts_: [],
    parent_: e,
    immer_: t,
    // Whenever the modified draft contains a draft from another scope, we
    // need to prevent auto-freezing so the unowned draft can be finalized.
    canAutoFreeze_: !0,
    unfinalizedDrafts_: 0
  };
}
function B(e, t) {
  t && (g("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
}
function R(e) {
  j(e), e.drafts_.forEach(ie), e.drafts_ = null;
}
function j(e) {
  e === z && (z = e.parent_);
}
function G(e) {
  return z = ne(z, e);
}
function ie(e) {
  const t = e[u];
  t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
}
function H(e, t) {
  t.unfinalizedDrafts_ = t.drafts_.length;
  const r = t.drafts_[0];
  return e !== void 0 && e !== r ? (r[u].modified_ && (R(t), d(4)), p(e) && (e = O(t, e), t.parent_ || E(t, e)), t.patches_ && g("Patches").generateReplacementPatches_(
    r[u].base_,
    e,
    t.patches_,
    t.inversePatches_
  )) : e = O(t, r, []), R(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== X ? e : void 0;
}
function O(e, t, r) {
  if (A(t))
    return t;
  const n = t[u];
  if (!n)
    return w(
      t,
      (o, a) => J(e, n, t, o, a, r)
    ), t;
  if (n.scope_ !== e)
    return t;
  if (!n.modified_)
    return E(e, n.base_, !0), n.base_;
  if (!n.finalized_) {
    n.finalized_ = !0, n.scope_.unfinalizedDrafts_--;
    const o = n.copy_;
    let a = o, f = !1;
    n.type_ === 3 && (a = new Set(o), o.clear(), f = !0), w(
      a,
      (c, i) => J(e, n, o, c, i, r, f)
    ), E(e, o, !1), r && e.patches_ && g("Patches").generatePatches_(
      n,
      r,
      e.patches_,
      e.inversePatches_
    );
  }
  return n.copy_;
}
function J(e, t, r, n, o, a, f) {
  if (process.env.NODE_ENV !== "production" && o === r && d(5), P(o)) {
    const c = a && t && t.type_ !== 3 && // Set objects are atomic since they have no keys.
    !I(t.assigned_, n) ? a.concat(n) : void 0, i = O(e, o, c);
    if (Q(r, n, i), P(i))
      e.canAutoFreeze_ = !1;
    else
      return;
  } else f && r.add(o);
  if (p(o) && !A(o)) {
    if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1)
      return;
    O(e, o), (!t || !t.scope_.parent_) && typeof n != "symbol" && Object.prototype.propertyIsEnumerable.call(r, n) && E(e, o);
  }
}
function E(e, t, r = !1) {
  !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && $(t, r);
}
function se(e, t) {
  const r = Array.isArray(e), n = {
    type_: r ? 1 : 0,
    // Track which produce call this is associated with.
    scope_: t ? t.scope_ : D(),
    // True for both shallow and deep changes.
    modified_: !1,
    // Used during finalization.
    finalized_: !1,
    // Track which properties have been assigned (true) or deleted (false).
    assigned_: {},
    // The parent draft state.
    parent_: t,
    // The base state.
    base_: e,
    // The base proxy.
    draft_: null,
    // set below
    // The base copy with any updated values.
    copy_: null,
    // Called by the `produce` function.
    revoke_: null,
    isManual_: !1
  };
  let o = n, a = U;
  r && (o = [n], a = S);
  const { revoke: f, proxy: c } = Proxy.revocable(o, a);
  return n.draft_ = c, n.revoke_ = f, c;
}
var U = {
  get(e, t) {
    if (t === u)
      return e;
    const r = _(e);
    if (!I(r, t))
      return oe(e, r, t);
    const n = r[t];
    return e.finalized_ || !p(n) ? n : n === x(e.base_, t) ? (C(e), e.copy_[t] = v(n, e)) : n;
  },
  has(e, t) {
    return t in _(e);
  },
  ownKeys(e) {
    return Reflect.ownKeys(_(e));
  },
  set(e, t, r) {
    const n = Y(_(e), t);
    if (n?.set)
      return n.set.call(e.draft_, r), !0;
    if (!e.modified_) {
      const o = x(_(e), t), a = o?.[u];
      if (a && a.base_ === r)
        return e.copy_[t] = r, e.assigned_[t] = !1, !0;
      if (ee(r, o) && (r !== void 0 || I(e.base_, t)))
        return !0;
      C(e), h(e);
    }
    return e.copy_[t] === r && // special case: handle new props with value 'undefined'
    (r !== void 0 || t in e.copy_) || // special case: NaN
    Number.isNaN(r) && Number.isNaN(e.copy_[t]) || (e.copy_[t] = r, e.assigned_[t] = !0), !0;
  },
  deleteProperty(e, t) {
    return x(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, C(e), h(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0;
  },
  // Note: We never coerce `desc.value` into an Immer draft, because we can't make
  // the same guarantee in ES5 mode.
  getOwnPropertyDescriptor(e, t) {
    const r = _(e), n = Reflect.getOwnPropertyDescriptor(r, t);
    return n && {
      writable: !0,
      configurable: e.type_ !== 1 || t !== "length",
      enumerable: n.enumerable,
      value: r[t]
    };
  },
  defineProperty() {
    d(11);
  },
  getPrototypeOf(e) {
    return b(e.base_);
  },
  setPrototypeOf() {
    d(12);
  }
}, S = {};
w(U, (e, t) => {
  S[e] = function() {
    return arguments[0] = arguments[0][0], t.apply(this, arguments);
  };
});
S.deleteProperty = function(e, t) {
  return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && d(13), S.set.call(this, e, t, void 0);
};
S.set = function(e, t, r) {
  return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && d(14), U.set.call(this, e[0], t, r, e[0]);
};
function x(e, t) {
  const r = e[u];
  return (r ? _(r) : e)[t];
}
function oe(e, t, r) {
  const n = Y(t, r);
  return n ? "value" in n ? n.value : (
    // This is a very special case, if the prop is a getter defined by the
    // prototype, we should invoke it with the draft as context!
    n.get?.call(e.draft_)
  ) : void 0;
}
function Y(e, t) {
  if (!(t in e))
    return;
  let r = b(e);
  for (; r; ) {
    const n = Object.getOwnPropertyDescriptor(r, t);
    if (n)
      return n;
    r = b(r);
  }
}
function h(e) {
  e.modified_ || (e.modified_ = !0, e.parent_ && h(e.parent_));
}
function C(e) {
  e.copy_ || (e.copy_ = k(
    e.base_,
    e.scope_.immer_.useStrictShallowCopy_
  ));
}
var ce = class {
  constructor(e) {
    this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.produce = (t, r, n) => {
      if (typeof t == "function" && typeof r != "function") {
        const a = r;
        r = t;
        const f = this;
        return function(i = a, ...s) {
          return f.produce(i, (l) => r.call(this, l, ...s));
        };
      }
      typeof r != "function" && d(6), n !== void 0 && typeof n != "function" && d(7);
      let o;
      if (p(t)) {
        const a = G(this), f = v(t, void 0);
        let c = !0;
        try {
          o = r(f), c = !1;
        } finally {
          c ? R(a) : j(a);
        }
        return B(a, n), H(o, a);
      } else if (!t || typeof t != "object") {
        if (o = r(t), o === void 0 && (o = t), o === X && (o = void 0), this.autoFreeze_ && $(o, !0), n) {
          const a = [], f = [];
          g("Patches").generateReplacementPatches_(t, o, a, f), n(a, f);
        }
        return o;
      } else
        d(1, t);
    }, this.produceWithPatches = (t, r) => {
      if (typeof t == "function")
        return (f, ...c) => this.produceWithPatches(f, (i) => t(i, ...c));
      let n, o;
      return [this.produce(t, r, (f, c) => {
        n = f, o = c;
      }), n, o];
    }, typeof e?.autoFreeze == "boolean" && this.setAutoFreeze(e.autoFreeze), typeof e?.useStrictShallowCopy == "boolean" && this.setUseStrictShallowCopy(e.useStrictShallowCopy);
  }
  createDraft(e) {
    p(e) || d(8), P(e) && (e = ae(e));
    const t = G(this), r = v(e, void 0);
    return r[u].isManual_ = !0, j(t), r;
  }
  finishDraft(e, t) {
    const r = e && e[u];
    (!r || !r.isManual_) && d(9);
    const { scope_: n } = r;
    return B(n, t), H(void 0, n);
  }
  /**
   * Pass true to automatically freeze all copies created by Immer.
   *
   * By default, auto-freezing is enabled.
   */
  setAutoFreeze(e) {
    this.autoFreeze_ = e;
  }
  /**
   * Pass true to enable strict shallow copy.
   *
   * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
   */
  setUseStrictShallowCopy(e) {
    this.useStrictShallowCopy_ = e;
  }
  applyPatches(e, t) {
    let r;
    for (r = t.length - 1; r >= 0; r--) {
      const o = t[r];
      if (o.path.length === 0 && o.op === "replace") {
        e = o.value;
        break;
      }
    }
    r > -1 && (t = t.slice(r + 1));
    const n = g("Patches").applyPatches_;
    return P(e) ? n(e, t) : this.produce(
      e,
      (o) => n(o, t)
    );
  }
};
function v(e, t) {
  const r = M(e) ? g("MapSet").proxyMap_(e, t) : N(e) ? g("MapSet").proxySet_(e, t) : se(e, t);
  return (t ? t.scope_ : D()).drafts_.push(r), r;
}
function ae(e) {
  return P(e) || d(10, e), Z(e);
}
function Z(e) {
  if (!p(e) || A(e))
    return e;
  const t = e[u];
  let r;
  if (t) {
    if (!t.modified_)
      return t.base_;
    t.finalized_ = !0, r = k(e, t.scope_.immer_.useStrictShallowCopy_);
  } else
    r = k(e, !0);
  return w(r, (n, o) => {
    Q(r, n, Z(o));
  }), t && (t.finalized_ = !1), r;
}
function ue() {
  class e extends Map {
    constructor(i, s) {
      super(), this[u] = {
        type_: 2,
        parent_: s,
        scope_: s ? s.scope_ : D(),
        modified_: !1,
        finalized_: !1,
        copy_: void 0,
        assigned_: void 0,
        base_: i,
        draft_: this,
        isManual_: !1,
        revoked_: !1
      };
    }
    get size() {
      return _(this[u]).size;
    }
    has(i) {
      return _(this[u]).has(i);
    }
    set(i, s) {
      const l = this[u];
      return f(l), (!_(l).has(i) || _(l).get(i) !== s) && (r(l), h(l), l.assigned_.set(i, !0), l.copy_.set(i, s), l.assigned_.set(i, !0)), this;
    }
    delete(i) {
      if (!this.has(i))
        return !1;
      const s = this[u];
      return f(s), r(s), h(s), s.base_.has(i) ? s.assigned_.set(i, !1) : s.assigned_.delete(i), s.copy_.delete(i), !0;
    }
    clear() {
      const i = this[u];
      f(i), _(i).size && (r(i), h(i), i.assigned_ = /* @__PURE__ */ new Map(), w(i.base_, (s) => {
        i.assigned_.set(s, !1);
      }), i.copy_.clear());
    }
    forEach(i, s) {
      const l = this[u];
      _(l).forEach((m, W, fe) => {
        i.call(s, this.get(W), W, this);
      });
    }
    get(i) {
      const s = this[u];
      f(s);
      const l = _(s).get(i);
      if (s.finalized_ || !p(l) || l !== s.base_.get(i))
        return l;
      const m = v(l, s);
      return r(s), s.copy_.set(i, m), m;
    }
    keys() {
      return _(this[u]).keys();
    }
    values() {
      const i = this.keys();
      return {
        [Symbol.iterator]: () => this.values(),
        next: () => {
          const s = i.next();
          return s.done ? s : {
            done: !1,
            value: this.get(s.value)
          };
        }
      };
    }
    entries() {
      const i = this.keys();
      return {
        [Symbol.iterator]: () => this.entries(),
        next: () => {
          const s = i.next();
          if (s.done)
            return s;
          const l = this.get(s.value);
          return {
            done: !1,
            value: [s.value, l]
          };
        }
      };
    }
    [Symbol.iterator]() {
      return this.entries();
    }
  }
  function t(c, i) {
    return new e(c, i);
  }
  function r(c) {
    c.copy_ || (c.assigned_ = /* @__PURE__ */ new Map(), c.copy_ = new Map(c.base_));
  }
  class n extends Set {
    constructor(i, s) {
      super(), this[u] = {
        type_: 3,
        parent_: s,
        scope_: s ? s.scope_ : D(),
        modified_: !1,
        finalized_: !1,
        copy_: void 0,
        base_: i,
        draft_: this,
        drafts_: /* @__PURE__ */ new Map(),
        revoked_: !1,
        isManual_: !1
      };
    }
    get size() {
      return _(this[u]).size;
    }
    has(i) {
      const s = this[u];
      return f(s), s.copy_ ? !!(s.copy_.has(i) || s.drafts_.has(i) && s.copy_.has(s.drafts_.get(i))) : s.base_.has(i);
    }
    add(i) {
      const s = this[u];
      return f(s), this.has(i) || (a(s), h(s), s.copy_.add(i)), this;
    }
    delete(i) {
      if (!this.has(i))
        return !1;
      const s = this[u];
      return f(s), a(s), h(s), s.copy_.delete(i) || (s.drafts_.has(i) ? s.copy_.delete(s.drafts_.get(i)) : (
        /* istanbul ignore next */
        !1
      ));
    }
    clear() {
      const i = this[u];
      f(i), _(i).size && (a(i), h(i), i.copy_.clear());
    }
    values() {
      const i = this[u];
      return f(i), a(i), i.copy_.values();
    }
    entries() {
      const i = this[u];
      return f(i), a(i), i.copy_.entries();
    }
    keys() {
      return this.values();
    }
    [Symbol.iterator]() {
      return this.values();
    }
    forEach(i, s) {
      const l = this.values();
      let m = l.next();
      for (; !m.done; )
        i.call(s, m.value, m.value, this), m = l.next();
    }
  }
  function o(c, i) {
    return new n(c, i);
  }
  function a(c) {
    c.copy_ || (c.copy_ = /* @__PURE__ */ new Set(), c.base_.forEach((i) => {
      if (p(i)) {
        const s = v(i, c);
        c.drafts_.set(i, s), c.copy_.add(s);
      } else
        c.copy_.add(i);
    }));
  }
  function f(c) {
    c.revoked_ && d(3, JSON.stringify(_(c)));
  }
  re("MapSet", { proxyMap_: t, proxySet_: o });
}
var y = new ce(), le = y.produce;
y.produceWithPatches.bind(
  y
);
y.setAutoFreeze.bind(y);
y.setUseStrictShallowCopy.bind(y);
y.applyPatches.bind(y);
y.createDraft.bind(y);
y.finishDraft.bind(y);
export {
  ce as Immer,
  ae as current,
  ue as enableMapSet,
  $ as freeze,
  K as immerable,
  P as isDraft,
  p as isDraftable,
  X as nothing,
  le as produce
};
//# sourceMappingURL=immer.js.map
