<script lang="ts">
  interface Props {
    visible?: boolean;
    percent?: number;
    stage?: string;
    message?: string;
  }

  let { visible = false, percent = 0, stage = '', message = '' }: Props = $props();
</script>

{#if visible}
  <div class="overlay">
    <div class="progress-card">
      <div class="spinner-row">
        <div class="spinner"></div>
        <h3>{stage || 'Processing...'}</h3>
      </div>
      <div class="bar-track">
        <div class="bar-fill" style="width: {Math.max(percent, 2)}%"></div>
      </div>
      <p class="status-text">{percent}% — {message || 'Please wait...'}</p>
      <p class="hint-text">This may take several minutes for large files</p>
    </div>
  </div>
{/if}

<style>
  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
  }
  .progress-card {
    background: #16213e;
    padding: 2rem 2.5rem;
    border-radius: 12px;
    min-width: 420px;
    color: #e0e0e0;
    border: 1px solid #2a3a5e;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  }
  .spinner-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }
  .spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #2a3a5e;
    border-top-color: #e94560;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  h3 {
    margin: 0;
    text-transform: capitalize;
    font-size: 1.1rem;
  }
  .bar-track {
    height: 10px;
    background: #0f3460;
    border-radius: 5px;
    overflow: hidden;
  }
  .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #e94560, #ff6b81);
    transition: width 0.3s;
    border-radius: 5px;
  }
  .status-text {
    margin: 0.75rem 0 0;
    font-size: 0.9rem;
    color: #b0b0b0;
  }
  .hint-text {
    margin: 0.5rem 0 0;
    font-size: 0.75rem;
    color: #666;
  }
</style>
