<!-- #region ReviewWorkspaceRightRail [C:3] [TYPE Component] [SEMANTICS dataset-review, right-rail, preview, launch, exports, blockers] -->
<!-- @ingroup Routes -->
<!-- @BRIEF Right rail for dataset review workspace: next action, blockers, health counts, exports, SQL preview, launch panel. -->
<!-- @LAYER UI -->
<script lang="ts">
  import { t } from "$lib/i18n/index.svelte.js";
  import CompiledSQLPreview from "$lib/components/dataset-review/CompiledSQLPreview.svelte";
  import LaunchConfirmationPanel from "$lib/components/dataset-review/LaunchConfirmationPanel.svelte";

  let {
    session,
    getRecommendedActionLabel,
    workspaceLaunchBlockers,
    blockingCount,
    warningCount,
    infoCount,
    launchDisabled,
    exportDisabled,
    exportMessage,
    onExportArtifact,
    latestPreview,
    previewUiState,
    sessionVersion,
    onPreviewUpdated,
    onSectionJump,
    executionMappings,
    latestRunContext,
    launchResult,
    onLaunchUpdated,
  } = $props();
</script>

<div class="space-y-5 xl:sticky xl:top-6">
  <section id="next-action" class="rounded-3xl border border-primary-ring bg-primary-light p-5 shadow-sm">
    <p class="text-xs font-semibold uppercase tracking-wide text-primary">
      {$t.dataset_review?.workspace?.next_action_card_eyebrow}
    </p>
    <h2 class="mt-1 text-lg font-semibold text-text">
      {getRecommendedActionLabel(session.recommended_action)}
    </h2>
    <p class="mt-2 text-sm text-text">
      {$t.dataset_review?.workspace?.execution_rail_body || "The right rail stays dedicated to preview, blockers, exports, and launch."}
    </p>

    {#if workspaceLaunchBlockers.length > 0}
      <div class="mt-4 rounded-2xl border border-warning bg-surface-card px-3 py-3">
        <div class="text-[11px] font-semibold uppercase tracking-wide text-warning">
          {$t.dataset_review?.workspace?.launch_blockers_title || "Launch blockers snapshot"}
        </div>
        <ul class="mt-2 space-y-2 text-xs text-amber-900">
          {#each workspaceLaunchBlockers as blocker}
            <li class="rounded-xl bg-warning-light px-3 py-2">{blocker}</li>
          {/each}
        </ul>
      </div>
    {/if}
  </section>

  <section class="rounded-3xl border border-border bg-surface-card p-5 shadow-sm">
    <h2 class="text-lg font-semibold text-text">
      {$t.dataset_review?.workspace?.health_title}
    </h2>
    <div class="mt-4 grid gap-3">
      <div class="rounded-2xl border border-destructive-ring bg-destructive-light p-3">
        <div class="text-xs uppercase tracking-wide text-destructive">
          {$t.dataset_review?.findings?.blocking_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-destructive">{blockingCount}</div>
      </div>
      <div class="rounded-2xl border border-warning bg-warning-light p-3">
        <div class="text-xs uppercase tracking-wide text-warning">
          {$t.dataset_review?.findings?.warning_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-warning">{warningCount}</div>
      </div>
      <div class="rounded-2xl border border-border bg-surface-page p-3">
        <div class="text-xs uppercase tracking-wide text-text-muted">
          {$t.dataset_review?.findings?.informational_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-text">{infoCount}</div>
      </div>
    </div>
  </section>

  <section class="rounded-3xl border border-border bg-surface-card p-5 shadow-sm">
    <h2 class="text-lg font-semibold text-text">
      {$t.dataset_review?.workspace?.exports_title}
    </h2>
    <div class="mt-4 grid gap-2">
      <button
        type="button"
        class="inline-flex items-center justify-center rounded-xl border border-border-strong px-4 py-2 text-sm font-medium text-text transition hover:bg-surface-page disabled:cursor-not-allowed disabled:opacity-50"
        onclick={() => onExportArtifact("documentation", "json")}
        disabled={exportDisabled}
      >
        {$t.dataset_review?.workspace?.export_documentation_json}
      </button>
      <button
        type="button"
        class="inline-flex items-center justify-center rounded-xl border border-border-strong px-4 py-2 text-sm font-medium text-text transition hover:bg-surface-page disabled:cursor-not-allowed disabled:opacity-50"
        onclick={() => onExportArtifact("documentation", "markdown")}
        disabled={exportDisabled}
      >
        {$t.dataset_review?.workspace?.export_documentation_markdown}
      </button>
      <button
        type="button"
        class="inline-flex items-center justify-center rounded-xl border border-border-strong px-4 py-2 text-sm font-medium text-text transition hover:bg-surface-page disabled:cursor-not-allowed disabled:opacity-50"
        onclick={() => onExportArtifact("validation", "json")}
        disabled={exportDisabled}
      >
        {$t.dataset_review?.workspace?.export_validation_json}
      </button>
      <button
        type="button"
        class="inline-flex items-center justify-center rounded-xl border border-border-strong px-4 py-2 text-sm font-medium text-text transition hover:bg-surface-page disabled:cursor-not-allowed disabled:opacity-50"
        onclick={() => onExportArtifact("validation", "markdown")}
        disabled={exportDisabled}
      >
        {$t.dataset_review?.workspace?.export_validation_markdown}
      </button>
    </div>
    {#if exportMessage}
      <div class="mt-3 rounded-xl border border-border bg-surface-page px-3 py-3 text-xs text-text-muted">
        {exportMessage}
      </div>
    {/if}
  </section>

  <div id="sql-preview">
    <CompiledSQLPreview
      sessionId={session.session_id}
      {sessionVersion}
      preview={latestPreview}
      previewState={previewUiState}
      disabled={launchDisabled}
      onupdated={onPreviewUpdated}
      onjump={onSectionJump}
    />
  </div>

  <div id="launch">
    <LaunchConfirmationPanel
      sessionId={session.session_id}
      {sessionVersion}
      {session}
      findings={session.findings || []}
      mappings={executionMappings}
      preview={latestPreview}
      previewState={previewUiState}
      latestRunContext={launchResult?.run_context || latestRunContext}
      disabled={launchDisabled}
      onupdated={onLaunchUpdated}
      onjump={onSectionJump}
    />
  </div>
</div>
<!-- #endregion ReviewWorkspaceRightRail -->
