/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ "./src/WebSocketEvent.ts":
/*!*******************************!*\
  !*** ./src/WebSocketEvent.ts ***!
  \*******************************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.WebSocketEvent = void 0;
var WebSocketEvent;
(function (WebSocketEvent) {
    WebSocketEvent["STATUS"] = "STATUS";
})(WebSocketEvent = exports.WebSocketEvent || (exports.WebSocketEvent = {}));


/***/ }),

/***/ "./src/WebSocketPayload.ts":
/*!*********************************!*\
  !*** ./src/WebSocketPayload.ts ***!
  \*********************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.WebSocketPayload = void 0;
const WebSocketEvent_1 = __webpack_require__(/*! ./WebSocketEvent */ "./src/WebSocketEvent.ts");
class WebSocketPayload {
    constructor(event, error = false, data) {
        this._event = event;
        this._error = error;
        this._data = data;
    }
    set event(value) {
        this._event = value;
    }
    set error(value) {
        this._error = value;
    }
    set data(value) {
        this._data = value;
    }
    get event() {
        return this._event;
    }
    get error() {
        return this._error;
    }
    get data() {
        return this._data;
    }
    static parseFromBase64Json(json) {
        json = (typeof window != 'undefined') ? atob(json) : Buffer.from(json, "base64").toString();
        let rawPayload;
        try {
            rawPayload = JSON.parse(json);
        }
        catch (e) {
            return null;
        }
        let wsEvent = WebSocketEvent_1.WebSocketEvent[rawPayload.event];
        return new WebSocketPayload(wsEvent, rawPayload.error, rawPayload.data);
    }
    toString() {
        let json = JSON.stringify({ "event": this._event, status: this._error, data: this._data });
        json = ((typeof window != 'undefined') ? btoa(json) : Buffer.from(json).toString("base64"));
        return json;
    }
}
exports.WebSocketPayload = WebSocketPayload;


/***/ }),

/***/ "./src/web/ButtonType.ts":
/*!*******************************!*\
  !*** ./src/web/ButtonType.ts ***!
  \*******************************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ButtonType = void 0;
var ButtonType;
(function (ButtonType) {
    ButtonType["SUCCESS"] = "success";
    ButtonType["ERROR"] = "error";
})(ButtonType = exports.ButtonType || (exports.ButtonType = {}));


/***/ }),

/***/ "./src/web/Modal.ts":
/*!**************************!*\
  !*** ./src/web/Modal.ts ***!
  \**************************/
/***/ ((__unused_webpack_module, exports) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Modal = void 0;
class Modal {
    constructor(id, title, content) {
        this._title = "iTender";
        this._content = "";
        this._id = "";
        this._loader = false;
        this._buttons = [];
        this._id = id;
        this._title = title;
        this._content = content;
    }
    set title(value) {
        this._title = value;
    }
    set content(value) {
        this._content = value;
    }
    set id(value) {
        this._id = value;
    }
    set loader(value) {
        this._loader = value;
    }
    addButton(type, content, onclick) {
        this._buttons.push({ type: type, content: content, onclick: onclick });
    }
    open() {
        if (!this._content)
            this._content = "";
        if (this._loader)
            this._content += "<br><div class=\"lds-ellipsis\">\n" +
                "  <div></div><div></div><div></div><div></div>\n" +
                "</div>";
        for (let btn of this._buttons) {
            this._content += `<button class="btn btn-${btn.type}" onclick="(${btn.onclick})();">${btn.content}</button>`;
        }
        Modal.open(this._title, this._content, this._id);
    }
    static open(title, content, id) {
        const modal = document.getElementById("modal");
        const modalContent = document.getElementById("modalInnerContent");
        if (!modal || !modalContent)
            return;
        modalContent.classList.add("modalBlendIn");
        modal.classList.add("modalBlendIn");
        setTimeout(() => {
            modalContent.classList.remove("modalBlendIn");
            modal.classList.remove("modalBlendIn");
        }, 800);
        modalContent.innerHTML = `<h1 id="modalTitle">${title}</h1>${content}`;
        modal.style.display = "block";
        this.currentModalId = id ? id : "null";
    }
    static close(id) {
        if (this.currentModalId != id)
            return;
        const modal = document.getElementById("modal");
        const modalContent = document.getElementById("modal-content");
        const modalInnerContent = document.getElementById("modalInnerContent");
        if (!modal || !modalContent || !modalInnerContent)
            return;
        modalContent.classList.add("modalBlendOut");
        modal.classList.add("modalBlendOut");
        setTimeout(() => {
            modal.style.display = "none";
            modalInnerContent.innerHTML = "";
            modalContent.classList.remove("modalBlendOut");
            modal.classList.remove("modalBlendOut");
        }, 800);
    }
}
exports.Modal = Modal;
Modal.currentModalId = "";


/***/ }),

