/* global React, I, Button, Reveal, HeroDashboard, useTilt, CountUp */
const { useState:useHS, useEffect:useHE, useRef:useHR } = React;

/* ============ HERO ============ */
function Hero({ go }){
  return (
    React.createElement("section",{ className:"hero", id:"top" },
      React.createElement("div",{ className:"wrap" },
        React.createElement("div",{ className:"hero-center" },
          React.createElement(Reveal,null,
            React.createElement("h1",null, "Explainable medical coding,",
              React.createElement("br",null), "Supercharged by AI Agents")),
          React.createElement(Reveal,{ delay:90 },
            React.createElement("p",{ className:"hero-lead" },
              "Transform clinical notes into low, moderate, or high MDM scoring with CPT recommendations, ICD candidates, and a full audit trail — in seconds.")),
          React.createElement(Reveal,{ delay:170 },
            React.createElement("div",{ className:"hero-cta" },
              React.createElement(Button,{ variant:"grad", onClick:()=>go("new") }, "Analyze a note"),
              React.createElement(Button,{ variant:"ghost", icon:false, onClick:()=>go("flow") }, "How it works")))
        ),
        React.createElement(Reveal,{ delay:120, scale:true, className:"hero-dash-wrap" },
          React.createElement(HeroDashboard,null))
      )
    )
  );
}

/* ============ FEATURES ============ */
const FEATURES = [
  { ic:"spark", t:"Smart AI Automation", d:"Each recommendation is paired with documented excerpts, MDM rationale, and review-friendly reasoning." },
  { ic:"doc",   t:"Designed for Pilots", d:"An open, no-login workflow gives stakeholders a fast way to evaluate the experience without platform overhead." },
  { ic:"layers",t:"Provider-flexible Backend", d:"The model layer stays isolated behind a backend adapter so teams can evolve providers without rebuilding the product." },
];
function FeatureCard({ f, i }){
  const tilt = useTilt(4);
  return React.createElement(Reveal,{ delay:i*90 },
    React.createElement("div",{ className:"feat-card", ...tilt },
      React.createElement("div",{ className:"feat-ic" }, React.createElement(I[f.ic],{ size:21 })),
      React.createElement("h3",null,f.t),
      React.createElement("p",null,f.d),
      React.createElement("div",{ className:"feat-foot" }, "Review-ready output",
        React.createElement("span",{ className:"a" }, React.createElement(I.arrow,{ size:14 })))
    )
  );
}
function Features(){
  return React.createElement("section",{ className:"section" },
    React.createElement("div",{ className:"wrap" },
      React.createElement(Reveal,null, React.createElement("p",{ className:"eyebrow" }, "Built for outpatient coding")),
      React.createElement(Reveal,{ delay:60 }, React.createElement("h2",{ className:"h-sec" }, "Everything you need to review and scale with AI")),
      React.createElement("div",{ className:"feat-grid" },
        FEATURES.map((f,i)=> React.createElement(FeatureCard,{ key:f.t, f, i })))
    )
  );
}

/* ============ WORKFLOW SHOWCASE ============ */
const FLOW = [
  { s:"Step 01", t:"Medical Record Upload", d:"Paste or upload an office/outpatient note. Text is extracted and validated before anything runs." },
  { s:"Step 02", t:"AI Analysis", d:"The agent parses the encounter, isolating problems, reviewed data, and management decisions." },
  { s:"Step 03", t:"Coding Recommendation", d:"MDM is scored across Problems, Data, and Risk, producing a defensible CPT recommendation." },
  { s:"Step 04", t:"Compliance Validation", d:"Guardrails check note-size caps, supported encounter types, and documentation sufficiency." },
  { s:"Step 05", t:"Audit Review", d:"Every decision links back to a quoted excerpt — an evidence trail built for human review." },
  { s:"Step 06", t:"Final Submission", d:"Export the structured assessment with ICD candidates and rationale, ready for billing review." },
];
function Flow(){
  const wrapRef = useHR(null);
  const [prog, setProg] = useHS(0);
  const [active, setActive] = useHS(-1);
  useHE(()=>{
    const onScroll = ()=>{
      const el = wrapRef.current; if(!el) return;
      const r = el.getBoundingClientRect();
      const vh = innerHeight;
      const total = r.height - vh*0.5;
      const p = Math.max(0, Math.min(1, (vh*0.72 - r.top) / total));
      setProg(p);
      setActive(Math.floor(p * FLOW.length * 0.999));
    };
    addEventListener("scroll", onScroll); onScroll();
    return ()=> removeEventListener("scroll", onScroll);
  },[]);
  return React.createElement("section",{ className:"section", id:"flow" },
    React.createElement("div",{ className:"wrap" },
      React.createElement(Reveal,null, React.createElement("p",{ className:"eyebrow" }, "From note to defensible code")),
      React.createElement(Reveal,{ delay:60 }, React.createElement("h2",{ className:"h-sec" }, "One continuous, explainable workflow")),
      React.createElement(Reveal,{ delay:120 }, React.createElement("p",{ className:"sub-sec" }, "Each stage animates as you scroll — a living map of how a clinical note becomes an audit-ready coding assessment.")),
      React.createElement("div",{ className:"flow", ref:wrapRef },
        React.createElement("div",{ className:"flow-line" }, React.createElement("div",{ className:"prog", style:{ height:`${prog*100}%` } })),
        React.createElement("div",{ className:"flow-steps" },
          FLOW.map((st,i)=>(
            React.createElement("div",{ key:st.s, className:`flow-step ${i<=active?"on":""}` },
              React.createElement("div",{ className:"flow-spacer" }),
              React.createElement("div",{ className:"flow-node" }, React.createElement(I[["upload","brain","layers","shield","activity","check"][i]],{ size:20 })),
              React.createElement("div",{ className:"flow-card" },
                React.createElement("div",{ className:"fc-step" }, st.s),
                React.createElement("h4",null,st.t),
                React.createElement("p",null,st.d))
            )
          ))
        )
      )
    )
  );
}

