"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const Log_1 = require("../core/Log");
const ste_events_1 = require("ste-events");
class TypeScriptDefinition {
    _data;
    _file;
    _isLoaded = false;
    _onLoaded = new ste_events_1.EventDispatcher();
    id;
    get data() {
        if (!this._file || !this._file.content || typeof this._file.content != "string") {
            return undefined;
        }
        return this._file.content;
    }
    get isLoaded() {
        return this._isLoaded;
    }
    get file() {
        return this._file;
    }
    get onLoaded() {
        return this._onLoaded.asEvent();
    }
    set file(newFile) {
        this._file = newFile;
    }
    static async ensureOnFile(file, loadHandler) {
        let tsd;
        if (file.manager === undefined) {
            tsd = new TypeScriptDefinition();
            tsd.file = file;
            file.manager = tsd;
        }
        if (file.manager !== undefined && file.manager instanceof TypeScriptDefinition) {
            tsd = file.manager;
            if (!tsd.isLoaded) {
                if (loadHandler) {
                    tsd.onLoaded.subscribe(loadHandler);
                }
                await tsd.load();
            }
        }
        return tsd;
    }
    persist() { }
    async load() {
        if (this._isLoaded) {
            return;
        }
        if (this._file === undefined) {
            Log_1.default.unexpectedUndefined("TSCDF");
            return;
        }
        if (!this._file.isContentLoaded) {
            await this._file.loadContent();
        }
        if (!this._file.content || this._file.content instanceof Uint8Array) {
            return;
        }
        this._isLoaded = true;
        this._onLoaded.dispatch(this, this);
    }
}
exports.default = TypeScriptDefinition;

//# sourceMappingURL=../maps/minecraft/TypeScriptDefinition.js.map
