<script lang="ts">
  import ProjectWorkbench from '../features/workbench/ProjectWorkbench.svelte';
  import ServerLogin from '../features/auth/ServerLogin.svelte';

  let apiBase = localStorage.getItem('apiBase') ?? 'http://localhost:8080';
  let currentUser: { account: string } | null = null;

  function handleLogin(detail: { apiBase: string; account: string }) {
    apiBase = detail.apiBase;
    localStorage.setItem('apiBase', apiBase);
    currentUser = { account: detail.account };
  }
</script>

{#if currentUser}
  <ProjectWorkbench {currentUser} />
{:else}
  <ServerLogin {apiBase} onLogin={handleLogin} />
{/if}
