/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./store.js"),t=require("./scheduler.js");class s{constructor(e){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const e=this.options.deps.length,t=new Array(e),s=new Array(e);for(let i=0;i<e;i++){const e=this.options.deps[i];t[i]=e.prevState,s[i]=e.state}return this.lastSeenDepValues=s,{prevDepVals:t,currDepVals:s,prevVal:this.prevState??void 0}},this.recompute=()=>{var e,t;this.prevState=this.state;const s=this.getDepVals();this.state=this.options.fn(s),null==(t=(e=this.options).onUpdate)||t.call(e)},this.checkIfRecalculationNeededDeeply=()=>{for(const r of this.options.deps)r instanceof s&&r.checkIfRecalculationNeededDeeply();let e=!1;const t=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let s=0;s<i.length;s++)if(i[s]!==t[s]){e=!0;break}e&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const e of this._subscriptions)e()}),this.subscribe=e=>{var t,s;this.listeners.add(e);const i=null==(s=(t=this.options).onSubscribe)?void 0:s.call(t,e,this);return()=>{this.listeners.delete(e),null==i||i()}},this.options=e,this.state=e.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(i=this.options.deps){for(const r of i)if(r instanceof s)r.registerOnGraph(),this.registerOnGraph(r.options.deps);else if(r instanceof e.Store){let e=t.__storeToDerived.get(r);e||(e=new Set,t.__storeToDerived.set(r,e)),e.add(this);let s=t.__derivedToStore.get(this);s||(s=new Set,t.__derivedToStore.set(this,s)),s.add(r)}}unregisterFromGraph(i=this.options.deps){for(const r of i)if(r instanceof s)this.unregisterFromGraph(r.options.deps);else if(r instanceof e.Store){const e=t.__storeToDerived.get(r);e&&e.delete(this);const s=t.__derivedToStore.get(this);s&&s.delete(r)}}}exports.Derived=s;