const LCD = require('raspberrypi-liquid-crystal');
const common = require('./common')
const globalVars = require('./globalVars')
const clock = require('./clock');

const lcd = new LCD(1, 0x27, 20, 4);

lcd.beginSync();

module.exports = {
    clearScreen: async () => {
        lcd.clearSync();
    },
    clearLine: async (line) => {
        line = line - 1
        lcd.setCursorSync(0, line);
        lcd.printSync('                    ')
    },
    intro: async () => {
        lcd.clearSync();
        lcd.printLineSync(1, 'MiGenie Status')
        lcd.setCursorSync(13, 2);
        lcd.printSync('By Karl')
        await common.pause(3000)
        lcd.clearSync();
    },
    heading: async (title) => {
        lcd.setCursorSync(0, 0);
        lcd.printSync(title)
    },
    time: async () => {
        console.log('get time')
        lcd.setCursorSync(15, 0);
        lcd.printSync(await clock.time())
    },
    waterStatus: async (input) => {
        lcd.printLineSync(2, 'Water=')
        lcd.setCursorSync(6, 2);
        lcd.printSync('                    ')
        lcd.setCursorSync(6, 2);
        lcd.printSync(input)
    },
    heatingStatus: async (input) => {
        lcd.printLineSync(2, 'Heating=')
        lcd.setCursorSync(8, 2);
        lcd.printSync('                  ')
        lcd.setCursorSync(8, 2);
        lcd.printSync(input)
    },
    NextEvent: async (input) => {
        if (globalVars.waterOn === "true") {
            lcd.printLineSync(3, 'Switch Off=')
            lcd.setCursorSync(11, 3);
            lcd.printSync('         ')
            lcd.setCursorSync(11, 3);
            lcd.printSync(input)
        } else {
            lcd.printLineSync(3, 'Switch On=')
            lcd.setCursorSync(10, 3);
            lcd.printSync('         ')
            lcd.setCursorSync(10, 3);
            lcd.printSync(input)
        }
    },
    currentRoomTemp: async (temp) => {
        let icon = '°'
        temp = temp + icon
        console.log(temp)
    },
    lastSetTemp: async (temp) => {
        let icon = '°'
        temp = temp + icon
        console.log(temp)
    }
}