import { describe, it, expect, beforeEach } from 'vitest'
import {
  shouldShowStep,
  clearChainProgress,
  tutorialEnabled,
  tutorialProgress,
  sessionSkipped,
} from '../controller'

describe('tutorial controller - shouldShowStep', () => {
  beforeEach(() => {
    tutorialEnabled.value = true
    tutorialProgress.value = {}
    sessionSkipped.value = false
  })

  it('returns true when tips are enabled, the step is unseen, and the session is not skipped', () => {
    expect(shouldShowStep('create-chore')).toBe(true)
  })

  it('returns false when tips are disabled for a normal step', () => {
    tutorialEnabled.value = false
    expect(shouldShowStep('create-penalty')).toBe(false)
  })

  it('returns true for a locally-cleared step even when tips are disabled', () => {
    tutorialEnabled.value = false
    clearChainProgress('create-reward')
    expect(shouldShowStep('create-reward')).toBe(true)
  })

  it('still blocks locally-cleared steps when the session has been skipped', () => {
    tutorialEnabled.value = false
    sessionSkipped.value = true
    clearChainProgress('create-kindness')
    expect(shouldShowStep('create-kindness')).toBe(false)
  })

  it('returns false when the step has already been seen', () => {
    tutorialProgress.value = { 'notification-click': true }
    expect(shouldShowStep('notification-click')).toBe(false)
  })

  it('ignores the enabled flag when ignoreEnabled is true', () => {
    tutorialEnabled.value = false
    expect(shouldShowStep('status-pending', true)).toBe(true)
  })
})
