// Import and register all your controllers from the importmap under controllers/*

import { application } from "controllers/application"

// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)

// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      const lat = position.coords.latitude;
      const lng = position.coords.longitude;
      fetchSunriseSunset(lat, lng);
    });
  } else {
    console.log("Geolocation is not supported by this browser.");
  }
  
  function fetchSunriseSunset(lat, lng) {
    fetch(`/getSunriseSunset?lat=${lat}&lng=${lng}`)
      .then(response => response.json())
      .then(data => {
        console.log(data.sunrise);  // This will be in local time
        console.log(data.sunset);   // This will be in local time 
      });
  }

  