const http = require('http')
const globalVars = require('../libs/globalVars')
const led = require('../libs/led')
const common = require('../libs/common')
const screen = require('../libs/lcd')

var requireDir = require('require-dir');
var modules = requireDir('../modules');

module.exports = {
    home: async () => {
        clearInterval(globalVars.waterPolling);
        clearInterval(globalVars.heatingPolling)
        clearInterval(globalVars.piHolePolling)
        await screen.clearScreen()
        await screen.heading('Main Menu')
        await screen.clearLine(2)
        await screen.clearLine(3)
        await screen.clearLine(4)
        await screen.time()
        await modules.weather.getStatus()
    },
    water: async () => {
        clearInterval(globalVars.waterPolling);
        clearInterval(globalVars.heatingPolling)
        clearInterval(globalVars.piHolePolling)
        await screen.clearScreen()
        await screen.heading('Hot Water')
        await screen.time()
        await modules.water.getStatus()
        globalVars.waterPolling = setInterval(() => {
            modules.water.getStatus()
        }, 60000);
    },
    heating: async () => {
        clearInterval(globalVars.waterPolling);
        clearInterval(globalVars.heatingPolling)
        clearInterval(globalVars.piHolePolling)
        await screen.clearScreen()
        await screen.heading('Heating')
        await screen.time()
        await modules.heating.getStatus(globalVars.heatingPageS)
        globalVars.heatingPolling = setInterval(async () => {
            await modules.heating.getStatus(globalVars.heatingPageS)
        }, 60000);
    },
    piHole: async () => {
        clearInterval(globalVars.waterPolling);
        clearInterval(globalVars.heatingPolling)
        clearInterval(globalVars.piHolePolling)
        await screen.clearScreen()
        await screen.heading('PiHole')
        await screen.time()
        await modules.pihole.getStatus()
        globalVars.piHolePolling = setInterval(() => {
            modules.pihole.getStatus()
        }, 30000);
    },
}