import { MutableObservableOption, Terminator } from "@opendaw/lib-std";
export class TimelineFocus {
    #terminator = new Terminator();
    #trackSubscription = this.#terminator.own(new Terminator());
    #regionSubscription = this.#terminator.own(new Terminator());
    #track;
    #region;
    constructor() {
        this.#track = this.#terminator.own(new MutableObservableOption());
        this.#region = this.#terminator.own(new MutableObservableOption());
    }
    get track() { return this.#track; }
    get region() { return this.#region; }
    focusTrack(track) {
        this.#trackSubscription.terminate();
        this.#trackSubscription.own(track.box.subscribeDeletion(() => {
            console.debug("TimelineFocus: track deleted");
            this.#trackSubscription.terminate();
            this.#track.clear();
        }));
        this.#track.wrap(track);
        this.clearRegionFocus();
    }
    focusRegion(region) {
        region.trackBoxAdapter.ifSome(track => this.focusTrack(track));
        this.#regionSubscription.terminate();
        this.#regionSubscription.own(region.box.subscribeDeletion(() => {
            console.debug("TimelineFocus: region deleted");
            this.#regionSubscription.terminate();
            this.#region.clear();
        }));
        this.#region.wrap(region);
    }
    clearRegionFocus() {
        this.#regionSubscription.terminate();
        this.#region.clear();
    }
    clear() {
        this.#trackSubscription.terminate();
        this.#regionSubscription.terminate();
        this.#track.clear();
        this.#region.clear();
    }
    terminate() { this.#terminator.terminate(); }
}
