package state

var (
	serviceWorkerInstall = templ.NewOnceHandle()
)

templ RegisterServiceWorker() {
	@serviceWorkerInstall.Once() {
		<script type="text/javascript">
          if ("serviceWorker" in navigator) {
            // Register the service worker
            window.addEventListener("load", function() {
                navigator.serviceWorker
                    .register("/sw.js")
                    .then(function (registration) {
                        console.log("Service Worker registered with scope:", registration.scope);
                    })
                    .catch(function (error) {
                        console.log("Service Worker registration failed:", error);
                    });
            });
        }
    </script>
	}
}
