// CAABA content — polished launch copy
const NAV = [
  { id: "home", label: "Home", path: "/" },
  { id: "about", label: "About", path: "/about" },
  { id: "leadership", label: "Leadership", path: "/leadership" },
  { id: "projects", label: "Projects", path: "/projects" },
  { id: "news", label: "News", path: "/news" },
  { id: "membership", label: "Membership", path: "/membership" },
  { id: "donate", label: "Donate", path: "/donate" },
  { id: "contact", label: "Contact", path: "/contact" },
];

const PILLARS = [
  { icon: "development", title: "Professional Development",
    body: "Support the advancement of our members within the United States legal profession through substantive programming, continuing education, and practice-focused resources." },
  { icon: "network", title: "Networking",
    body: "A structured platform for knowledge sharing, practice-group convenings, and sustained professional collaboration across firms, agencies, and in-house teams." },
  { icon: "mentor", title: "Mentorship",
    body: "Intergenerational exchange that pairs experienced attorneys with law students, LLM graduates, and early-career professionals navigating the U.S. legal system." },
  { icon: "referral", title: "Trusted Referrals",
    body: "An ethically grounded network that facilitates qualified referrals and dependable collaboration across practice areas and jurisdictions." },
  { icon: "visibility", title: "Visibility & Positioning",
    body: "Elevate the standing of our members within the broader legal, business, and international communities they serve." },
  { icon: "global", title: "Cross-Border Opportunities",
    body: "Create pathways for members to engage in meaningful international and cross-border legal matters and institutional work." },
  { icon: "bridge", title: "U.S.–Central Asia Legal Bridge",
    body: "Strengthen enduring professional ties between the legal communities of the United States and Central Asia through dialogue and partnership." },
  { icon: "future", title: "Support for Future Lawyers",
    body: "Mentor and equip foreign-trained lawyers, LLM students, and early-career professionals entering the U.S. legal ecosystem." },
];

const LEADERSHIP = {
  officers: [
    { name: "Abzal Kabyl", title: "President",
      linkedin: "https://www.linkedin.com/in/abzal-kabyl-1153b4206",
      bio: "Leads the strategic direction of the Association and its commitment to professional development, cross-border legal dialogue, and community stewardship." },
    { name: "Ruslan Tashkenbay", title: "Vice President",
      linkedin: "https://www.linkedin.com/in/ruslan-tashkenbay-462a34ab",
      bio: "Partners with the President on organizational priorities, long-term planning, and the continued development of CAABA's professional programming." },
    { name: "Anar Moldabekova", title: "Corporate Secretary",
      linkedin: "https://www.linkedin.com/in/anar-moldabekova-78018691",
      bio: "Oversees the governance, records, and institutional integrity of the Association's corporate operations." },
  ],
  vps: [
    { name: "Aidos Amirgaliyev", title: "Vice President, Education", short: "Education",
      linkedin: "https://www.linkedin.com/in/aidos-amirgaliyev-esq-6ba760255/",
      bio: "Directs the Association's programs in continuing legal education, professional development, and substantive practice initiatives." },
    { name: "Aizat Imanbek", title: "Vice President, PR & Relationships", short: "PR & Relationships",
      linkedin: "https://www.linkedin.com/in/aizat-imambek-572368127/",
      bio: "Cultivates CAABA's external relationships with bar associations, institutional partners, and the broader legal community." },
    { name: "Arzhan Moldabayev", title: "Vice President, Legal Tech", short: "Legal Tech",
      linkedin: "https://www.linkedin.com/in/arzhanm/",
      bio: "Oversees legal operations and technology infrastructure supporting CAABA's members and programs." },
    { name: "Assel Anarbekova", title: "Vice President, Membership", short: "Membership",
      linkedin: "https://www.linkedin.com/in/assel-anarbekova-24833696",
      bio: "Leads member engagement, recruitment, and the long-term stewardship of the CAABA community." },
  ]
};

