'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = exports.showTabHtmlAndScript = exports.giveHTMLAndScript = exports.decodeHtml = exports.encodeHtml = exports.getChartOptions = exports.getChartDoc = exports.selectDrawAll = exports.selectDraw = exports.containerDrawAll = exports.containerDraw = exports.containerLoadAll = exports.HOMEPAGE = exports.VERSION = exports.leaflet = exports.d3 = exports.google = exports.bordercloud = exports.sgvizler = void 0;
const tslib_1 = require("tslib");
// Namespace
const S = tslib_1.__importStar(require("./sgvizler"));
exports.sgvizler = S;
const bordercloudNS = tslib_1.__importStar(require("./bordercloud"));
exports.bordercloud = bordercloudNS;
const googleNS = tslib_1.__importStar(require("./google"));
exports.google = googleNS;
const d3NS = tslib_1.__importStar(require("./d3"));
exports.d3 = d3NS;
const leafletNS = tslib_1.__importStar(require("./leaflet"));
exports.leaflet = leafletNS;
/**
 * Todo
 * @const
 *
 */
exports.VERSION = S.Core.VERSION;
/**
 * Todo
 * @const
 */
exports.HOMEPAGE = S.Core.HOMEPAGE;
/**
 * Draws the sgvizler-containers with the given element id.
 *
 */
function containerLoadAll() {
    S.Container.loadAllDependencies();
}
exports.containerLoadAll = containerLoadAll;
function readOptions(options) {
    if (options) {
        if (typeof options === 'object') {
            exports.google.API.key = options.googleApiKey ? options.googleApiKey : '';
            exports.leaflet.API.osmAccessToken = options.osmAccessToken ? options.osmAccessToken : '';
            if (options.path) {
                S.Core.path = options.path.endsWith('/') ? options.path : options.path + '/';
            }
            else {
                S.Core.path = '';
            }
        }
    }
}
/**
 * Draws the sgvizler-containers with the given element id.
 * @param {string} elementID
 */
function containerDraw(elementID, options) {
    // S.Container.loadDependenciesId(elementID)
    readOptions(options);
    S.Container.drawWithElementId(elementID);
    return S.Logger;
}
exports.containerDraw = containerDraw;
/**
 * Todo.
 */
function containerDrawAll(options) {
    // S.Container.loadAllDependencies()
    readOptions(options);
    S.Container.drawAll();
    return S.Logger;
}
exports.containerDrawAll = containerDrawAll;
/**
 * Todo.
 */
function selectDraw(elementID) {
    // S.Select.loadDependencies()
    S.Select.drawWithElementId(elementID);
    return S.Logger;
}
exports.selectDraw = selectDraw;
/**
 * Todo.
 */
function selectDrawAll() {
    // S.Select.loadDependencies()
    S.Select.drawAll();
    return S.Logger;
}
exports.selectDrawAll = selectDrawAll;
/**
 * Todo.
 * @param {string} className
 * @param {string} pathDoc
 * @returns {string}
 */
function getChartDoc(className, pathDoc) {
    return S.Select.getChartDoc(className, pathDoc);
}
exports.getChartDoc = getChartDoc;
/**
 * Todo.
 * @param {string} className
 * @param {string} pathDoc
 * @returns {string}
 */
