import { describe, expect, it } from "vitest";
import {
  isPbelFlyerPage,
  resolveEffectiveSectionWidth,
  sectionWidthForBlock,
} from "./sectionWidthForBlock";

describe("sectionWidthForBlock", () => {
  it("marks course body shells as full", () => {
    expect(sectionWidthForBlock({ componentSlug: "why-this-course-matters" })).toBe("full");
    expect(sectionWidthForBlock({ componentSlug: "how-connects" })).toBe("full");
  });

  it("marks PBEL narrow shells as full", () => {
    expect(sectionWidthForBlock({ componentSlug: "what-is-pbel" })).toBe("full");
    expect(sectionWidthForBlock({ componentSlug: "pbel-cycle" })).toBe("full");
  });

  it("marks Closing Vision (Landing) as full without treating it as footer", () => {
    expect(sectionWidthForBlock({ componentSlug: "closing-vision" })).toBe("full");
    expect(sectionWidthForBlock({ componentSlug: "footer" })).toBe("full");
    expect(sectionWidthForBlock({ componentSlug: "pbel-guide-footer" })).toBe("full");
  });

  it("marks unknown blocks as container", () => {
    expect(sectionWidthForBlock({ componentSlug: "unknown-widget" })).toBe("container");
  });
});

describe("resolveEffectiveSectionWidth", () => {
  it("promotes single self-contained block sections to full at render time", () => {
    expect(
      resolveEffectiveSectionWidth({
        width: "container",
        layout: "100",
        blocks: [{ componentSlug: "why-this-course-matters", componentId: 1 }],
      }),
    ).toBe("full");
  });

  it("keeps multi-column sections as stored", () => {
    expect(
      resolveEffectiveSectionWidth({
        width: "container",
        layout: "50-50",
        blocks: [{ componentSlug: "why-this-course-matters", componentId: 1 }, null],
      }),
    ).toBe("container");
  });
});

describe("isPbelFlyerPage", () => {
  it("returns true when every block is a flyer fragment", () => {
    expect(
      isPbelFlyerPage([
        { blocks: [{ componentSlug: "orion-school-header", componentId: 1 }] },
        { blocks: [{ componentSlug: "what-is-pbel", componentId: 2 }] },
      ]),
    ).toBe(true);
  });

  it("returns false when a non-flyer block is present", () => {
    expect(
      isPbelFlyerPage([
        { blocks: [{ componentSlug: "orion-school-header", componentId: 1 }] },
        { blocks: [{ componentSlug: "hero", componentId: 2 }] },
      ]),
    ).toBe(false);
  });

  it("allows PBEL Guide Footer on flyer pages", () => {
    expect(
      isPbelFlyerPage([
        { blocks: [{ componentSlug: "orion-school-header", componentId: 1 }] },
        { blocks: [{ componentSlug: "pbel-guide-footer", componentId: 2 }] },
      ]),
    ).toBe(true);
  });
});
