var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
import { defaultTemplate } from "./DefaultTemplate";
export var repeat = function (times) { return function (callback) {
    return Array(times)
        .fill(0)
        .map(function (_, index) { return callback(index); });
}; };
export var noop = function () { return void 0; };
// Currently using https://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t
export var inIframe = function () {
    try {
        return window.self !== window.top;
    }
    catch (e) {
        return true;
    }
};
var isV2Document = function (document) {
    return !!document.$template;
};
// TODO this function is weird, returns current template + templates for attachments
export function documentTemplates(document, templateRegistry, attachmentToComponent) {
    if (!document || !isV2Document(document))
        return [];
    // Find the template in the template registry or use a default template
    var templateName = typeof document.$template === "object" ? document.$template.name : "";
    var selectedTemplate = (templateName && templateRegistry[templateName]) || [
        defaultTemplate
    ];
    // Add type property to differentiate between custom template tabs VS attachments tab
    var templatesFromCustom = selectedTemplate.map(function (template) {
        return __assign(__assign({}, template), { type: "custom-template" });
    });
    // Create additional tabs from attachments
    var templatesFromAttachments = (document.attachments || []).map(function (attachment, index) { return ({
        id: "attachment-" + index,
        label: attachment.filename || "Unknown filename",
        type: attachment.type || "Unknown filetype",
        template: attachmentToComponent(attachment, document)
    }); });
    return __spreadArrays(templatesFromCustom, templatesFromAttachments);
}
//# sourceMappingURL=utils.js.map