import { describe, test, expect } from "vitest"
import { recolorSvg, stripSvgWrapper } from "../src/recolor"

const SAMPLE = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 19v3" /></svg>`

describe("recolor — recolorSvg", () => {
  test("replaces stroke=currentColor with accent", () => {
    const out = recolorSvg(SAMPLE, "#ccff00")
    expect(out).toContain('stroke="#ccff00"')
    expect(out).not.toContain('stroke="currentColor"')
  })

  test("replaces fill (non-none) with target color", () => {
    const svg = `<svg fill="#000000" stroke="currentColor"><path fill="#ff0000" /></svg>`
    const out = recolorSvg(svg, "#ccff00")
    expect(out).toContain('fill="#ccff00"')
    expect(out).not.toContain('fill="#000000"')
    expect(out).not.toContain('fill="#ff0000"')
  })

  test("preserves fill=none", () => {
    const svg = `<svg fill="none" stroke="currentColor"><path fill="none" /></svg>`
    const out = recolorSvg(svg, "#ccff00")
    expect(out).toContain('fill="none"')
  })

  test("none color returns unchanged", () => {
    expect(recolorSvg(SAMPLE, "none")).toBe(SAMPLE)
  })

  test("replaces stroke with fg color", () => {
    const out = recolorSvg(SAMPLE, "#ededed")
    expect(out).toContain('stroke="#ededed"')
  })

  test("replaces stroke with muted color", () => {
    const out = recolorSvg(SAMPLE, "#a1a1aa")
    expect(out).toContain('stroke="#a1a1aa"')
  })
})

describe("recolor — stripSvgWrapper", () => {
  test("extracts inner content", () => {
    const inner = stripSvgWrapper(SAMPLE)
    expect(inner).toContain("<path")
    expect(inner).not.toContain("<svg")
  })
})