"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const IProjectItemData_2 = require("../app/IProjectItemData");
const Utilities_1 = require("../core/Utilities");
const ProjectItemUtilities_1 = require("../app/ProjectItemUtilities");
const TopicTestIdBase = 100;
class LineSizeInfoGenerator {
    id = "LINESIZE";
    title = "File Line/Size Information";
    canAlwaysProcess = true;
    getTopicData(topicId) {
        if (topicId >= TopicTestIdBase) {
            return {
                title: ProjectItemUtilities_1.default.getDescriptionForType(topicId - TopicTestIdBase),
            };
        }
        return {
            title: topicId.toString(),
        };
    }
    summarize(info, infoSet) { }
    async generate(project, contentIndex) {
        const items = [];
        const itemsByType = {};
        const lineSizeCounts = [];
        for (let i = 0; i < IProjectItemData_2.MaxItemTypes; i++) {
            lineSizeCounts[i] = 0;
        }
        const itemsCopy = project.getItemsCopy();
        for (let i = 0; i < itemsCopy.length; i++) {
            const pi = itemsCopy[i];
            let projInfoItem = undefined;
            if (itemsByType[pi.itemType] !== undefined) {
                projInfoItem = itemsByType[pi.itemType];
            }
            else {
                const name = ProjectItemUtilities_1.default.getDescriptionForType(pi.itemType) +
                    " file " +
                    (ProjectItemUtilities_1.default.isBinaryType(pi.itemType) ? "size" : "lines");
                projInfoItem = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, TopicTestIdBase + pi.itemType, name, pi);
                itemsByType[pi.itemType] = projInfoItem;
                items.push(projInfoItem);
            }
            if (pi.storageType === IProjectItemData_1.ProjectItemStorageType.singleFile) {
                let file = await pi.ensureFileStorage();
                if (file) {
                    await file.loadContent();
                    projInfoItem.spectrumIntFeature("Size", file.coreContentLength);
                    const content = file.content;
                    if (content && typeof content === "string") {
                        projInfoItem.spectrumIntFeature("Lines", Utilities_1.default.countSignificantLines(content));
                    }
                }
            }
        }
        return items;
    }
}
exports.default = LineSizeInfoGenerator;

//# sourceMappingURL=../maps/info/LineSizeInfoGenerator.js.map
