import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import StorageBrowser from '../StorageBrowser.vue'

const globalStubs = {
  BreadcrumbBar: true,
  SearchBar: true,
  SortControls: true,
  DropZone: true,
  UploadProgress: true,
  TopicBadge: true,
  AppIcon: true,
  EmptyState: true,
}

describe('UX-02: StorageBrowser shows skeleton rows during loading', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  })

  it('renders 5 skeleton rows when loading=true and lists empty', () => {
    const wrapper = mount(StorageBrowser, {
      props: { loading: true, folders: [], files: [] },
      global: { stubs: globalStubs },
    })
    const pulseEls = wrapper.findAll('.animate-pulse')
    expect(pulseEls.length).toBeGreaterThanOrEqual(5)
  })

  it('Loading… text is absent when loading=true', () => {
    const wrapper = mount(StorageBrowser, {
      props: { loading: true, folders: [], files: [] },
      global: { stubs: globalStubs },
    })
    expect(wrapper.text()).not.toContain('Loading…')
  })

  it('skeleton rows are NOT rendered when loading=false', () => {
    const wrapper = mount(StorageBrowser, {
      props: { loading: false, folders: [], files: [] },
      global: { stubs: globalStubs },
    })
    const pulseEls = wrapper.findAll('.animate-pulse')
    expect(pulseEls.length).toBe(0)
  })

  it('skeleton row grid matches grid-cols-[2rem_1fr_6rem_8rem_6rem]', () => {
    const wrapper = mount(StorageBrowser, {
      props: { loading: true, folders: [], files: [] },
      global: { stubs: globalStubs },
    })
    const skeletonGrids = wrapper.findAll('.grid-cols-\\[2rem_1fr_6rem_8rem_6rem\\]')
    expect(skeletonGrids.length).toBeGreaterThanOrEqual(1)
  })
})

describe('UX-13: StorageBrowser folder picker uses Teleport + getBoundingClientRect', () => {
  it.todo('folder picker dropdown is teleported to body (escapes overflow container)')
  it.todo('dropdown position reflects getBoundingClientRect of the trigger button')
  it.todo('window scroll while open recalculates position')
})
