"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ste_events_1 = require("ste-events");
const EslintDefaultConfig = [
    "import minecraftLinting from 'eslint-plugin-minecraft-linting';",
    "import tsParser from '@typescript-eslint/parser';",
    "import ts from '@typescript-eslint/eslint-plugin';",
    "export default [",
    "  {",
    "    files: ['scripts/**/*.ts'],",
    "    languageOptions: {",
    "      parser: tsParser,",
    "      ecmaVersion: 'latest',",
    "    },",
    "    plugins: {",
    "      ts,",
    "      'minecraft-linting': minecraftLinting,",
    "    },",
    "    rules: {",
    "      'minecraft-linting/avoid-unnecessary-command': 'error',",
    "    },",
    "  },",
    "];",
];
class EslintConfig {
    _file;
    _id;
    _isLoaded = false;
    _onLoaded = new ste_events_1.EventDispatcher();
    project = undefined;
    get isLoaded() {
        return this._isLoaded;
    }
    get file() {
        return this._file;
    }
    set file(newFile) {
        this._file = newFile;
    }
    get onLoaded() {
        return this._onLoaded.asEvent();
    }
    get id() {
        return this._id;
    }
    set id(newId) {
        this._id = newId;
    }
    static async ensureOnFile(file, loadHandler) {
        let justf;
        if (file.manager === undefined) {
            justf = new EslintConfig();
            justf.file = file;
            file.manager = justf;
        }
        if (file.manager !== undefined && file.manager instanceof EslintConfig) {
            justf = file.manager;
            if (!justf.isLoaded && loadHandler) {
                justf.onLoaded.subscribe(loadHandler);
            }
            await justf.load();
            return justf;
        }
        return justf;
    }
    async ensureDefault() {
        if (this._file === undefined) {
            return;
        }
        await this.load();
        this._file.setContent(EslintConfig.getDefaultContent());
    }
    async ensureMin() {
        if (this._file === undefined) {
            return;
        }
        await this.load();
        if (!this._file.content || typeof this._file.content !== "string") {
            this._file.setContent(EslintConfig.getDefaultContent());
        }
    }
    async persist() { }
    async save() {
        if (this._file === undefined) {
            return;
        }
        await this._file.saveContent(false);
    }
    async load() {
        if (this._file === undefined || this._isLoaded) {
            return;
        }
        await this._file.loadContent(true);
        if (this._file.content === null || this._file.content instanceof Uint8Array) {
            return;
        }
        this._isLoaded = true;
    }
    static getDefaultContent() {
        return EslintDefaultConfig.join("\n").replace(/'/gi, '"');
    }
}
exports.default = EslintConfig;

//# sourceMappingURL=../maps/devproject/EslintConfig.js.map
