
$(() => {
    class Chronology
    {
        #min = null;
        #max = null;

        #onChronologyUpdated() {
            console.log("Chronology update with ", this.#min, this.#max);
            window.ReloadFilters(MediaStorage.Instance);
        }

        rebuildRange(_minTs, _maxTs) {
            let updated = false;

            if (!this.#min || this.#min.getTime() !== _minTs) {
                this.#min = new Date(_minTs);
                updated = true;
            }
            if (!this.#max || this.#max.getTime() !== _maxTs) {
                this.#max = new Date(_maxTs);
                updated = true;
            }
            if (updated)
                this.#onChronologyUpdated();
        }

        getRange() {
            return {
                min: new Date(this.#min),
                max: new Date(this.#max)
            };
        }

        isInitialized() {
            return this.#min && this.#max;
        }

        reset() {
            this.#min = this.#max = null;
        }
    }

    window.chronology = new Chronology();
});
