/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

function __export(m) {
    for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(1));
__export(__webpack_require__(2));


/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const options = { autoscroll: true };
let socket;
class Socket {
    /**
     *
     */
    constructor() {
        this.io = window.io;
        this.activeTails = {};
        this.init();
    }
    tail(logpath) {
        this.socket.emit('GET_/tail', logpath, function (data) {
        });
    }
    endTail(logpath) {
        this.socket.emit('GET_/end_tail', logpath, function (data) {
        });
    }
    init() {
        if (!this.io)
            return;
        this.socket = this.io('/describe', { nsp: '/describe' }).connect();
        //this.socket = this.io.connect();
        socket = this.socket;
        setTimeout(() => {
            this.socket.emit('GET_/connect', {}, (data) => {
                document.getElementById('FilesList').innerHTML = data.result.map(elem => {
                    return `<a class="dropdown-item" href='javascript:socketClass.tail(${JSON.stringify(elem)})'>${elem}</a>`;
                }).join();
            });
        }, 2000);
        this.socket.on('log', (logsData) => {
            document.getElementById('LogTail').innerHTML += logsData;
            if (options.autoscroll) {
                document.documentElement.scrollTop = document.body.scrollHeight;
            }
        });
        this.socket.on('disconnect', function () {
            console.log('user disconnected');
        });
    }
}
exports.Socket = Socket;
function tail(logpath) {
    socketClass.activeTails[logpath] = logpath;
    document.getElementById('ActiveTails').innerHTML = Object.keys(socketClass.activeTails).map(elem => {
        return `<a class="dropdown-item" href='javascript:tail(${JSON.stringify(elem)})'>${elem}</a>`;
    }).join();
    socket.emit('GET_/tail', logpath, function (data) {
    });
}
const socketClass = new Socket();
window.socketClass = socketClass;


