import * as React from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { PaginationControls } from '../src/data-display/pagination-controls'
import { emptyStateCatalog } from '../../../apps/zync-app/src/lib/empty-state-catalog'
import { errorPagePresets } from '../../../apps/zync-app/src/components/error-page'

describe('error and empty state spec contracts', () => {
  it('uses the spec route for the support empty state action', () => {
    expect(emptyStateCatalog['support.empty']).toMatchObject({
      heading: 'No support tickets have come in yet.',
      action: {
        label: 'Create a ticket',
        href: '/support/new',
      },
    })
  })

  it('uses the spec copy for module-disabled error pages', () => {
    expect(errorPagePresets.moduleDisabledAdmin()).toMatchObject({
      heading: 'This module is turned off.',
      description: 'You can turn it on in your workspace settings.',
      cta: { label: 'Go to Settings', href: '/settings/modules' },
    })

    expect(errorPagePresets.moduleDisabledStaff()).toMatchObject({
      heading: 'This module is turned off.',
      description: 'Ask your workspace admin to enable it.',
    })
  })

  it('renders desktop pagination with the spec labels and controls', () => {
    const onPageChange = vi.fn()
    const onPerPageChange = vi.fn()
    const markup = renderToStaticMarkup(
      <PaginationControls
        currentPage={2}
        pagination={{
          total: 143,
          nextCursor: 'next-cursor',
          prevCursor: 'prev-cursor',
          perPage: 20,
          onPageChange,
          onPerPageChange,
        }}
      />,
    )

    expect(markup).toContain('Showing 21–40 of 143')
    expect(markup).toContain('Prev')
    expect(markup).toContain('Next')
    expect(markup).toContain('Per page')
    expect(markup).not.toContain('No results')
  })
})
