import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import StandardStatePanel, { type StandardUiState } from '../StandardStatePanel.vue'

const states: readonly StandardUiState[] = [
  'READY', 'LOADING', 'EMPTY', 'WARN', 'ERROR', 'EXPIRED', 'UNAUTHORIZED', 'FORBIDDEN',
  'READONLY', 'DIRTY', 'CONFLICT', 'PROCESSING', 'PARTIAL'
]

describe('StandardStatePanel canonical state contract', () => {
  it.each(states)('renders the %s state without inventing a fallback state', state => {
    const wrapper = mount(StandardStatePanel, { props: { state } })
    if (state === 'READY') expect(wrapper.find('[data-state]').exists()).toBe(false)
    else expect(wrapper.find(`[data-state="${state}"]`).exists()).toBe(true)
  })

  it('does not expose retry for non-retryable states unless explicitly enabled', () => {
    const wrapper = mount(StandardStatePanel, { props: { state: 'FORBIDDEN' } })
    expect(wrapper.find('[data-state="FORBIDDEN"] button').exists()).toBe(false)
  })

  it('emits retry only when the caller explicitly enables it', async () => {
    const wrapper = mount(StandardStatePanel, { props: { state: 'ERROR', retryable: true } })
    await wrapper.get('button').trigger('click')
    expect(wrapper.emitted('retry')).toHaveLength(1)
  })
})
