<script>
  /** @type {{ vision: ReturnType<import('../lib/stores/vision.svelte.js').createVisionStore> }} */
  let { vision } = $props();
</script>

{#if vision.loadingModels.length > 0}
  <div class="loader-overlay">
    <div class="loader-card">
      {#each vision.loadingModels as model}
        <div class="model-entry">
          <h3>Loading Model</h3>
          <p class="subtitle">{model.name}</p>
          {#if model.progress !== null}
            <div class="progress-bar">
              <div class="progress-fill" style="width: {model.progress}%"></div>
            </div>
            <span class="percent">{model.progress}%</span>
          {:else}
            <div class="progress-bar">
              <div class="progress-fill indeterminate"></div>
            </div>
            <span class="percent">Preparing...</span>
          {/if}
        </div>
      {/each}
    </div>
  </div>
{/if}

<style>
  .loader-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
  }

  .loader-card {
    background: rgba(30, 30, 30, 0.95);
    border-radius: 16px;
    padding: 24px 32px;
    text-align: center;
    color: #fff;
    max-width: 320px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .model-entry {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
  }

  .subtitle {
    margin: 0 0 8px;
    font-size: 0.75rem;
    color: #999;
  }

  .progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
  }

  .progress-fill {
    height: 100%;
    background: #3b82f6;
    border-radius: 3px;
    transition: width 0.3s ease;
  }

  .progress-fill.indeterminate {
    width: 30%;
    animation: slide 1.5s ease-in-out infinite;
  }

  .percent {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: #aaa;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
  }
</style>
