import { describe, expect, test } from 'vitest'
import { getCursorDefault, getTooltipDefault } from './helpers'
import type { Tooltip } from './types'

describe('helpers', () => {
  describe('getCursorDefault', () => {
    test('returns "grab" when not dragging and not hovering', () => {
      const cursor = getCursorDefault({
        isDragging: false,
        isHovering: false,
      })
      expect(cursor).toBe('grab')
    })

    test('returns "pointer" when hovering but not dragging', () => {
      const cursor = getCursorDefault({
        isDragging: false,
        isHovering: true,
      })
      expect(cursor).toBe('pointer')
    })

    test('returns "grabbing" when dragging and not hovering', () => {
      const cursor = getCursorDefault({
        isDragging: true,
        isHovering: false,
      })
      expect(cursor).toBe('grabbing')
    })

    test('returns "grabbing" when dragging and hovering', () => {
      const cursor = getCursorDefault({
        isDragging: true,
        isHovering: true,
      })
      expect(cursor).toBe('grabbing')
    })
  })

  describe('getTooltipDefault', () => {
    test('returns null when html is not provided', () => {
      const info = { html: '' } as Tooltip
      const tooltip = getTooltipDefault(info)
      expect(tooltip).toBeNull()
    })

    test('returns null when html is undefined', () => {
      const info = {} as Tooltip
      const tooltip = getTooltipDefault(info)
      expect(tooltip).toBeNull()
    })

    test('returns formatted tooltip when html is provided', () => {
      const info = { html: '<strong>Test Content</strong>' } as Tooltip
      const tooltip = getTooltipDefault(info)

      expect(tooltip).toBeDefined()
      expect(tooltip?.html).toBe(
        "<div class='map-tooltip__content'><strong>Test Content</strong></div>",
      )
      expect(tooltip?.style).toEqual({
        padding: '0',
        background: 'none',
      })
    })

    test('wraps simple text html', () => {
      const info = { html: 'Simple text' } as Tooltip
      const tooltip = getTooltipDefault(info)

      expect(tooltip?.html).toBe(
        "<div class='map-tooltip__content'>Simple text</div>",
      )
    })
  })
})
