"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createUploadMiddleware = exports.prioritizeHTMLFile = void 0;
exports.minutesToISO8601Duration = minutesToISO8601Duration;
const prioritizeHTMLFile = (entryFiles) => {
    let files = [];
    // Find the html file and put it as latest in the files array
    // in order to keep the html file opened in vscode plugin
    const index = entryFiles.findIndex(file => {
        return /.*\.html$/.test(file);
    });
    if (index !== -1) {
        for (const [i, entryFile] of entryFiles.entries()) {
            if (i !== index) {
                files.push(entryFile);
            }
        }
        files.push(entryFiles[index]);
    }
    else {
        files = entryFiles;
    }
    return files;
};
exports.prioritizeHTMLFile = prioritizeHTMLFile;
function minutesToISO8601Duration(minutes) {
    if (minutes <= 0)
        return "PT0M";
    const weeks = Math.floor(minutes / (60 * 24 * 7));
    minutes %= 60 * 24 * 7;
    const days = Math.floor(minutes / (60 * 24));
    minutes %= 60 * 24;
    const hours = Math.floor(minutes / 60);
    const mins = minutes % 60;
    let duration = "P";
    if (weeks)
        duration += `${weeks}W`;
    if (days)
        duration += `${days}D`;
    if (hours || mins)
        duration += "T";
    if (hours)
        duration += `${hours}H`;
    if (mins)
        duration += `${mins}M`;
    return duration;
}
const createUploadMiddleware = () => {
    // eslint-disable-next-line
    const multer = require("multer");
    return multer({ limits: { fileSize: 25 * 1024 * 1024 } });
};
exports.createUploadMiddleware = createUploadMiddleware;
