// #region Imports
import { Signal } from './Signal';
// #endregion
/**
 * Trackable signal class to monitor changes to its value with change tracking.
 * @public
 */
export class TrackableSignal extends Signal {
    // #region Fields
    _isChanged;
    _changes;
    // #endregion
    // #region Constructor
    /**
     * Initializes a new instance of TrackableSignal.
     *
     * @param initialValue The initial value of the signal.
     */
    constructor(initialValue) {
        super(initialValue);
        this._isChanged = false;
        this._changes = [initialValue];
    }
    // #endregion
    // #region Properties
    /**
     * Indicates if the signal has been modified since the last change acceptance.
     */
    get isChanged() {
        return this._isChanged;
    }
    // #endregion
    // #region Public Methods
    /**
     * Factory method for creating a new TrackableSignal instance.
     *
     * @param value Initial value of the trackable signal.
     */
    static from(value) {
        return new TrackableSignal(value);
    }
    /**
     * Clears all tracked changes, resets the isChanged flag, and keeps only the current value in the changes list.
     */
    acceptChanges() {
        this._isChanged = false;
        this._changes.length = 0;
        this._changes.push(this.get());
    }
    /**
     * Retrieves the list of all previous values that the signal has held.
     */
    getChanges() {
        return this._changes;
    }
    /**
     * Overrides the set method to track changes and add each new value to the changes list.
     *
     * @param next - The new value to set.
     */
    set(next) {
        if (this.get() !== next) {
            // Cache the new value in the changes list
            this._changes.push(next);
            this._isChanged = true;
            super.set(next);
        }
    }
}
//# sourceMappingURL=TrackableSignal.js.map