/* global React */
// Varick Health — Portal kit: shared helpers + mock data
const { useEffect, useState } = React;

function Icon({ name, size = 18, color, strokeWidth = 1.75, style }) {
  const ref = React.useRef(null);
  useEffect(() => {
    if (ref.current && window.lucide) {
      ref.current.innerHTML = "";
      const el = document.createElement("i");
      el.setAttribute("data-lucide", name);
      ref.current.appendChild(el);
      window.lucide.createIcons({ attrs: { width: size, height: size, "stroke-width": strokeWidth }, nameAttr: "data-lucide" });
      const svg = ref.current.querySelector("svg");
      if (svg && color) svg.style.color = color;
    }
  }, [name, size, strokeWidth, color]);
  return <span ref={ref} className="vh-ic" style={{ display: "inline-flex", color, ...style }} />;
}

// status → pill class + label
const STATUS = {
  enrolled:  { c: "ok",       l: "Enrolled" },
  verified:  { c: "ok",       l: "Verified" },
  submitted: { c: "progress", l: "Submitted" },
  review:    { c: "progress", l: "In Review" },
  action:    { c: "warn",     l: "Action Needed" },
  expiring:  { c: "warn",     l: "Expiring" },
  denied:    { c: "danger",   l: "Denied" },
  expired:   { c: "danger",   l: "Expired" },
  queued:    { c: "idle",     l: "Queued" },
  notstarted:{ c: "idle",     l: "Not Started" },
};
function Pill({ s, label }) {
  const d = STATUS[s] || STATUS.queued;
  return <span className={"vh-status vh-status--" + d.c}>{label || d.l}</span>;
}

const PAYERS = ["Empire BCBS", "Optum NY IPA", "Healthfirst", "Aetna", "Cigna", "Fidelis (Medicaid MCO)", "Medicare"];

// per-provider payer enrollment states
function pe(arr) { return PAYERS.map((p, i) => ({ payer: p, status: arr[i] || "notstarted" })); }

