import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import Radio from '../src/components/Radio/Radio.vue'

describe('Radio', () => {
  it('renders disabled unselected radio with explicit disabled-off state class', () => {
    const wrapper = mount(Radio, {
      props: {
        modelValue: false,
        disabled: true,
      },
      slots: {
        default: 'Option',
      },
    })

    expect(wrapper.find('.radio-circle--disabled-off').exists()).toBe(true)
    expect(wrapper.find('.radio-circle--disabled-selected').exists()).toBe(false)
  })

  it('renders disabled selected radio with explicit disabled-selected state class', () => {
    const wrapper = mount(Radio, {
      props: {
        modelValue: true,
        disabled: true,
      },
      slots: {
        default: 'Option',
      },
    })

    expect(wrapper.find('.radio-circle--disabled-selected').exists()).toBe(true)
    expect(wrapper.find('.radio-circle--disabled-off').exists()).toBe(false)
    expect(wrapper.find('.radio-dot').exists()).toBe(true)
  })

  it('exposes radio role and reflects aria-checked state', () => {
    const off = mount(Radio, { props: { modelValue: false } })
    const label = off.find('label')
    expect(label.attributes('role')).toBe('radio')
    expect(label.attributes('tabindex')).toBe('0')
    expect(label.attributes('aria-checked')).toBe('false')

    const on = mount(Radio, { props: { modelValue: true } })
    expect(on.find('label').attributes('aria-checked')).toBe('true')
  })

  it('selects via keyboard Space and Enter (emits true)', async () => {
    const wrapper = mount(Radio, { props: { modelValue: false } })
    await wrapper.find('label').trigger('keydown', { key: ' ' })
    expect(wrapper.emitted('update:modelValue')![0]).toEqual([true])
    await wrapper.find('label').trigger('keydown', { key: 'Enter' })
    expect(wrapper.emitted('update:modelValue')![1]).toEqual([true])
  })

  it('is not keyboard-focusable or selectable when disabled', async () => {
    const wrapper = mount(Radio, { props: { disabled: true, modelValue: false } })
    expect(wrapper.find('label').attributes('tabindex')).toBe('-1')
    expect(wrapper.find('label').attributes('aria-disabled')).toBe('true')
    await wrapper.find('label').trigger('keydown', { key: ' ' })
    expect(wrapper.emitted('update:modelValue')).toBeFalsy()
  })
})
