"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HotAsset = void 0;
/**
 * An asset to load.
 */
class HotAsset {
    constructor(type, name = "") {
        this.type = type;
        this.name = name;
        this.path = "";
        this.content = "";
    }
    load() {
    }
    /**
     * Load the asset.
     */
    output() {
        if ((this.path == null) && (this.content == null))
            throw new Error(`HotAsset ${this.name} of type ${this.type} does not have a path or content set!`);
        let output = "";
        if (this.path != null) {
            if (this.path !== "") {
                if (this.type === "js")
                    output = `<script type = "text/javascript" src = "${this.path}"></script>`;
                if (this.type === "css")
                    output = `<link href = "${this.path}" rel = "stylesheet" />`;
                if ((this.type === "html") ||
                    (this.type === "component")) {
                    if (this.name === "")
                        throw new Error(`Loading an HTML or component asset requires a name to be set!`);
                    let fileUrl = `"${this.path}"`;
                    output = { name: this.name, url: this.path };
                }
            }
        }
        if (this.content != null) {
            if (this.content !== "") {
                if (this.type === "js")
                    throw new Error(`Loading JS assets using content is not supported yet!`);
                if (this.type === "css")
                    throw new Error(`Loading CSS assets using content is not supported yet!`);
                if (this.type === "html") {
                    if (this.name === "")
                        throw new Error(`Loading an HTML asset requires a name to be set!`);
                    let escapedContent = JSON.stringify(this.content);
                    let fileUrl = this.path;
                    let fileContent = "";
                    // Find any script tags and interrupt them so the HTML parsers 
                    // don't get confused.
                    escapedContent = escapedContent.replace(new RegExp("\\<script", "gmi"), "<scr\" + \"ipt");
                    escapedContent = escapedContent.replace(new RegExp("\\<\\/script", "gmi"), "</scr\" + \"ipt");
                    fileContent = escapedContent;
                    output = { name: this.name, url: fileUrl, content: escapedContent };
                }
            }
        }
        return (output);
    }
}
exports.HotAsset = HotAsset;
//# sourceMappingURL=HotAsset.js.map