import { Router } from 'express';
import { Main } from '../Main';
import { join } from 'path';
import { pathExistsSync, readdirSync, readFile } from 'fs-extra';

export class DashboardRouter {
	private _Main: Main;
	Router: Router;

	path: string;

	constructor(Main: Main) {
		this._Main = Main;
		this.Router = Router();

		this.path = join(
			__filename,
			'..',
			'..',
			'..',
			'frontend',
			'views',
			'dashboard',
		);

		this.registerRoutes();
	}

	async registerRoutes() {
		this.Router.get(
			['/dashboard', '/calibration', '/cameralogs', '/unitylogs'],
			async (req, res) => {
				const htmlContent = await readFile(
					join(this.path, 'index.html'),
				);
				res.setHeader('Content-Type', 'text/html');
				res.send(htmlContent);
			},
		);
		this.Router.get('/dashboard/style.css', async (req, res) => {
			const styleContent = await readFile(join(this.path, 'style.css'));
			res.setHeader('Content-Type', 'text/css');
			res.send(styleContent);
		});
		this.Router.get('/dashboard/script.js', async (req, res) => {
			const scriptContent = await readFile(join(this.path, 'script.js'));
			res.setHeader('Content-Type', 'application/javascript');
			res.send(scriptContent);
		});
	}
}
