import { DOM } from '@ni/fast-element';
import { UpdateTracker } from '../../utilities/models/update-tracker';
const trackedItems = [
    'highlightedTags',
    'canvasWidth',
    'canvasHeight',
    'originLocation',
    'gridMinX',
    'gridMaxX',
    'gridMinY',
    'gridMaxY',
    'dies',
    'maxCharacters',
    'colorScale',
    'colorScaleMode',
    'dieLabelsHidden',
    'dieLabelsSuffix',
    'transform',
    'hoverDie'
];
/**
 * Helper class to track what updates are needed to the wafer based on configuration
 * changes.
 */
export class WaferMapUpdateTracker extends UpdateTracker {
    constructor(wafermap) {
        super(trackedItems);
        this.wafermap = wafermap;
        this.updateQueued = false;
    }
    get requiresEventsUpdate() {
        return (this.isTracked('canvasWidth')
            || this.isTracked('canvasHeight')
            || this.isTracked('originLocation')
            || this.isTracked('gridMinX')
            || this.isTracked('gridMaxX')
            || this.isTracked('gridMinY')
            || this.isTracked('gridMaxY')
            || this.isTracked('dies')
            || this.isTracked('maxCharacters')
            || this.isTracked('highlightedTags')
            || this.isTracked('colorScale')
            || this.isTracked('colorScaleMode')
            || this.isTracked('dieLabelsHidden')
            || this.isTracked('dieLabelsSuffix')
            || this.isTracked('transform'));
    }
    get requiresWorkerWaferSetup() {
        return (this.isTracked('canvasWidth')
            || this.isTracked('canvasHeight')
            || this.isTracked('originLocation')
            || this.isTracked('gridMinX')
            || this.isTracked('gridMaxX')
            || this.isTracked('gridMinY')
            || this.isTracked('gridMaxY')
            || this.isTracked('dies')
            || this.isTracked('maxCharacters')
            || this.isTracked('highlightedTags')
            || this.isTracked('colorScale')
            || this.isTracked('colorScaleMode')
            || this.isTracked('dieLabelsHidden')
            || this.isTracked('dieLabelsSuffix'));
    }
    get requiresContainerDimensionsUpdate() {
        return this.isTracked('canvasWidth') || this.isTracked('canvasHeight');
    }
    get requiresComponentResizeUpdate() {
        return this.isTracked('canvasWidth') || this.isTracked('canvasHeight');
    }
    get requiresScalesUpdate() {
        return (this.isTracked('originLocation')
            || this.isTracked('gridMinX')
            || this.isTracked('gridMaxX')
            || this.isTracked('gridMinY')
            || this.isTracked('gridMaxY')
            || this.isTracked('dies'));
    }
    get requiresInputDataUpdate() {
        return (this.isTracked('originLocation')
            || this.isTracked('gridMinX')
            || this.isTracked('gridMaxX')
            || this.isTracked('gridMinY')
            || this.isTracked('gridMaxY')
            || this.isTracked('dies'));
    }
    get requiresLabelsFontSizeUpdate() {
        return this.isTracked('maxCharacters');
    }
    get requiresDiesRenderInfoUpdate() {
        return (this.isTracked('highlightedTags')
            || this.isTracked('colorScale')
            || this.isTracked('colorScaleMode')
            || this.isTracked('dieLabelsHidden')
            || this.isTracked('dieLabelsSuffix'));
    }
    get requiresColorAndTextUpdate() {
        return (this.isTracked('maxCharacters')
            || this.isTracked('highlightedTags')
            || this.isTracked('colorScale')
            || this.isTracked('colorScaleMode')
            || this.isTracked('dieLabelsHidden')
            || this.isTracked('dieLabelsSuffix'));
    }
    get requiresDrawnWaferUpdate() {
        return this.isTracked('transform');
    }
    get requiresRenderHoverUpdate() {
        return this.isTracked('hoverDie');
    }
    /**
     * Queues an update using the DOM and until the update is run no other updates are queued.
     * After the update is finished, all the tracked items are reset.
     */
    queueUpdate() {
        if (!this.wafermap.$fastController.isConnected || this.updateQueued) {
            return;
        }
        this.updateQueued = true;
        if (this.wafermap.currentTask === undefined) {
            DOM.queueUpdate(() => {
                this.wafermap.update();
                this.untrackAll();
                this.updateQueued = false;
            });
        }
        else {
            void (async () => {
                await this.wafermap.currentTask;
                DOM.queueUpdate(() => {
                    this.wafermap.update();
                    this.untrackAll();
                    this.updateQueued = false;
                    this.wafermap.currentTask = undefined;
                });
            })();
        }
    }
}
//# sourceMappingURL=wafer-map-update-tracker.js.map