<script lang="ts">
  import Ellipsis from './Ellipsis.svelte';
  import Ripple from './Ripple.svelte';
  import Grid from './Grid.svelte';
  import Popup from '$lib/Layout/Popup.svelte';
  import type { Snippet } from 'svelte';

  interface Props {
    message?: string | undefined;
    loader?: 'ellipsis' | 'ripple' | 'grid';
    colour?: string;
    slot?: boolean;
    withReload?: boolean;
    fullscreen?: boolean;
    children?: Snippet;
  }

  let {
    message = undefined,
    loader = 'ellipsis',
    colour = 'var(--fg)',
    slot = false,
    withReload = false,
    fullscreen = true,
    children
  }: Props = $props();
</script>

<Popup {fullscreen} locked>
  <div class="message">
    {#if loader === 'ellipsis'}
      <Ellipsis {colour} />
    {:else if loader === 'ripple'}
      <Ripple {colour} />
    {:else if loader === 'grid'}
      <Grid {colour} />
    {/if}

    {#if message}
      <br />

      {message}
    {:else if slot}
      <br />

      {@render children?.()}

      {#if withReload}
        Please <a href={'#'} onclick={() => location.reload()}>try again</a> later.
      {/if}
    {/if}
  </div>
</Popup>

<style>
  .message {
    text-align: center;
  }
</style>