/* ============ AI TOOLS ============ */
function ToolPerf(){
  return React.createElement("div",{ className:"tool-viz", style:{ display:"flex", alignItems:"flex-end", gap:6, height:54 } },
    [40,62,48,78,58,88,72].map((h,i)=>(
      React.createElement("div",{ key:i, style:{ width:14, height:`${h}%`, borderRadius:5,
        background:i===5?"linear-gradient(180deg,#8b7ee6,#c9a6e0)":"#e7e5f3",
        animation:`barGrow 1s ease-out ${i*80}ms both` } })))
  );
}
function ToolBuilder(){
  return React.createElement("div",{ className:"tool-viz", style:{ position:"relative", height:54 } },
    React.createElement("svg",{ width:"100%", height:54, viewBox:"0 0 240 54", style:{overflow:"visible"} },
      React.createElement("path",{ d:"M36 27 H108", stroke:"#cdc6ef", strokeWidth:2, fill:"none", strokeDasharray:"4 4",
        style:{ animation:"dash 18s linear infinite" } }),
      React.createElement("path",{ d:"M132 27 H204", stroke:"#cdc6ef", strokeWidth:2, fill:"none", strokeDasharray:"4 4",
        style:{ animation:"dash 18s linear infinite" } }),
      [36,120,204].map((x,i)=>React.createElement("g",{ key:i },
        React.createElement("rect",{ x:x-18, y:13, width:36, height:28, rx:8, fill:"#fff", stroke:"#e2e0ef" }),
        React.createElement("circle",{ cx:x, cy:27, r:4, fill:["#8b7ee6","#6f9af0","#2c9a6a"][i] })))
    )
  );
}
function ToolFeed(){
  const items=["MDM scored · Moderate","Evidence linked · E11.65","CPT mapped · 99213"];
  const [n,setN]=useHS(0);
  useHE(()=>{ const id=setInterval(()=>setN(p=>(p+1)%(items.length+1)),1100); return ()=>clearInterval(id); },[]);
  return React.createElement("div",{ className:"tool-viz", style:{ display:"flex", flexDirection:"column", gap:6 } },
    items.map((t,i)=>(
      React.createElement("div",{ key:i, style:{ display:"flex", alignItems:"center", gap:8, fontSize:12, color:"var(--muted)",
        opacity:i<n?1:.3, transition:"opacity .4s" } },
        React.createElement("span",{ style:{ width:6, height:6, borderRadius:"50%", background:i<n?"var(--green)":"#d4d1e8" } }),
        t)))
  );
}
function ToolAgents(){
  return React.createElement("div",{ className:"tool-viz", style:{ display:"flex", gap:8 } },
    ["Docs","ICD","Audit"].map((t,i)=>(
      React.createElement("div",{ key:i, style:{ flex:1, background:"var(--purple-soft)", borderRadius:10, padding:"8px 10px", textAlign:"center" } },
        React.createElement("div",{ style:{ fontSize:11, fontWeight:600, color:"var(--purple-ink)" } }, t),
        React.createElement("div",{ style:{ height:4, marginTop:6, borderRadius:3, background:"#d6cdf3", overflow:"hidden" } },
          React.createElement("div",{ style:{ height:"100%", width:"100%", background:"linear-gradient(90deg,#8b7ee6,#c9a6e0)",
            transformOrigin:"left", animation:`barGrow 1.4s ease-out ${i*200}ms both` } })))
    ))
  );
}
const TOOLS = [
  { ic:"chart",    t:"Performance Insights", d:"Track MDM accuracy, average review time, and CPT coverage across every encounter your team submits.", viz:ToolPerf },
  { ic:"workflow", t:"Workflow Builder", d:"Define how Problems, Data, and Risk are scored. Set guardrails that match your billing policies.", viz:ToolBuilder },
  { ic:"activity", t:"Real-Time Updates", d:"Watch the analyzer extract evidence, score MDM, and map CPT in seconds — live as the note is parsed.", viz:ToolFeed },
  { ic:"bolt",     t:"Autonomous AI Agents", d:"Hand off documentation sufficiency, ICD mapping, and audit-trail compilation to coordinated agents.", viz:ToolAgents },
];
function Tools(){
  return React.createElement("section",{ className:"section" },
    React.createElement("div",{ className:"wrap" },
      React.createElement(Reveal,null, React.createElement("h2",{ className:"h-sec" }, "AI tools that work while you review")),
      React.createElement(Reveal,{ delay:80 }, React.createElement("p",{ className:"sub-sec" }, "A precise path from clinical note to explainable output — Submit, Analyze, Explain.")),
      React.createElement("div",{ className:"tools-grid" },
        TOOLS.map((t,i)=>(
          React.createElement(Reveal,{ key:t.t, delay:(i%2)*90 },
            React.createElement("div",{ className:"tool-card" },
              React.createElement("div",{ className:"tool-ic" }, React.createElement(I[t.ic],{ size:20 })),
              React.createElement("div",{ style:{flex:1} },
                React.createElement("h4",null,t.t),
                React.createElement("p",null,t.d),
                React.createElement(t.viz,null)))
          )))
      )
    )
  );
}

Object.assign(window, { Hero, Features, Flow, Tools });
