'use strict';

var express = require('express');

function createDashboardRouter(backend) {
    const dashboardRouter = express.Router();
    function rangeToMs(range) {
        let rangeMs;
        switch (range) {
            case "12h":
                rangeMs = 12 * 60 * 60 * 1000;
                break;
            case "12d":
                rangeMs = 12 * 24 * 60 * 60 * 1000;
                break;
            case "12m":
            default:
                // Defaults to 12m
                rangeMs = 12 * 60 * 1000;
                break;
        }
        return rangeMs;
    }
    dashboardRouter.get("/", async (req, res) => {
        const { range = "12m" } = req.query;
        const from = new Date(Date.now() - rangeToMs(range));
        const jobs = await backend.countJobs({ from });
        res.render("pages/index", {
            title: "Sidequest Dashboard",
            stats: jobs,
        });
    });
    dashboardRouter.get("/dashboard/stats", async (req, res) => {
        const { range = "12m" } = req.query;
        const from = new Date(Date.now() - rangeToMs(range));
        const jobs = await backend.countJobs({ from });
        res.render("partials/dashboard-stats", {
            stats: jobs,
            layout: false,
        });
    });
    dashboardRouter.get("/dashboard/graph-data", async (req, res) => {
        const { range = "12m" } = req.query;
        const jobs = await backend.countJobsOverTime(range);
        res.json(jobs).end();
    });
    return ["/", dashboardRouter];
}

exports.createDashboardRouter = createDashboardRouter;
//# sourceMappingURL=dashboard.cjs.map
