#include <FastLED.h>
#include <WiFi.h>
#include <NTPClient.h>
#include <EEPROM.h>
#include <ArduinoJson.h>

#define LED_PIN      2   // Pin al que está conectada la tira de LEDs
#define NUM_LEDS     86  // Número de LEDs en la tira
#define LED_BRIGHTNESS 100

CRGB leds[NUM_LEDS];

const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer = "time.windows.com";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpServer);

struct Alarm {
  int hour;
  int minute;
  bool active;
};

struct ClockConfig {
  int timezoneOffset;
  Alarm alarms[3];
};

ClockConfig clockConfig;

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(LED_BRIGHTNESS);

  Serial.begin(115200);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  timeClient.begin();

  EEPROM.begin(sizeof(clockConfig));
  EEPROM.get(0, clockConfig);

  if (clockConfig.timezoneOffset == 0) {
    // Set default values if EEPROM is empty
    clockConfig.timezoneOffset = -3;  // Example: UTC-3
    for (int i = 0; i < 3; i++) {
      clockConfig.alarms[i].hour = 0;
      clockConfig.alarms[i].minute = 0;
      clockConfig.alarms[i].active = false;
    }
    saveConfig();
  }
}

void loop() {
  timeClient.update();
  int currentHour = (timeClient.getHours() + clockConfig.timezoneOffset) % 24;
  int currentMinute = timeClient.getMinutes();

  // Display current time on LEDs
  displayTime(currentHour, currentMinute);

  // Check and display alarms
  checkAndDisplayAlarms(currentHour, currentMinute);

  delay(1000); // Wait for a second
}

void displayTime(int hour, int minute) {
  // Implement LED display for the current time here
}

void checkAndDisplayAlarms(int currentHour, int currentMinute) {
  // Implement alarm checking and LED display for alarms here
}

void saveConfig() {
  EEPROM.put(0, clockConfig);
  EEPROM.commit();
}