function getChartOptions(elementID) {
    let optionsChart = "";
    S.Container.list.forEach((container) => {
        if (container.id === elementID) {
            optionsChart = container.chart.newOptionsRaw;
        }
    });
    return optionsChart;
}
exports.getChartOptions = getChartOptions;
function encodeHtml(str) {
    return S.Tools.encodeHtml(str);
}
exports.encodeHtml = encodeHtml;
function decodeHtml(str) {
    return S.Tools.decodeHtml(str);
}
exports.decodeHtml = decodeHtml;
function giveHTMLAndScript(idDivOfSgvizler, idHtmlOfSgvizler, idScriptOfSgvizler, options) {
    let div = document.getElementById(idDivOfSgvizler);
    let htmlDiv = document.getElementById(idHtmlOfSgvizler);
    let scriptDiv = document.getElementById(idScriptOfSgvizler);
    if (div) {
        if (htmlDiv) {
            htmlDiv.textContent = new XMLSerializer().serializeToString(div)
                .replace(/&#10;/g, "\n")
                .replace(/xmlns="http:\/\/www.w3.org\/1999\/xhtml"/g, "")
                .replace(/ data-/gm, "\ndata-");
        }
        if (scriptDiv) {
            let script = "<script src=\"../browser/sgvizler2.js\"><\/script>\n" +
                "<script>\n";
            if (options) {
                script += "var options = {\n" +
                    "             googleApiKey : \"YOUR_GOOGLE_MAP_API_KEY\",\n" +
                    "             //OpenStreetMap Access Token\n" +
                    "             // https://www.mapbox.com/\n" +
                    "             osmAccessToken:  \"YOUR_OSM_ACCESS_TOKEN\"\n" +
                    "};\n";
                script += "//Draw a chart\n" +
                    "//sgvizler2.containerDraw('result',options);\n" +
                    "//or\n" +
                    "//$(\"#result\").containerchart(options);\n" +
                    "\n" +
                    "//Draw all Chart\n" +
                    "sgvizler2.containerDrawAll(options);\n";
            }
            else {
                script +=
                    "//Draw a chart\n" +
                        "//sgvizler2.containerDraw('" + idDivOfSgvizler + "');\n" +
                        "//or\n" +
                        "//$(\"#" + idDivOfSgvizler + "\").containerchart();\n" +
                        "\n" +
                        "//Draw all Chart\n" +
                        "sgvizler2.containerDrawAll();\n";
            }
            script += "<\/script>";
            scriptDiv.textContent = script;
        }
    }
}
exports.giveHTMLAndScript = giveHTMLAndScript;
function showTabHtmlAndScript(idDivOfSgvizler, options) {
    $("#" + idDivOfSgvizler).before('<ul class="nav nav-tabs" role="tablist" idDivOfSgvizler="' + idDivOfSgvizler + 'tab">\n' +
        '    <li class="nav-item">\n' +
        '         <a class="nav-link active" data-toggle="tab" href="#' + idDivOfSgvizler + 'Tab" role="tab" aria-expanded="true">Result</a>\n' +
        '         </li>\n' +
        '         <li class="nav-item">\n' +
        '         <a class="nav-link" data-toggle="tab" href="#' + idDivOfSgvizler + 'htmlTab" role="tab" aria-expanded="false">HTML</a>\n' +
        '         </li>\n' +
        '         <li class="nav-item">\n' +
        '         <a class="nav-link" data-toggle="tab" href="#' + idDivOfSgvizler + 'scriptTab" role="tab" aria-expanded="false">Javascript</a>\n' +
        '         </li>\n' +
        '</ul>\n' +
        '<div class="tab-content">\n' +
        '         <div class="tab-pane active" id="' + idDivOfSgvizler + 'Tab" role="tabpanel" aria-expanded="true">' +
        '              <div id="' + idDivOfSgvizler + 'example" style="padding: 25px;"></div>' +
        '         </div>\n' +
        '         <div class="tab-pane" id="' + idDivOfSgvizler + 'htmlTab" role="tabpanel" aria-expanded="false">\n' +
        '            <div class="bg-faded" style="padding: 25px;"><pre lang="html" id="' + idDivOfSgvizler + 'Html"></pre></div>\n' +
        '         </div>\n' +
        '         <div class="tab-pane" id="' + idDivOfSgvizler + 'scriptTab" role="tabpanel" aria-expanded="false">\n' +
        '            <div class="bg-faded" style="padding: 25px;"><pre lang="html" id="' + idDivOfSgvizler + 'Script"></pre></div>\n' +
        '         </div>\n' +
        '</div>');
    var element = $("#" + idDivOfSgvizler).detach();
    $('#' + idDivOfSgvizler + 'example').append(element);
    giveHTMLAndScript(idDivOfSgvizler, idDivOfSgvizler + "Html", idDivOfSgvizler + "Script", options);
}
exports.showTabHtmlAndScript = showTabHtmlAndScript;
/**
 * Todo
 * @param {string} elementID
 * @param {string} endpoint
 * @param {string} query
 * @param {string} chartName
 * @param {string} options
 * @param {string} loglevel
 * @returns {string}
 */
function create(elementID, endpoint, query, chartName, options, loglevel, output, method, parameter, lang) {
    return S.Container.create(elementID, endpoint, query, chartName, options, loglevel, output, method, parameter, lang);
}
exports.create = create;
// noinspection JSPotentiallyInvalidConstructorUsage
jQuery.fn.extend({
    selectchart: function (param, option) {
        let $this = this;
        let action = 'render';
        if (param) {
            if (typeof param === 'string') {
                action = param;
            }
            else if (typeof param === 'object') {
                action = param.action ? param.action : action;
            }
        }
        // Return the jQuery object for chaining.
        return $this.each(function (index, obj) {
            if (index >= 0 && action === 'render') {
                if (param && typeof param === 'object') {
                    S.Select.draw(obj, param);
                }
                else {
                    S.Select.draw(obj);
                }
            }
        });
    },
    containerchart: function (param, option) {
        let $this = this;
        let action = 'render';
        if (param) {
            if (typeof param === 'string') {
                action = param;
            }
            else if (typeof param === 'object') {
                action = param.action ? param.action : action;
            }
        }
        // Return the jQuery object for chaining.
        return $this.each(function (index, obj) {
            if (index >= 0 && action === 'render') {
                if (param && typeof param === 'object') {
                    readOptions(param);
                }
                S.Container.drawWithElementId($(obj).attr('id'));
            }
        });
    }
});
S.Loader.detectRoot();
//# sourceMappingURL=data:application/json;base64, 