<!-- #region ReviewWorkspaceRightRail [C:3] [TYPE Component] [SEMANTICS dataset-review, right-rail, preview, launch, exports, blockers] -->
<!-- @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-blue-700">
      {$t.dataset_review?.workspace?.next_action_card_eyebrow}
    </p>
    <h2 class="mt-1 text-lg font-semibold text-slate-900">
      {getRecommendedActionLabel(session.recommended_action)}
    </h2>
    <p class="mt-2 text-sm text-slate-700">
      {$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-amber-200 bg-white px-3 py-3">
        <div class="text-[11px] font-semibold uppercase tracking-wide text-amber-700">
          {$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-amber-50 px-3 py-2">{blocker}</li>
          {/each}
        </ul>
      </div>
    {/if}
  </section>

  <section class="rounded-3xl border border-slate-200 bg-white p-5 shadow-sm">
    <h2 class="text-lg font-semibold text-slate-900">
      {$t.dataset_review?.workspace?.health_title}
    </h2>
    <div class="mt-4 grid gap-3">
      <div class="rounded-2xl border border-red-100 bg-destructive-light p-3">
        <div class="text-xs uppercase tracking-wide text-red-700">
          {$t.dataset_review?.findings?.blocking_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-red-800">{blockingCount}</div>
      </div>
      <div class="rounded-2xl border border-amber-100 bg-amber-50 p-3">
        <div class="text-xs uppercase tracking-wide text-amber-700">
          {$t.dataset_review?.findings?.warning_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-amber-800">{warningCount}</div>
      </div>
      <div class="rounded-2xl border border-slate-200 bg-slate-50 p-3">
        <div class="text-xs uppercase tracking-wide text-slate-500">
          {$t.dataset_review?.findings?.informational_title}
        </div>
        <div class="mt-1 text-xl font-semibold text-slate-800">{infoCount}</div>
      </div>
    </div>
  </section>

  <section class="rounded-3xl border border-slate-200 bg-white p-5 shadow-sm">
    <h2 class="text-lg font-semibold text-slate-900">
      {$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-slate-300 px-4 py-2 text-sm font-medium text-slate-700 transition hover:bg-slate-50 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-slate-300 px-4 py-2 text-sm font-medium text-slate-700 transition hover:bg-slate-50 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-slate-300 px-4 py-2 text-sm font-medium text-slate-700 transition hover:bg-slate-50 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-slate-300 px-4 py-2 text-sm font-medium text-slate-700 transition hover:bg-slate-50 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-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600">
        {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 -->
