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

describe("TimezonePicker (props-based composition)", () => {
  describe("rendering", () => {
    it("renders the label and combobox input", () => {
      const wrapper = mount(TimezonePicker, { props: { label: "Timezone" } })
      expect(wrapper.text()).toContain("Timezone")
      expect(wrapper.find("input").exists()).toBe(true)
    })

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

    it("uses a custom placeholder when provided", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", placeholder: "Choose tz…" },
      })
      expect(wrapper.html()).toContain("Choose tz…")
    })

    it("marks the label as required", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", required: true },
      })
      expect(wrapper.html()).toContain("after:content-['*']")
    })
  })

  describe("value binding", () => {
    it("accepts modelValue as initial selection", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", modelValue: "Europe/London" },
      })
      expect(wrapper.exists()).toBe(true)
    })
  })

  describe("state matrix", () => {
    it("flags readonly via data-attribute", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", readonly: true },
      })
      expect(wrapper.html()).toContain("data-readonly")
    })

    it("renders help text", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", helpText: "IANA tz identifier" },
      })
      expect(wrapper.text()).toContain("IANA tz identifier")
    })
  })

  describe("errors", () => {
    it("renders errors from props", () => {
      const wrapper = mount(TimezonePicker, {
        props: { label: "Timezone", errors: ["Required"] },
      })
      expect(wrapper.text()).toContain("Required")
    })
  })

  it("works without any props at all", () => {
    const wrapper = mount(TimezonePicker)
    expect(wrapper.find("input").exists()).toBe(true)
  })
})
