export const options = {
    menus: {},
    submenu_names: {},
    data: null,
    hostname: "netdata_server",
    version: "unknown",
    release_channel: "unknown",
    hosts: [],
    duration: 0,
    update_every: 1,
    chartsPerRow: 0,
    // chartsMinWidth: 1450,
    chartsHeight: 180,
};
// netdata standard information
export const netdataDashboard = {
    sparklines_registry: {},
    os: "unknown",
    menu: {},
    submenu: {},
    context: {},
    // generate a sparkline
    // used in the documentation
    sparkline(prefix, chart, dimension, units = "", suffix) {
        if (options.data === null || typeof options.data.charts === "undefined") {
            return "";
        }
        if (typeof options.data.charts[chart] === "undefined") {
            return "";
        }
        if (typeof options.data.charts[chart].dimensions === "undefined") {
            return "";
        }
        if (typeof options.data.charts[chart].dimensions[dimension] === "undefined") {
            return "";
        }
        let key = `${chart}.${dimension}`;
        if (typeof this.sparklines_registry[key] === "undefined") {
            this.sparklines_registry[key] = { count: 1 };
        }
        else {
            this.sparklines_registry[key].count += 1;
        }
        key = `${key}.${this.sparklines_registry[key].count}`;
        return `${prefix}<div class="netdata-container" data-netdata="${chart}" data-after="-120"
      data-width="25%" data-height="15px" data-chart-library="dygraph"
      data-dygraph-theme="sparkline" data-dimensions="${dimension}"
      data-show-value-of-${dimension}-at="${key}"></div>
       (<span id="${key}" style="display: inline-block; min-width: 50px; text-align: right;">
       X</span>${units})${suffix}`;
    },
    gaugeChart(title, width, dimensions = "", colors = "") {
        return `${"<div class=\"netdata-container\" data-netdata=\"CHART_UNIQUE_ID\""
            + " data-dimensions=\""}${dimensions}"`
            + " data-chart-library=\"gauge\""
            + " data-gauge-adjust=\"width\""
            + ` data-title="${title}"`
            + ` data-width="${width}"`
            + " data-before=\"0\""
            + " data-after=\"-CHART_DURATION\""
            + " data-points=\"CHART_DURATION\""
            + ` data-colors="${colors}"`
            + " role=\"application\"></div>";
    },
    anyAttribute(obj, attr, key, def) {
        if (typeof (obj[key]) !== "undefined") {
            const x = obj[key][attr];
            if (typeof (x) === "undefined") {
                return def;
            }
            if (typeof (x) === "function") {
                return x(netdataDashboard.os);
            }
            return x;
        }
        return def;
    },
    menuTitle(chart) {
        if (chart.sectionTitle) {
            return chart.sectionTitle;
        }
        if (typeof chart.menu_pattern !== "undefined") {
            const type = chart.type || chart.id.split(".")[0];
            return (`${this.anyAttribute(this.menu, "title", chart.menu_pattern, chart.menu_pattern)
                .toString()} ${type.slice(-(type.length - chart.menu_pattern.length - 1)).toString()}`)
                .replace(/_/g, " ");
        }
        return (this.anyAttribute(this.menu, "title", chart.menu, chart.menu)).toString()
            .replace(/_/g, " ");
    },
    menuIcon(chart) {
        if (typeof chart.menu_pattern !== "undefined") {
            return this.anyAttribute(this.menu, "icon", chart.menu_pattern, "<i class=\"fas fa-puzzle-piece\"></i>").toString();
        }
        return this.anyAttribute(this.menu, "icon", chart.menu, "<i class=\"fas fa-puzzle-piece\"></i>");
    },
    menuInfo(chart) {
        if (typeof chart.menu_pattern !== "undefined") {
            return this.anyAttribute(this.menu, "info", chart.menu_pattern, null);
        }
        return this.anyAttribute(this.menu, "info", chart.menu, null);
    },
    menuHeight(chart) {
        if (typeof chart.menu_pattern !== "undefined") {
            return this.anyAttribute(this.menu, "height", chart.menu_pattern, 1.0);
        }
        return this.anyAttribute(this.menu, "height", chart.menu, 1.0);
    },
    submenuTitle(menu, submenu) {
        const key = `${menu}.${submenu}`;
        // console.log(key);
        const title = this.anyAttribute(this.submenu, "title", key, submenu)
            .toString().replace(/_/g, " ");
        if (title.length > 28) {
            const a = title.substring(0, 13);
            const b = title.substring(title.length - 12, title.length);
            return `${a}...${b}`;
        }
        return title;
    },
    submenuInfo(menu, submenu) {
        const key = `${menu}.${submenu}`;
        return this.anyAttribute(this.submenu, "info", key, null);
    },
    submenuHeight(menu, submenu, relative) {
        const key = `${menu}.${submenu}`;
        return this.anyAttribute(this.submenu, "height", key, 1.0) * relative;
    },
    contextInfo(id) {
        const x = this.anyAttribute(this.context, "info", id, null);
        if (x !== null) {
            return `<div class="shorten dashboard-context-info"
        role="document">${x}</div>`;
        }
        return "";
    },
    contextValueRange(id) {
        if (typeof this.context[id] !== "undefined"
            && typeof this.context[id].valueRange !== "undefined") {
            try {
                return JSON.parse(this.context[id].valueRange);
            }
            catch (e) {
                return [null, null];
            }
        }
        return [null, null];
    },
    contextHeight(id, def) {
        if (typeof this.context[id] !== "undefined" && typeof this.context[id].height !== "undefined") {
            return def * this.context[id].height;
        }
        return def;
    },
    contextDecimalDigits(id, def) {
        if (typeof this.context[id] !== "undefined"
            && typeof this.context[id].decimalDigits !== "undefined") {
            return this.context[id].decimalDigits;
        }
        return def;
    },
};
// @ts-ignore
window.netdataDashboard = netdataDashboard;
//# sourceMappingURL=netdata-dashboard.js.map