import { globSync, readFileSync } from "node:fs";
import { join } from "node:path";

const projectRoot = process.cwd();
const migrationTestPath = "src/test/tailwind-migration.test.ts";
const runtimeSource = globSync("src/**/*.{ts,tsx}", { cwd: projectRoot })
  .filter((filePath) => filePath !== migrationTestPath)
  .map((filePath) => readFileSync(join(projectRoot, filePath), "utf8"))
  .join("\n");

describe("Tailwind v4 migration", () => {
  it("does not reintroduce v3-only utility syntax", () => {
    expect(runtimeSource).not.toMatch(/(?:max-h|origin)-\[--/);
    expect(runtimeSource).not.toMatch(/\bshadow-sm\b/);
    expect(runtimeSource).not.toMatch(/\boutline-none\b/);
    expect(runtimeSource).not.toMatch(
      /(?:^|\s)!(?:m-|left-|right-|fixed\b|z-|w-|border-|ring-)|:!(?:border-|ring-)/m
    );
  });

  it("preserves the Tailwind v3 default border color", () => {
    const styles = readFileSync(join(projectRoot, "src/styles.css"), "utf8");

    expect(styles).toMatch(
      /@layer base\s*{[\s\S]*?::file-selector-button\s*{[\s\S]*?border-color:\s*var\(--color-gray-200, currentColor\)/
    );
  });
});
