<script lang="ts">
  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}
  <main class="workbench-placeholder" aria-label="Project workbench">
    <h1>SenlinAI Workbench</h1>
    <p>Signed in as {currentUser.account}</p>
  </main>
{:else}
  <ServerLogin {apiBase} onLogin={handleLogin} />
{/if}
