<script>
  import LogOut from '$lib/components/LogOut.svelte';
  import Invites from '$lib/components/Invites.svelte';
  import NotificationSettings from '$lib/components/NotificationSettings.svelte';
  import ChangePassword from '$lib/components/ChangePassword.svelte';

  import { goto } from '$app/navigation';
  import * as api from '$lib/apiServer.js';

  let invites = $state([]);

  async function logOut() {
    const response = await api.logOut();
    if (200 <= response.status && response.status < 300) {
      await goto('/login');
    }
  }

  async function changePassword(currentPassword, newPassword) {
    await api.changePassword(currentPassword, newPassword);
  }

  async function createInvite() {
    let response = await api.createInvite();
    if (response.status === 200) {
      invites.push(response.data);
    }
  }
</script>

<ChangePassword {changePassword} />
<hr />
<Invites {invites} {createInvite} />
<hr />
<NotificationSettings />
<hr />
<LogOut {logOut} />
