import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";

const RESPONSIVE_PREFIX_PATTERN = /\b(?:max-sm|sm:|md:|lg:|xl:|2xl:)/;

const HOOK_DRIVEN_FILES = [
  "src/app/page.tsx",
  "src/app/demo/combined-date-picker/page.tsx",
  "src/components/ai-toolbar.tsx",
  "src/components/event-dialog.tsx",
  "src/components/settings-panel.tsx",
  "src/components/ui/calendar.tsx",
  "src/components/ui/date-picker.tsx",
  "src/components/ui/dialog.tsx",
  "src/components/ui/drawer.tsx",
  "src/components/ui/input-group.tsx",
  "src/components/ui/textarea.tsx",
  "src/lib/ui-shell-contract.ts",
];

const DIRECT_HOOK_FILES = [
  "src/app/page.tsx",
  "src/app/demo/combined-date-picker/page.tsx",
  "src/components/ai-toolbar.tsx",
  "src/components/event-dialog.tsx",
  "src/components/settings-panel.tsx",
  "src/components/ui/calendar.tsx",
  "src/components/ui/date-picker.tsx",
  "src/components/ui/dialog.tsx",
  "src/components/ui/input-group.tsx",
  "src/components/ui/textarea.tsx",
];

const BOOLEAN_HELPER_FILES = ["src/lib/ui-shell-contract.ts"];

describe("mobile hook adoption", () => {
  test("responsive source files stop using Tailwind breakpoint prefixes for mobile behavior", () => {
    for (const filePath of HOOK_DRIVEN_FILES) {
      const source = readFileSync(filePath, "utf8");
      expect(source).not.toMatch(RESPONSIVE_PREFIX_PATTERN);
    }
  });

  test("mobile-responsive component files explicitly depend on the shared useIsMobile hook", () => {
    for (const filePath of DIRECT_HOOK_FILES) {
      const source = readFileSync(filePath, "utf8");
      expect(source).toContain("useIsMobile");
    }
  });

  test("utility files accept isMobile booleans instead of embedding breakpoint strings", () => {
    for (const filePath of BOOLEAN_HELPER_FILES) {
      const source = readFileSync(filePath, "utf8");
      expect(source).toContain("isMobile");
    }
  });
});