const PROVIDERS = [
  { id: "p1", name: "Dana Okafor", cred: "LCSW", icp: "Therapy", site: "Brooklyn", npi: "1740442891", caqh: "14905327",
    status: "enrolled", ttb: 19, payers: pe(["enrolled","enrolled","enrolled","enrolled","enrolled","enrolled","enrolled"]),
    exps: [{ t: "State license (LCSW)", d: "2027-04-30", s: "verified" }, { t: "CAQH attestation", d: "2026-09-12", s: "verified" }, { t: "Malpractice", d: "2026-11-01", s: "verified" }] },
  { id: "p2", name: "Marcus Alvarez", cred: "PMHNP", icp: "Psychiatry", site: "Manhattan", npi: "1659327004", caqh: "10238841",
    status: "action", ttb: 28, payers: pe(["enrolled","enrolled","enrolled","submitted","review","enrolled","notstarted"]),
    exps: [{ t: "DEA registration", d: "2026-06-12", s: "expiring" }, { t: "State license (NP)", d: "2027-01-15", s: "verified" }, { t: "Collaborative practice agt.", d: "2026-08-01", s: "verified" }] },
  { id: "p3", name: "Jordan Reyes", cred: "LMHC", icp: "Therapy", site: "Queens", npi: "1881229017", caqh: "15580922",
    status: "submitted", ttb: null, payers: pe(["enrolled","submitted","review","submitted","notstarted","review","notstarted"]),
    exps: [{ t: "State license (LMHC)", d: "2027-07-20", s: "verified" }, { t: "CAQH attestation", d: "2026-10-02", s: "verified" }] },
  { id: "p4", name: "Sana Patel", cred: "Psy.D", icp: "Therapy", site: "Manhattan", npi: "1023994410", caqh: "13345001",
    status: "enrolled", ttb: 22, payers: pe(["enrolled","enrolled","enrolled","enrolled","enrolled","enrolled","verified"]),
    exps: [{ t: "State license (Psychology)", d: "2028-02-28", s: "verified" }, { t: "Malpractice", d: "2026-12-15", s: "verified" }] },
  { id: "p5", name: "Wei Chen", cred: "MD", icp: "Psychiatry", site: "Manhattan", npi: "1447781230", caqh: "11002934",
    status: "enrolled", ttb: 25, payers: pe(["enrolled","enrolled","enrolled","enrolled","enrolled","enrolled","enrolled"]),
    exps: [{ t: "DEA registration", d: "2027-09-30", s: "verified" }, { t: "Board certification", d: "2029-01-01", s: "verified" }, { t: "State license (MD)", d: "2027-03-31", s: "verified" }] },
  { id: "p6", name: "Aisha Bello", cred: "LMSW", icp: "Clinic", site: "Bronx", npi: "1590028876", caqh: "16690115",
    status: "review", ttb: null, payers: pe(["enrolled","review","submitted","notstarted","notstarted","review","submitted"]),
    exps: [{ t: "State license (LMSW)", d: "2027-05-10", s: "verified" }, { t: "CAQH attestation", d: "2026-07-08", s: "expiring" }] },
  { id: "p7", name: "Tomás Vega", cred: "LMFT", icp: "Therapy", site: "Brooklyn", npi: "1338820045", caqh: "14411902",
    status: "denied", ttb: null, payers: pe(["enrolled","enrolled","denied","enrolled","enrolled","enrolled","notstarted"]),
    exps: [{ t: "State license (LMFT)", d: "2027-08-18", s: "verified" }, { t: "Malpractice", d: "2026-10-22", s: "verified" }] },
  { id: "p8", name: "Priya Nair", cred: "PMHNP", icp: "Psychiatry", site: "Queens", npi: "1779930028", caqh: "17820334",
    status: "queued", ttb: null, payers: pe(["notstarted","notstarted","notstarted","notstarted","notstarted","notstarted","notstarted"]),
    exps: [{ t: "State license (NP)", d: "2027-11-30", s: "verified" }, { t: "DEA registration", d: "2027-02-14", s: "verified" }] },
  { id: "p9", name: "Daniel Stern", cred: "LCSW", icp: "Clinic", site: "Bronx", npi: "1228194471", caqh: "12290048",
    status: "enrolled", ttb: 18, payers: pe(["enrolled","enrolled","enrolled","notstarted","notstarted","enrolled","enrolled"]),
    exps: [{ t: "State license (LCSW)", d: "2028-06-30", s: "verified" }, { t: "CAQH attestation", d: "2026-08-25", s: "verified" }] },
  { id: "p10", name: "Grace Lim", cred: "LMHC", icp: "Therapy", site: "Manhattan", npi: "1665520119", caqh: "15012876",
    status: "action", ttb: null, payers: pe(["enrolled","enrolled","action","enrolled","review","notstarted","notstarted"]),
    exps: [{ t: "State license (LMHC)", d: "2027-09-09", s: "verified" }, { t: "CAQH attestation", d: "2026-06-30", s: "expiring" }] },
];

const TASKS = [
  { p: "Marcus Alvarez", s: "expiring", t: "DEA registration expires in 14 days", due: "Jun 12", who: "Varick" },
  { p: "Grace Lim", s: "action", t: "Empire BCBS requires updated W-9", due: "Jun 03", who: "You" },
  { p: "Tomás Vega", s: "denied", t: "Healthfirst denied — re-submitting with corrected taxonomy", due: "Jun 05", who: "Varick" },
  { p: "Grace Lim", s: "expiring", t: "CAQH attestation due", due: "Jun 30", who: "Varick" },
  { p: "Aisha Bello", s: "expiring", t: "CAQH attestation due", due: "Jul 08", who: "Varick" },
];

const ACTIVITY = [
  { ic: "circle-check", t: "Sana Patel enrolled with Medicare", time: "2h ago", c: "var(--vh-ok)" },
  { ic: "upload", t: "Jordan Reyes — Optum NY IPA application submitted", time: "5h ago", c: "var(--vh-indigo)" },
  { ic: "file-check-2", t: "Wei Chen — primary-source verification complete", time: "Yesterday", c: "var(--vh-ok)" },
  { ic: "circle-alert", t: "Tomás Vega — Healthfirst returned for correction", time: "Yesterday", c: "var(--vh-warn)" },
  { ic: "user-plus", t: "Priya Nair added to roster", time: "2 days ago", c: "var(--vh-text-faint)" },
];

Object.assign(window, { Icon, Pill, STATUS, PAYERS, PROVIDERS, TASKS, ACTIVITY });
