/**
 * scaffold-theme / generate.test.ts (2026-05-27)
 *
 * Covers Fix #5: Shoelace imports are now conditional on the `useShoelace`
 * flag. Default OFF so projects without `@shoelace-style/shoelace` in their
 * package.json don't fail Vite resolution at boot.
 */
import { describe, it, expect } from 'vitest'
import { generate } from '../generate.js'
import type { ScaffoldThemeInput } from '../types.js'

function fixture(overrides: Partial<ScaffoldThemeInput> = {}): ScaffoldThemeInput {
  return {
    projectPath: '/test',
    appCode: 'TestV2',
    force: false,
    useShoelace: false,
    ...overrides,
  } as ScaffoldThemeInput
}

describe('scaffold-theme / generate — Fix #5 (Shoelace imports conditional)', () => {
  it('omits Shoelace @import lines by default (useShoelace not set)', () => {
    const files = generate(fixture())
    const css = files.find(f => f.path.endsWith('index.css'))!
    expect(css.content).not.toMatch(/@shoelace-style\/shoelace/)
    expect(css.content).not.toMatch(/themes\/light\.css/)
    expect(css.content).not.toMatch(/themes\/dark\.css/)
  })

  it('emits Shoelace @import lines when useShoelace: true', () => {
    const files = generate(fixture({ useShoelace: true }))
    const css = files.find(f => f.path.endsWith('index.css'))!
    expect(css.content).toMatch(/@import '@shoelace-style\/shoelace\/dist\/themes\/light\.css';/)
    expect(css.content).toMatch(/@import '@shoelace-style\/shoelace\/dist\/themes\/dark\.css' \(prefers-color-scheme: dark\);/)
  })

  it('always emits Tailwind + SmartStack theme imports regardless of useShoelace', () => {
    for (const useShoelace of [true, false]) {
      const css = generate(fixture({ useShoelace })).find(f => f.path.endsWith('index.css'))!
      expect(css.content, `useShoelace=${useShoelace}`).toMatch(/@import 'tailwindcss';/)
      expect(css.content, `useShoelace=${useShoelace}`).toMatch(/@import '@atlashub\/smartstack\/theme\.css';/)
    }
  })

  it('emits the accent ramp from the PRD theme slice when provided', () => {
    const files = generate(fixture({
      prdSlice: { theme: { accent: '#ff0000' } },
    }))
    const css = files.find(f => f.path.endsWith('index.css'))!
    expect(css.content).toMatch(/--color-accent-500: #ff0000;/)
  })
})