const PROJECTS = [
  {
    id: 1,
    label: "Initiative 01",
    title: "International Lawyer Pathways",
    subtitle: "OPT Support & Professional Integration",
    body: "A dedicated pathway program for foreign-trained lawyers, LLM students, and internationally trained legal professionals navigating U.S. career entry — including Optional Practical Training guidance, networking, and long-term professional integration.",
    audience: "LLM students, foreign-trained lawyers, early-career professionals",
    goals: [
      "Clarify U.S. legal career pathways for international lawyers",
      "Support OPT and practical training transitions",
      "Connect candidates with practitioners, employers, and institutional resources",
    ],
    cta: "Learn More",
  },
  {
    id: 2,
    label: "Initiative 02",
    title: "Mentorship & Career Network",
    subtitle: "Intergenerational Professional Exchange",
    body: "A structured initiative pairing experienced attorneys with law students, LLM graduates, and early-career professionals to provide sustained mentorship, guidance, and long-term development across practice areas.",
    audience: "Attorneys, mentees, law students, LLM graduates",
    goals: [
      "Pair members through thoughtful, practice-aware matching",
      "Provide sustained, structured guidance across career stages",
      "Build durable intergenerational professional relationships",
    ],
    cta: "Express Interest",
  },
  {
    id: 3,
    label: "Initiative 03",
    title: "U.S.–Central Asia Legal Bridge",
    subtitle: "Cross-Border Dialogue & Partnership",
    body: "A cross-border initiative dedicated to legal dialogue, professional exchange, institutional partnership, and collaboration between the legal communities of the United States and Central Asia.",
    audience: "Bar associations, academic institutions, international firms, government counterparts",
    goals: [
      "Convene cross-border legal dialogue and roundtables",
      "Establish institutional partnerships with Central Asian counterparts",
      "Support collaborative projects, exchanges, and publications",
    ],
    cta: "Partner With Us",
  },
  {
    id: 4,
    label: "Initiative 04",
    title: "Trusted Referral Network",
    subtitle: "Ethically Grounded Professional Collaboration",
    body: "A professional member network structured to encourage ethically sound referrals and trusted collaboration across practice areas and jurisdictions — anchored in the long-term reputations of its participants.",
    audience: "CAABA members across practice areas and jurisdictions",
    goals: [
      "Facilitate ethically grounded referrals within the membership",
      "Strengthen cross-practice and cross-jurisdictional collaboration",
      "Reinforce the professional trust that sustains the Association",
    ],
    cta: "Join the Network",
  },
];

const AUDIENCES = [
  { tag: "For Attorneys", title: "Practicing Attorneys & Legal Professionals",
    body: "A professional home and referral community for attorneys who value substantive collaboration, continued development, and the stewardship of a growing legal network." },
  { tag: "For Students", title: "Law Students & Early-Career Professionals",
    body: "Mentorship, career guidance, and an access point into a professional community committed to supporting the next generation of legal talent." },
  { tag: "For Foreign-Trained Lawyers", title: "Foreign-Trained Lawyers & LLM Graduates",
    body: "Practical support for navigating the U.S. legal profession — from OPT pathways to licensure, networking, and long-term career integration." },
  { tag: "For Partners", title: "Mentors, Donors, Sponsors & Institutional Partners",
    body: "Purposeful ways to contribute — through mentorship, philanthropy, sponsorship, or institutional partnership — to a durable professional community." },
];

const VALUES = [
  { k: "01", v: "Integrity", d: "Professional ethics and the trust of our members are the foundation of everything we build." },
  { k: "02", v: "Excellence", d: "Substantive programming and institutional craftsmanship — no shortcuts, no filler." },
  { k: "03", v: "Community", d: "A generous, intergenerational professional community that stewards its members carefully." },
  { k: "04", v: "Bridge-Building", d: "Enduring professional relationships between the United States and Central Asia." },
  { k: "05", v: "Inclusivity", d: "Open to legal professionals, students, foreign-trained lawyers, and mission-aligned supporters." },
  { k: "06", v: "Stewardship", d: "A long-horizon commitment to the members and institutions that will follow us." },
];