/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const dynamicProxy_1 = __webpack_require__(3);
class UI {
    constructor() {
        var storedStr = localStorage.getItem('methodusTestParams') || '{}';
        this.store = JSON.parse(storedStr);
        var selected = document.querySelectorAll('.store');
        selected.forEach((param) => {
            const cacheValue = this.store[param.name || param.id];
            if (cacheValue !== undefined && cacheValue !== null) {
                param.value = cacheValue;
            }
        });
        this.client = new dynamicProxy_1.Proxy();
    }
    renderJsonResponse(element, data, options) {
        options = options || { collapsed: true };
        $(element).jsonViewer(data, options);
    }
    cacheParams() {
        var selected = document.querySelectorAll('.store');
        const storedStr = localStorage.getItem('methodusTestParams') || '{}';
        this.store = JSON.parse(storedStr);
        selected.forEach((param) => {
            this.store[param.name || param.id] = param.value;
        });
        localStorage.setItem('methodusTestParams', JSON.stringify(this.store));
        return true;
    }
    updateParam() {
        //document.getElementById('TestForm').action = url;
        // execute();
        //build the request url (params + query)
        var selected = document.querySelectorAll('.param');
        const testForm = document.getElementById('TestForm');
        const params = [];
        if (testForm) {
            var url = testForm.getAttribute('xaction');
            const method = testForm.getAttribute('method');
            if (selected && url) {
                selected.forEach(function (param) {
                    params.push({ id: param.id, value: param.value });
                });
            }
            var selectedQuery = document.querySelectorAll('.query');
            let queryString = [];
            selectedQuery.forEach(function (param) {
                if (param.value) {
                    queryString.push(`${param.id}=${param.value}`);
                }
            });
            const RequestUrl = document.getElementById('RequestUrl');
            if (RequestUrl) {
                let finalUrl = url;
                params.forEach((param) => {
                    finalUrl = finalUrl.replace(`:${param.id}`, param.value);
                });
                RequestUrl.innerHTML = finalUrl;
            }
            //add body
            const body = {};
            let selectedBody = document.querySelectorAll('.body');
            selectedBody.forEach(function (param) {
                if (param.name) {
                    body[param.name] = param.value;
                }
                else {
                    try {
                        const str = param.value;
                        const obj = JSON.parse(str);
                        Object.assign(body, obj);
                    }
                    catch (error) {
                        console.error(param.value, 'not a json object');
                    }
                }
            });
            let headers = {};
            if (this.store['att_security_context']) {
                // headers = { "hub-ess-cookie": `{"user_id":"${this.store['att_security_context']}"}` };
                // headers = { "iv-user": `"${this.store['att_security_context']}"` };
                headers = { "dev-iv-user": `"${this.store['att_security_context']}"`, "iv-user": `"${this.store['att_security_context']}"` };
                // [
                //    { "hub-ess-cookie": `{"user_id":"${this.store['att_security_context']}"}` },
                // { "iv-user": `"${this.store['att_security_context']}"` }];
                //headers = { 'iv-user': `${this.store['att_security_context']}` };
            }
            this.client.prepare(url, method, params, body, queryString, headers);
        }
    }
    jsonHandler(json) {
        return __awaiter(this, void 0, void 0, function* () {
            $('#HtmlPane').hide();
            $('#JsonPane').show();
            $('#JsonPane').jsonViewer(json, { collapsed: false });
        });
    }
    htmlHandler(html) {
        return __awaiter(this, void 0, void 0, function* () {
            $('#JsonPane').hide();
            $('#HtmlPane').html(html).show();
        });
    }
    responseHandler(response) {
        return __awaiter(this, void 0, void 0, function* () {
            const responseHeaders = document.getElementById('ResponseHeaders');
            if (responseHeaders) {
                responseHeaders.innerHTML = JSON.stringify({ url: response.url });
            }
            const RequestUrl = document.getElementById('RequestUrl');
            if (RequestUrl) {
                RequestUrl.innerHTML = response.url;
            }
            if (response.status === 200) {
                $('#ResultStatusOK').show();
                $('#ResultStatusBAD').hide();
            }
            else {
                $('#ResultStatusOK').hide();
                $('#ResultStatusBAD').show();
            }
            $('#StatusCode').html(response.status);
        });
    }
    execute() {
        return __awaiter(this, void 0, void 0, function* () {
            this.updateParam();
            this.cacheParams();
            const response = yield this.client.execute(this.responseHandler, this.jsonHandler, this.htmlHandler);
        });
    }
}
exports.UI = UI;
window.ui = new UI();


/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
class Proxy {
    constructor() {
        this.options = {};
    }
    prepare(url, method, params, body, query, headers) {
        //M.Rest.
        //console.log(url, method, params, body, query, headers);
        if (params && url) {
            params.forEach(function (param) {
                if (url) {
                    url = url.replace(':' + param.id, param.value);
                }
            });
        }
        if (query && query.length > 0) {
            url = url + '?' + query.join('&');
        }
        let formData = new FormData();
        Object.keys(body).forEach((key) => {
            formData.append(key, body[key]);
        });
        //add files
        //add headers
        this.url = url;
        this.request = new Request(url);
        this.options = {
            method: method,
            credentials: 'include',
            headers: Object.assign(headers, {
                'Content-Type': 'application/json'
            }),
            //headers: myHeaders,
            mode: 'cors',
            cache: 'default'
        };
        if (body && Object.keys(body).length > 0) {
            Object.assign(this.options, { body: JSON.stringify(body) });
        }
    }
    execute(responseCB, jsonCB, htmlCB) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield fetch(this.request, this.options);
            if (responseCB) {
                responseCB(response);
            }
            try {
                let jsonResult = yield response.text();
                try {
                    jsonResult = JSON.parse(jsonResult);
                    if (jsonCB) {
                        jsonCB(jsonResult);
                    }
                }
                catch (error) {
                    if (htmlCB) {
                        htmlCB(jsonResult);
                    }
                }
                return jsonResult;
            }
            catch (error) {
                return response.text();
            }
            // return response.json();
            // throw new Error('Network response was not ok.');
        });
    }
}
exports.Proxy = Proxy;


/***/ })
/******/ ]);