// @vitest-environment jsdom

import { fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import type { PRMeta } from "../model/pr-meta";
import { PreviewStepSection } from "./preview-step";

const baseMeta: PRMeta = {
  branchName: "branch",
  commitMessage: "commit",
  prTitle: "title",
  prBody: "body",
  scope: "scope",
  shortTag: "short",
};

describe("PreviewStepSection", () => {
  it("renders image-mode toggle and forwards actions", () => {
    const onBack = vi.fn();
    const onConfirm = vi.fn();

    render(
      <PreviewStepSection
        mode="image"
        sourceRegionId=""
        prMeta={baseMeta}
        targetTag="tag"
        selectedRegions={[]}
        diffs={[]}
        configSyncDiffs={[]}
        configSyncFailures={[]}
        enableImageTagCheck={true}
        onEnableImageTagCheckChange={() => {}}
        bumping={false}
        onBack={onBack}
        onConfirm={onConfirm}
      />
    );

    expect(screen.getByText("Enable image tag checks before execution")).toBeInTheDocument();

    fireEvent.click(screen.getByRole("button", { name: "Back" }));
    expect(onBack).toHaveBeenCalledTimes(1);

    fireEvent.click(screen.getByRole("button", { name: "Confirm & Create PR" }));
    expect(onConfirm).toHaveBeenCalledTimes(1);
  });
});
