#pragma once
#include <Arduino.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f, 16, 2);

namespace Screen{
    void init();
    void display(char* title, char* text);
}

void Screen::init(){
    lcd.begin();
    lcd.backlight();
    
    lcd.setCursor(3,0);
    lcd.print("CrabbyHome");
    lcd.setCursor(3,1);
    lcd.print("Activated!");
}

void Screen::display(char* title, char* text){
    int titleSize = strlen(title);
    int textSize = strlen(text);
    lcd.clear();
    lcd.display();
    lcd.backlight();
    
    // check if text fits in screen
    if(titleSize <= 16){
        int offset = (16 - titleSize) / 2;
        lcd.setCursor(offset, 0);
    }
    lcd.print(title);
    
    if(textSize <= 16){
        int offset = (16 - textSize) / 2;
        lcd.setCursor(offset, 1);
    }
    lcd.print(text);
    delay(1000);

    lcd.noBacklight();
    lcd.noDisplay();
}