<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ChargeOps</title>

    <!-- PWA Meta Tags -->
    <meta name="theme-color" content="#1e40af" />
    <meta
      name="description"
      content="Electric Vehicle Charging Load Management System"
    />

    <!-- iOS Support -->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="default" />
    <meta name="apple-mobile-web-app-title" content="ChargeOps" />

    <!-- Icons -->
    <link rel="icon" type="image/png" sizes="32x32" href="/icons/ios/32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/icons/ios/16.png" />
    <link rel="apple-touch-icon" sizes="180x180" href="/icons/ios/180.png" />
    <link rel="apple-touch-icon" sizes="152x152" href="/icons/ios/152.png" />
    <link rel="apple-touch-icon" sizes="120x120" href="/icons/ios/120.png" />
    <link rel="apple-touch-icon" sizes="76x76" href="/icons/ios/76.png" />

    <!-- PWA Manifest -->
    <link rel="manifest" href="/manifest.json" />
    <script type="module" crossorigin src="/assets/index-BlNnT4wk.js"></script>
    <link rel="stylesheet" crossorigin href="/assets/index-DJBGh5p0.css">
  </head>
  <body>
    <div id="root"></div>
    <!-- Service Worker Registration -->
    <script>
      if ("serviceWorker" in navigator) {
        window.addEventListener("load", () => {
          navigator.serviceWorker
            .register("/sw.js")
            .then((registration) => {
              console.log(
                "ServiceWorker registration successful:",
                registration,
              );

              // Auto-reload strategy for production deployments only
              // Disabled in development to avoid conflicts with HMR
              const isProduction =
                window.location.protocol === "https:" &&
                !window.location.hostname.includes(".replit.dev") &&
                !window.location.hostname.includes("localhost");

              if (isProduction) {
                registration.addEventListener("updatefound", () => {
                  const installingWorker = registration.installing;
                  if (installingWorker) {
                    installingWorker.addEventListener("statechange", () => {
                      if (
                        installingWorker.state === "installed" &&
                        navigator.serviceWorker.controller
                      ) {
                        console.log(
                          "[PWA Update] New version available, reloading...",
                        );
                        setTimeout(() => window.location.reload(), 1000);
                      }
                    });
                  }
                });

                // Check for updates periodically
                setInterval(() => registration.update(), 60000);
              } else {
                console.log("[PWA] Auto-reload disabled in development");
              }
            })
            .catch((err) =>
              console.error("ServiceWorker registration failed:", err),
            );
        });
      }
    </script>
    <!-- Replit dev banner disabled to prevent WebSocket errors that interfere with HMR -->
  </body>
</html>
