<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Hypha App (window)</title>
  <meta name="description" content="Template for Hypha app">
  <meta name="author" content="ImJoy-Team">
</head>

<body>
<script type="module">
  const config = {{ config | tojson(indent=2) }}
  const cfg = Object.assign(config, Object.fromEntries(new URLSearchParams(window.location.search)));
  if(!cfg.server_url) cfg.server_url = window.location.origin;
    
  window.env = new Map()
  window.env.set("HYPHA_SERVER_URL", config.server_url)
  window.env.set("HYPHA_WORKSPACE", config.workspace)
  window.env.set("HYPHA_CLIENT_ID", config.client_id)
  window.env.set("HYPHA_TOKEN", config.token)
  window.env.set("HYPHA_APP_ID", config.app_id)

  const hyphaWebsocketClient = await import(cfg.server_url + '/assets/hypha-rpc-websocket.mjs');
  hyphaWebsocketClient.connectToServer(cfg).then(async (api)=>{
      await hyphaWebsocketClient.loadRequirements([{% for req in requirements %}"{{req}}", {% endfor %}])
      {{ script | safe }}
  }).catch(console.error)

</script>
</body>
</html>