<script>
  let { step, totalSteps = 3, onback, onnext, saving = false, saveLabel = 'Save changes', saveError = '' } = $props();
</script>

<header class="topbar">
  <div class="topbar-left">
    <button class="ghost-btn" onclick={onback}>
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M19 12H5M12 5l-7 7 7 7"/></svg>
      {step === 1 ? 'Back' : 'Previous'}
    </button>
  </div>

  <div class="steps">
    {#each Array(totalSteps) as _, i}
      <div class="step-dot" class:active={step === i + 1} class:done={step > i + 1}></div>
    {/each}
  </div>

  <div class="topbar-right">
    <button class="save-btn" onclick={onnext} disabled={saving}>
      {#if saving}
        Saving…
      {:else if step < totalSteps}
        Next
      {:else}
        {saveLabel}
      {/if}
    </button>
    {#if saveError}<span class="save-err">{saveError}</span>{/if}
  </div>
</header>

<style>
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 52px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
  }
  .topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    min-width: 110px;
  }
  .topbar-right { justify-content: flex-end; }

  .steps {
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
  }
  .step-dot.active { background: var(--accent); transform: scale(1.25); }
  .step-dot.done   { background: var(--accent); opacity: 0.35; }

  .ghost-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--sans);
    font-size: 15px;
    font-weight: 400;
    color: var(--text);
    background: none;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }
  .ghost-btn:hover { background: var(--bg-subtle); border-color: var(--border); color: var(--text-h); }

  .save-btn {
    font-family: var(--sans);
    font-size: 15px;
    font-weight: 400;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 8px 18px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
  }
  .save-btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
  .save-btn:disabled { opacity: 0.6; cursor: not-allowed; }

  .save-err { font-size: 12px; color: #dc2626; white-space: nowrap; }
</style>
