"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    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) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRouter = void 0;
const configLoader = require("../lib/config-loader");
const dbManager = require("../lib/db-manager");
const express = require("express");
const helpers = require("../lib/helpers");
const moment = require("moment");
function createRouter(options) {
    options = options || {};
    const isReadOnlyRouter = options.readOnly || false;
    let uiRouter = express.Router();
    require('moment-timezone');
    const config = configLoader.getConfig();
    uiRouter.get('/', function (req, res) {
        res.render('home', {
            readOnlyView: isReadOnlyRouter,
            urlPrefix: config.urlPrefix
        });
    });
    uiRouter.get('/session/:sessionId', function (req, res) {
        return __awaiter(this, void 0, void 0, function* () {
            const db = dbManager.getDb();
            const sessionId = parseInt(req.params.sessionId);
            const dbTestSession = yield db.getSession(sessionId);
            if (dbTestSession) {
                const testSession = helpers.clone(dbTestSession);
                res.render('session', {
                    moment: moment,
                    readOnlyView: isReadOnlyRouter,
                    session: testSession,
                    urlPrefix: config.urlPrefix
                });
            }
            else {
                res.status(404).send(helpers.format('Session {0} not found', sessionId));
            }
        });
    });
    return uiRouter;
}
exports.createRouter = createRouter;
//# sourceMappingURL=ui.js.map