import { SITE, LANGS, UI } from "@/lib/config";

describe("Configuration", () => {
  describe("SITE Configuration", () => {
    it("should have required site properties", () => {
      expect(SITE.brand).toBe("Mawidi");
      expect(SITE.domain).toBe("mawidi.com");
      expect(SITE.defaultLang).toBe("ar");
    });

    it("should have valid contact information", () => {
      expect(SITE.contact.email).toMatch(/^[^\s@]+@[^\s@]+\.[^\s@]+$/);
      expect(SITE.contact.phone).toBeTruthy();
      expect(SITE.contact.whatsapp).toBeTruthy();
    });

    it("should have revalidate seconds configured", () => {
      expect(SITE.revalidateSeconds).toBe(3600);
    });
  });

  describe("Languages", () => {
    it("should support Arabic and English", () => {
      expect(LANGS).toContain("ar");
      expect(LANGS).toContain("en");
      expect(LANGS).toHaveLength(2);
    });

    it("should have Arabic as default language", () => {
      expect(SITE.defaultLang).toBe("ar");
    });
  });

  describe("UI Translations", () => {
    it("should have translations for both languages", () => {
      expect(UI.ar).toBeDefined();
      expect(UI.en).toBeDefined();
    });

    it("should have required translation keys", () => {
      const requiredKeys = ["t", "dir", "localeName"];

      for (const lang of LANGS) {
        for (const key of requiredKeys) {
          expect(UI[lang]).toHaveProperty(key);
        }
      }
    });

    it("should have correct text direction", () => {
      expect(UI.ar.dir).toBe("rtl");
      expect(UI.en.dir).toBe("ltr");
    });

    it("should have locale names", () => {
      expect(UI.ar.localeName).toBe("العربية");
      expect(UI.en.localeName).toBe("English");
    });

    it("should have common UI strings", () => {
      const commonKeys = ["features", "pricing", "login", "signup"];

      for (const lang of LANGS) {
        for (const key of commonKeys) {
          expect(UI[lang].t).toHaveProperty(key);
        }
      }
    });

    it("should have core translation keys in both languages", () => {
      const coreKeys = ["home", "features", "pricing", "login", "signup"];
      const arKeys = Object.keys(UI.ar.t);
      const enKeys = Object.keys(UI.en.t);

      // Core keys should exist in both languages
      coreKeys.forEach((key) => {
        expect(arKeys).toContain(key);
        expect(enKeys).toContain(key);
      });
    });
  });

  describe("Type Safety", () => {
    it("should enforce Lang type", () => {
      const validLang: "ar" | "en" = "ar";
      expect(LANGS).toContain(validLang);
    });

    it("should provide proper UI types", () => {
      const arUI = UI.ar;
      expect(arUI.dir).toMatch(/^(rtl|ltr)$/);
    });
  });
});