const NEWS = [
  {
    id: 1,
    type: "Program Recap",
    date: "May 7, 2026",
    title: "CAABA Hosts Online Bar Exam Knowledge-Sharing Session",
    dek: "CAABA recently convened an online discussion with community members who successfully passed the U.S. Bar Exam.",
    body: "The session focused on more than exam preparation. Participants discussed navigating the U.S. legal profession, professional adaptation, mentorship, and the value of sharing practical knowledge across the CAABA community.",
    cta: "View Instagram Post",
    externalUrl: "https://www.instagram.com/p/DYDhDSbFNYT/",
  },
  {
    id: 2,
    type: "Announcement",
    date: "April 23, 2026",
    title: "CAABA Officially Registered as a Texas Nonprofit Organization",
    dek: "The Central Asian American Bar Association has been officially registered as a nonprofit organization in Texas.",
    body: "CAABA's Certificate of Filing was issued by the Office of the Texas Secretary of State for Central Asian American Bar Association, File Number 806557346. The filing is dated April 20, 2026 and became effective April 21, 2026.",
    cta: "Contact CAABA",
    target: "contact",
  },
  {
    id: 3,
    type: "Program Update",
    date: "May 2026",
    title: "Membership Interest Now Open",
    dek: "CAABA is inviting attorneys, students, foreign-trained lawyers, and mission-aligned supporters connected to Central Asia to express interest in membership.",
    body: "The Association is building its first membership cohort with a focus on professional development, mentorship, trusted referrals, and cross-border legal community. Prospective members may submit an initial membership inquiry while formal dues and category details are finalized.",
    cta: "Express Interest",
    target: "membership",
  },
  {
    id: 4,
    type: "Program Update",
    date: "Spring 2026",
    title: "Mentorship and International Lawyer Pathways Programs in Formation",
    dek: "CAABA is developing structured programming for law students, LLM graduates, and foreign-trained lawyers entering the U.S. legal profession.",
    body: "The initial program design centers on career navigation, OPT support, practice-area exposure, and sustained mentorship with experienced practitioners. Additional details will be announced as committee work advances.",
    cta: "View Initiatives",
    target: "projects",
  },
  {
    id: 5,
    type: "Leadership",
    date: "2026",
    title: "Founding Leadership Team Announced",
    dek: "CAABA's officers and vice presidents will steward the Association's early governance, member engagement, education, relationships, and legal technology work.",
    body: "The leadership structure reflects CAABA's commitment to careful institution-building, professional standards, and durable service to a growing legal community.",
    cta: "Meet Leadership",
    target: "leadership",
  },
];

// IRS § 6113 — required notice for 501(c)(6) organizations. Must appear
// conspicuously alongside any solicitation of dues, contributions, gifts,
// or sponsorships.
const TAX_NOTICE = {
  label: "Tax Notice",
  body: "Association is a 501(c)(6) non-profit organization. Dues, contributions, gifts, or sponsorship payments to the Association are not deductible as charitable contributions for federal income tax purposes. However, they may be deductible as ordinary and necessary business expenses. Please consult your tax advisor.",
};

const TaxNotice = ({ tone = "light", compact = false }) => {
  const dark = tone === "dark";
  return (
    <aside
      role="note"
      aria-label="Tax-deductibility notice"
      style={{
        border: `1px solid ${dark ? "var(--rule-dark)" : "var(--rule)"}`,
        background: dark ? "rgba(255,255,255,0.04)" : "var(--paper-3)",
        padding: compact ? "16px 18px" : "20px 22px",
        display: "flex",
        flexDirection: "column",
        gap: 8,
      }}
    >
      <div className={`eyebrow${dark ? " light" : ""}`} style={{letterSpacing: "0.16em"}}>
        {TAX_NOTICE.label}
      </div>
      <p style={{
        margin: 0,
        fontSize: compact ? 13 : 13.5,
        lineHeight: 1.6,
        color: dark ? "#C9D2DC" : "var(--ink-3)",
      }}>
        {TAX_NOTICE.body}
      </p>
    </aside>
  );
};

const newsDateSortKey = (item) => {
  if (item && item.publishedAt) {
    const ts = Date.parse(item.publishedAt);
    if (!Number.isNaN(ts)) return ts;
  }
  if (item && item.date) {
    const ts = Date.parse(item.date);
    if (!Number.isNaN(ts)) return ts;
  }
  return 0;
};

const mergeNewsSources = (dynamic) => {
  const dynamicList = Array.isArray(dynamic) ? dynamic : [];
  const dynamicIds = new Set(dynamicList.map((it) => it && it.id).filter(Boolean));
  const merged = [
    ...dynamicList,
    ...NEWS.filter((it) => !dynamicIds.has(it.id)),
  ];
  return merged.sort((a, b) => newsDateSortKey(b) - newsDateSortKey(a));
};

const useNewsItems = () => {
  const [dynamic, setDynamic] = React.useState(null);

  React.useEffect(() => {
    let cancelled = false;
    fetch("/api/news", { cache: "no-store" })
      .then((r) => (r.ok ? r.json() : { items: [] }))
      .then((data) => {
        if (cancelled) return;
        const items = Array.isArray(data) ? data : Array.isArray(data && data.items) ? data.items : [];
        setDynamic(items);
      })
      .catch(() => {
        if (!cancelled) setDynamic([]);
      });
    return () => {
      cancelled = true;
    };
  }, []);

  return React.useMemo(() => mergeNewsSources(dynamic || []), [dynamic]);
};

Object.assign(window, {
  NAV, PILLARS, LEADERSHIP, PROJECTS, AUDIENCES, VALUES, NEWS,
  mergeNewsSources, newsDateSortKey, useNewsItems,
  TAX_NOTICE, TaxNotice,
});
