import { describe, expect, it } from "vitest"
import { mount } from "@vue/test-utils"
import RadioBoolean from "./RadioBoolean.vue"

describe("RadioBoolean (props-based composition)", () => {
  it("mounts and renders the label via FieldFrame", () => {
    const wrapper = mount(RadioBoolean, { props: { label: "Agree?" } })
    expect(wrapper.text()).toContain("Agree?")
  })

  it("hides the visible label when hideLabel is true", () => {
    const wrapper = mount(RadioBoolean, {
      props: { label: "Hidden", hideLabel: true },
    })
    expect(wrapper.find("[data-testid='field-frame-label-sr']").exists()).toBe(
      true,
    )
    expect(wrapper.find("[data-testid='field-frame-label']").exists()).toBe(
      false,
    )
  })

  it("renders default Yes / No labels", () => {
    const wrapper = mount(RadioBoolean, { props: { label: "Agree?" } })
    expect(wrapper.text()).toContain("Yes")
    expect(wrapper.text()).toContain("No")
  })

  it("uses custom trueLabel / falseLabel", () => {
    const wrapper = mount(RadioBoolean, {
      props: { label: "X", trueLabel: "Of course", falseLabel: "Nope" },
    })
    expect(wrapper.text()).toContain("Of course")
    expect(wrapper.text()).toContain("Nope")
  })

  it("renders two radio items", () => {
    const wrapper = mount(RadioBoolean, { props: { label: "X" } })
    expect(wrapper.findAll("[role='radio']").length).toBe(2)
  })

  it("renders inline layout when inline=true", () => {
    const wrapper = mount(RadioBoolean, {
      props: { label: "X", inline: true },
    })
    const group = wrapper.find("[role='radiogroup']")
    expect(group.classes()).toContain("flex-row")
  })

  it("respects disabled / required", () => {
    const wrapper = mount(RadioBoolean, {
      props: { label: "X", disabled: true, required: true },
    })
    const radios = wrapper.findAll("[role='radio']")
    expect(radios[0]!.attributes("disabled")).toBeDefined()
  })

  it("renders helpText and errors", () => {
    const wrapper = mount(RadioBoolean, {
      props: { label: "X", helpText: "Hint", errors: ["Bad"] },
    })
    expect(wrapper.find("[data-testid='field-frame-help']").text()).toBe("Hint")
    expect(wrapper.find("[data-testid='field-frame-errors']").text()).toContain(
      "Bad",
    )
  })

  it("works without any props at all", () => {
    const wrapper = mount(RadioBoolean)
    expect(wrapper.findAll("[role='radio']").length).toBe(2)
  })
})
