import { render, screen } from "@testing-library/react";
import ChartSingle from "./ChartSingle";
import DefinitionCard from "./DefinitionCard";
import EquationFocus from "./EquationFocus";
import type { SlideRuntimeProps } from "../types/lecture";

function makeProps(
  props: SlideRuntimeProps["props"],
  latexString?: string,
  displayMode: SlideRuntimeProps["displayMode"] = "fullscreen"
): SlideRuntimeProps {
  return {
    lectureId: "presentation-1",
    slideId: "slide-1",
    glitchSlideId: "slide-1-a",
    displayMode,
    props,
    latexString,
    paused: false
  };
}

describe("template header support", () => {
  it("renders a header on EquationFocus", () => {
    render(
      <EquationFocus
        {...makeProps(
          {
            header: "Mean",
            title: "Definition",
            annotation: "Average value"
          },
          String.raw`\bar{x} = \frac{1}{N}\sum_{i=0}^{N} x_i`
        )}
      />
    );

    expect(screen.getByText("Mean")).toBeInTheDocument();
  });

  it("supports square rendering for EquationFocus", () => {
    const { container } = render(
      <EquationFocus
        {...makeProps(
          {
            header: "Mean",
            title: "Definition",
            annotation: "Average value"
          },
          String.raw`\bar{x} = \frac{1}{N}\sum_{i=0}^{N} x_i`,
          "square"
        )}
      />
    );

    expect(container.querySelector(".equation-focus--square")).toBeTruthy();
  });

  it("renders a header on ChartSingle", () => {
    render(
      <ChartSingle
        {...makeProps({
          header: "Comparison",
          title: "Growth",
          body: "One trend",
          points: [{ label: "A", value: 10 }]
        })}
      />
    );

    expect(screen.getByText("Comparison")).toBeInTheDocument();
  });

  it("renders a header on DefinitionCard", () => {
    render(
      <DefinitionCard
        {...makeProps({
          header: "Concept",
          term: "Mean",
          definition: "Average",
          example: "Add then divide"
        })}
      />
    );

    expect(screen.getByText("Concept")).toBeInTheDocument();
  });
});
