"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemListTableTop = exports.ItemListTop = exports.EntityDamageSourceListTop = exports.EntityListTableTop = exports.EntityListTop = exports.BlockListTableTop = exports.BlockListTop = void 0;
const Log_1 = require("../core/Log");
const Utilities_1 = require("../core/Utilities");
const Database_1 = require("../minecraft/Database");
const LegacyDocumentationDefinition_1 = require("../minecraft/docs/LegacyDocumentationDefinition");
const FormMarkdownDocumentationGenerator_1 = require("./FormMarkdownDocumentationGenerator");
const MaxLinesPerTable = 200;
exports.BlockListTop = `# Default Minecraft Block Listings

Listed below are the available blocks for use in Minecraft: Bedrock Edition.

> [!NOTE]
> To learn more about how blocks function in Minecraft: Bedrock Edition, please take a look at the [Block JSON Documentation](../BlockReference/index.yml)

## List of Blocks

`;
exports.BlockListTableTop = `| Name | States |
|:-----------|:-----------|`;
exports.EntityListTop = `# Default Minecraft Entity Listings

An overview of the Entities that can be used in Addons for Minecraft: Bedrock Edition.

> [!NOTE]
> To learn more about how Entities function in Minecraft: Bedrock Edition, please take a look at the [Entity JSON Documentation](../EntityReference/index.yml)

## Entities List

Listed below are the available Entities for use in Minecraft: Bedrock Edition and their respective ID value.

`;
exports.EntityListTableTop = `| Identifier| Full ID| Short ID |
|:-----------|:-----------|:-----------|`;
exports.EntityDamageSourceListTop = `## Entity Damage Source

Listed below are the available Damage Sources that can be used when working with Entity components and filters.

| Damage Source|
|:-----------|`;
exports.ItemListTop = `# Default Minecraft Item Listings

Listed below are the available Items for use in Minecraft: Bedrock Edition.

> [!NOTE]
> To learn more about how Items function in Minecraft: Bedrock Edition, please take a look at the [Item JSON Documentation](../ItemReference/index.yml)

## List of Items

`;
exports.ItemListTableTop = `| Name | ID | 
|:-----------|:-----------|`;
class TableMarkdownDocumentationGenerator {
    async generateMarkdown(outputFolder) {
        const addonDocs = await Database_1.default.getAddonsDocs();
        const blocksMetadata = await Database_1.default.getBlocksMetadata();
        if (!addonDocs || !blocksMetadata) {
            Log_1.default.unexpectedUndefined();
            return;
        }
        await this.generateBlockListTable(blocksMetadata, outputFolder);
        await this.generateEntityListTable(outputFolder);
        await this.generateEntityDamageSourcesListTable(outputFolder);
        await this.generateItemListTable(outputFolder);
    }
    async generateEntityListTable(outputFolder) {
        const entitiesNode = await LegacyDocumentationDefinition_1.default.loadNode("addons", "/Entities/", true);
        if (!entitiesNode) {
            return;
        }
        const addonEntityLines = [];
        addonEntityLines.push(Utilities_1.default.stringFormat(FormMarkdownDocumentationGenerator_1.MarkdownTop, "Default Minecraft Entity Listings", "A reference document detailing the entities and damage sources used in addons for Minecraft: Bedrock Edition"));
        addonEntityLines.push(exports.EntityListTop);
        addonEntityLines.push(exports.EntityListTableTop);
        const previewFolder = await Database_1.default.getPreviewVanillaFolder();
        if (!previewFolder) {
            return;
        }
        const entitiesFolder = await previewFolder.getFolderFromRelativePath("/behavior_pack/entities/");
        if (!entitiesFolder) {
            return;
        }
        await entitiesFolder.load();
        let i = 0;
        for (const node of entitiesNode.nodes) {
            if (node.name && node.description && node.default) {
                if (i % MaxLinesPerTable === MaxLinesPerTable - 1) {
                    addonEntityLines.push("");
                    addonEntityLines.push(exports.EntityListTableTop);
                }
                let line = "| ";
                if (entitiesFolder.files[node.name + ".json"]) {
                    line +=
                        "[" +
                            node.name +
                            "](https://github.com/Mojang/bedrock-samples/blob/preview/behavior_pack/entities/" +
                            node.name +
                            ".json)";
                }
                else {
                    line += node.name;
                }
                line += " | " + node.default + " | " + node.description + " |";
                addonEntityLines.push(line);
                i++;
            }
        }
        const file = await outputFolder.ensureFileFromRelativePath("/VanillaListingsReference/Entities.md");
        file.setContent(addonEntityLines.join("\r\n"));
        await file.saveContent();
    }
    async generateEntityDamageSourcesListTable(outputFolder) {
        const entitiesNode = await LegacyDocumentationDefinition_1.default.loadNode("addons", "/Entity Damage Source/", true);
        if (!entitiesNode) {
            return;
        }
        const addonEntityLines = [];
        addonEntityLines.push(Utilities_1.default.stringFormat(FormMarkdownDocumentationGenerator_1.MarkdownTop, "Default Minecraft Entity Damage Source Listings", "A reference document detailing the damage sources used in addons for Minecraft: Bedrock Edition"));
        addonEntityLines.push(exports.EntityDamageSourceListTop);
        for (const node of entitiesNode.nodes) {
            if (node.name) {
                let line = "| ";
                line += node.name + " |";
                addonEntityLines.push(line);
            }
        }
        const file = await outputFolder.ensureFileFromRelativePath("/VanillaListingsReference/AddonEntityDamageSources.md");
        file.setContent(addonEntityLines.join("\r\n"));
        await file.saveContent();
    }
    async generateItemListTable(outputFolder) {
        const itemsNode = await LegacyDocumentationDefinition_1.default.loadNode("addons", "/Items/", true);
        if (!itemsNode) {
            return;
        }
        const addonItemLines = [];
        addonItemLines.push(Utilities_1.default.stringFormat(FormMarkdownDocumentationGenerator_1.MarkdownTop, "Default Minecraft Item Listings", "A reference document detailing the items and damage sources used in addons for Minecraft: Bedrock Edition"));
        addonItemLines.push(exports.ItemListTop);
        addonItemLines.push(exports.ItemListTableTop);
        const previewFolder = await Database_1.default.getPreviewVanillaFolder();
        if (!previewFolder) {
            return;
        }
        const itemsFolder = await previewFolder.getFolderFromRelativePath("/behavior_pack/items/");
        if (!itemsFolder) {
            return;
        }
        await itemsFolder.load();
        let i = 0;
        for (const node of itemsNode.nodes) {
            if (node.name && node.type) {
                if (i % MaxLinesPerTable === MaxLinesPerTable - 1) {
                    addonItemLines.push("");
                    addonItemLines.push(exports.ItemListTableTop);
                }
                let line = "| ";
                if (itemsFolder.files[node.name + ".json"]) {
                    line +=
                        "[" +
                            node.name +
                            "](https://github.com/Mojang/bedrock-samples/blob/preview/behavior_pack/items/" +
                            node.name +
                            ".json)";
                }
                else {
                    line += node.name;
                }
                line += " | " + node.type + " |";
                addonItemLines.push(line);
                i++;
            }
        }
        const file = await outputFolder.ensureFileFromRelativePath("/VanillaListingsReference/Items.md");
        file.setContent(addonItemLines.join("\r\n"));
        await file.saveContent();
    }
    async generateBlockListTable(blocksMetadata, outputFolder) {
        const addonBlockLines = [];
        addonBlockLines.push(Utilities_1.default.stringFormat(FormMarkdownDocumentationGenerator_1.MarkdownTop, "Default Minecraft Block Listings", "A reference document listing the available blocks for use in Minecraft: Bedrock Edition"));
        addonBlockLines.push(exports.BlockListTop);
        addonBlockLines.push(exports.BlockListTableTop);
        let i = 0;
        for (const dataItem of blocksMetadata.data_items) {
            if (i % MaxLinesPerTable === MaxLinesPerTable - 1) {
                addonBlockLines.push("");
                addonBlockLines.push(exports.BlockListTableTop);
            }
            let line = "| " + dataItem.name + " | ";
            if (dataItem.properties.length > 0) {
                let propIndex = 0;
                for (const prop of dataItem.properties) {
                    if (propIndex > 0) {
                        line += ", ";
                    }
                    line += prop.name;
                    propIndex++;
                }
            }
            line += " |";
            addonBlockLines.push(line);
            i++;
        }
        const file = await outputFolder.ensureFileFromRelativePath("/VanillaListingsReference/Blocks.md");
        file.setContent(addonBlockLines.join("\r\n"));
        await file.saveContent();
    }
}
exports.default = TableMarkdownDocumentationGenerator;

//# sourceMappingURL=../maps/docgen/TableMarkdownDocumentationGenerator.js.map