/***/ "./src/web/WebWebSocketHandler.ts":
/*!****************************************!*\
  !*** ./src/web/WebWebSocketHandler.ts ***!
  \****************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.WebWebSocketHandler = void 0;
const Modal_1 = __webpack_require__(/*! ./Modal */ "./src/web/Modal.ts");
const WebSocketEvent_1 = __webpack_require__(/*! ../WebSocketEvent */ "./src/WebSocketEvent.ts");
const WebSocketPayload_1 = __webpack_require__(/*! ../WebSocketPayload */ "./src/WebSocketPayload.ts");
const ButtonType_1 = __webpack_require__(/*! ./ButtonType */ "./src/web/ButtonType.ts");
class WebWebSocketHandler {
    constructor() {
        this.socket = new WebSocket(WebWebSocketHandler.url);
        this.socket.onopen = this.onOpen;
        this.socket.onclose = this.onClose;
        this.socket.onerror = this.onError;
        this.socket.onmessage = this.onMessage;
    }
    onMessage(msgEvent) {
        console.log("[WS] Incoming message", msgEvent);
        let payload = WebSocketPayload_1.WebSocketPayload.parseFromBase64Json(msgEvent.data);
        if (!payload) {
            console.log("[WS] Could not parse message: ", msgEvent);
            return;
        }
        console.debug(payload);
        console.debug(payload.event);
        console.log("[WS] Received " + payload.event + " Event");
        switch (payload.event) {
            case WebSocketEvent_1.WebSocketEvent.STATUS: {
                let statusElement = document.getElementById("status");
                if (statusElement)
                    statusElement.innerText = payload.data.status;
            }
        }
    }
    onOpen(event) {
        console.log("[WS] Connected", event);
        Modal_1.Modal.close("start");
        let connectionElement = document.getElementById("right");
        if (connectionElement)
            connectionElement.innerText = "Verbunden";
    }
    onClose(event) {
        console.error("[WS] Closed!", event);
        if (event.wasClean) {
            let modal = new Modal_1.Modal("socketClosed", "Sitzung beendet!");
            modal.content = `Diese Sitzung wurde beendet, da der iTender nun an einem anderen Gerät bzw. an dem Hauptgerät gesteuert wird.<br><br>`;
            modal.addButton(ButtonType_1.ButtonType.SUCCESS, "Sitzung wiederherstellen", () => {
                window.location.reload();
            });
            modal.open();
        }
        else {
            let modal = new Modal_1.Modal("socketClosed", "Verbindungsproblem!");
            modal.content = `Die Benutzeroberfläche hat die Verbindung mit dem Gerät verloren.<br>Die Verbindung wird wiederhergestellt...<br>`;
            modal.loader = true;
            modal.open();
            setInterval(() => {
                window.location.reload();
            }, 5000);
        }
        let connectionElement = document.getElementById("right");
        if (connectionElement)
            connectionElement.innerText = "Keine Verbindung";
    }
    onError(event) {
        console.error("[WS] Error", event);
        let connectionElement = document.getElementById("right");
        if (connectionElement)
            connectionElement.innerText = "Fehler";
    }
}
exports.WebWebSocketHandler = WebWebSocketHandler;
WebWebSocketHandler.url = (window.location.protocol == "http:" ? "ws://" : "wss://") + window.location.hostname + ":3005";


/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
var exports = __webpack_exports__;
/*!*************************!*\
  !*** ./src/web/main.ts ***!
  \*************************/

Object.defineProperty(exports, "__esModule", ({ value: true }));
const WebWebSocketHandler_1 = __webpack_require__(/*! ./WebWebSocketHandler */ "./src/web/WebWebSocketHandler.ts");
const Modal_1 = __webpack_require__(/*! ./Modal */ "./src/web/Modal.ts");
const main = document.getElementById("main");
const time = document.getElementById("title");
document.addEventListener("DOMContentLoaded", () => {
    console.log("DOM Loaded");
    let modal = new Modal_1.Modal("start", "iTender");
    modal.content = "Willkommen";
    modal.loader = true;
    modal.open();
    connect();
    setTimeout(load, 1000);
});
function load() {
    if (!main || !time)
        return;
    setInterval(() => {
        let currentDate = new Date();
        time.innerText = "" + (currentDate.getHours() < 10 ? "0" + currentDate.getHours() : currentDate.getHours()) + ":" + (currentDate.getMinutes() < 10 ? "0" + currentDate.getMinutes() : currentDate.getMinutes());
    }, 1000);
    let maxI = 20;
    main.style.gridTemplateRows = `repeat(${Math.round(maxI / 3)}, calc(90%/2))`;
    for (let i = 0; i < maxI; i++) {
        let testDrink = document.createElement("div");
        testDrink.classList.add("drink");
        let img = document.createElement("img");
        img.classList.add("thumbnail");
        testDrink.append(img);
        let name = document.createElement("p");
        name.classList.add("name");
        testDrink.append(name);
        img.alt = "Thumbnail";
        name.innerText = "Mixery";
        main.append(testDrink);
    }
}
let wsHandler;
function connect() {
    wsHandler = new WebWebSocketHandler_1.WebWebSocketHandler();
}

})();

/******/ })()
;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 25748 characters]