<script>
  import { connectWS, wsState } from "$lib/ws.svelte";
  import { onMount } from "svelte";
  import "../../app.css";
  import { browser } from "$app/environment";
  import ConnectionLostDialog2 from "$lib/ConnectionLostDialog2.svelte";

  let { children } = $props();

  onMount(() => {
    if (!browser) return;

    connectWS();
    console.log("Connecting to WebSocket...");
  });
</script>

{#if wsState.closed}
  <ConnectionLostDialog2 />
{/if}

{#if !wsState.connected && !wsState.closed}{/if}

{@render children?.()}

<style>
  #blocker {
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 1rem;
  }
</style>
