/* Calibrated Ascension HQ — mock data layer
   Exposed on window.HQ_DATA. All numbers are illustrative. */

const PILLARS = [
  { id: "offers", label: "Offers", blurb: "products, pricing, launches" },
  { id: "automation", label: "Automation", blurb: "GoHighLevel & workflows" },
  { id: "traffic", label: "Social & Traffic", blurb: "social, distribution, SEO" },
];

/* The agent team. status: running | waiting | needs-you | idle */
const AGENTS = [
  {
    id: "atlas", name: "Anubis", role: "Business Manager", title: "Master brain · Chief of staff",
    pillar: null, lead: true, status: "running",
    now: "Synthesizing today's brief across all 7 agents + 3 client accounts.",
    last: "Re-prioritized the Nova launch ahead of the blog backlog.",
    loops: ["Hourly: scan all agent outputs", "Daily 5:00pm: assemble EOD brief", "On idea: route to the right specialist"],
  },
  {
    id: "vera", name: "Sage", role: "Chief Marketing Officer", title: "Co-pilots strategy with Anubis",
    pillar: "traffic", lead: true, status: "running",
    now: "Mapping the Q3 content calendar to the two active launches.",
    last: "Approved Noah's ad angle test; flagged 2 hooks for you.",
    loops: ["Weekly: campaign performance review", "On launch: build go-to-market", "Daily: brief the specialist agents"],
  },
  {
    id: "margo", name: "Odin", role: "Offers Strategist", title: "Products · pricing · launches",
    pillar: "offers", status: "needs-you",
    now: "Drafted a 3-tier pricing test for the Nova skincare funnel.",
    last: "Modeled $14.2k upside from an order-bump on the core offer.",
    loops: ["Weekly: offer & price audit", "On launch: build the value ladder", "Monthly: churn + LTV readout"],
  },
  {
    id: "cole", name: "Alma", role: "Automation Engineer", title: "The GoHighLevel doer",
    pillar: "automation", status: "running",
    now: "Running the Community Call → Replays workflow.",
    last: "Built & QA'd a 6-email custom-coded welcome sequence in GHL.",
    loops: ["On trigger: run GHL workflows", "Daily: health-check automations", "Weekly: clean dead webhooks"],
  },
  {
    id: "ravi", name: "Noah", role: "Social & Traffic", title: "Social · distribution · SEO",
    pillar: "traffic", status: "running",
    now: "Reallocating effort toward the winning Reels hook (engagement up 22%).",
    last: "Published 3 SEO posts; 2 cluster pages now ranking p.1.",
    loops: ["Daily: distribution + engagement", "Daily: distribute new content", "Weekly: keyword gap scan"],
  },
  {
    id: "juno", name: "Iris", role: "Content Producer", title: "Scripts · captions · repurposing",
    pillar: "traffic", status: "needs-you",
    now: "Wrote the recap post + 4 shorts from last night's community call.",
    last: "Repurposed 1 long-form video into 9 assets across 4 channels.",
    loops: ["On idea: draft → you approve → publish", "Daily: repurpose top performer", "Weekly: refresh evergreen"],
  },
  {
    id: "sage", name: "Bella", role: "Community Manager", title: "Calls · posts · engagement",
    pillar: "automation", status: "waiting",
    now: "Holding the community recap post — waiting on your approval.",
    last: "Answered 41 community threads; escalated 2 to you.",
    loops: ["Bi-weekly: prep & post call recap", "Daily: triage community", "Weekly: engagement readout"],
  },
  {
    id: "quinn", name: "Abby", role: "Finance & Ops", title: "Cash · margins · subscriptions",
    pillar: "offers", status: "idle",
    now: "Idle — next run at 6:00am with the daily cash snapshot.",
    last: "Flagged a failed client subscription charge (recovered).",
    loops: ["Daily 6am: cash & MRR snapshot", "Weekly: margin by client", "On dunning: recover failed charges"],
  },
  {
    id: "max", name: "Max", role: "Messenger & DM", title: "Social DMs · responses", pillar: "traffic", pairWith: "juno", status: "running",
    now: "Working 23 DMs across IG + the community inbox — drafted 4 buyers for your eyes.",
    last: "Turned a cold DM thread into a booked call for Apex.",
    loops: ["Continuous: triage + reply to DMs", "On viral post: handle the inflow in your voice", "Daily: hand hot leads to the booking flow"],
  },
  {
    id: "soham", name: "Soham", role: "Dev Lead", title: "Code · fixes · integrations", pillar: "automation", pairWith: "cole", status: "running",
    now: "Patching the Lumen calendar webhook + hardening the Vercel deploy.",
    last: "Shipped the fix for the Apex blog-publish token flow.",
    loops: ["On break: hotfix first, then root-cause", "Weekly: dependency + secret-rotation pass", "On request: build custom integrations (GitHub → Vercel → Supabase)"],
  },
];

/* Client accounts — white-label agency. 'agency' is your own (always first). */
const CLIENTS = [
  { id: "agency", name: "Calibrated Ascension", kind: "Your agency", initials: "CA", color: "var(--accent)", agency: true, connected: true, contact: "you@calibratedascension.com", ghl: "loc_agency" },
  { id: "nova", name: "Nova Skincare", kind: "Client", initials: "NS", color: "oklch(0.62 0.12 25)", connected: true, pinned: true, contact: "team@novaskincare.com", ghl: "loc_8f2a1c" },
  { id: "lumen", name: "Lumen Wellness", kind: "Client", initials: "LW", color: "oklch(0.62 0.10 240)", connected: true, pinned: true, contact: "hello@lumenwellness.co", ghl: "loc_3b7c90" },
  { id: "apex", name: "Apex Coaching", kind: "Client", initials: "AC", color: "oklch(0.60 0.11 300)", connected: true, pinned: true, contact: "ops@apexcoaching.com", ghl: "loc_d41e22" },
  { id: "vireo", name: "Vireo Studio", kind: "Client", initials: "VS", color: "oklch(0.60 0.10 150)", connected: true, pinned: false, contact: "studio@vireo.design", ghl: "loc_77aa31" },
  { id: "harbor", name: "Harbor & Co", kind: "Client", initials: "HC", color: "oklch(0.56 0.08 60)", connected: false, pinned: false, contact: "admin@harborco.com", ghl: "" },
];

/* Per-client context. Keyed by client id. */
const CONTEXT = {
  agency: {
    greeting: "Everything's running. Three things want your eyes.",
    metrics: {
      offers: { value: "$48.6k", label: "Pipeline this month", delta: "+12%", up: true, sub: "2 launches live" },
      automation: { value: "31", label: "Workflows active", delta: "100% healthy", up: true, sub: "0 broken" },
      traffic: { value: "$2.14", label: "Blended CPL", delta: "-22%", up: true, sub: "spend $1.8k/day" },
    },
    decisions: [
      { id: "d1", agent: "margo", title: "Approve 3-tier pricing test for Nova funnel", detail: "Odin modeled +$14.2k/mo upside. Needs your go before Alma builds it in GHL.", tag: "Offers", urgency: "high", workflow: [{ agentId: "margo", label: "Modeled a 3-tier test ($47 / $97 / $197) — +$14.2k/mo" }, { agentId: "cole", label: "On approval: builds the tiers in GoHighLevel tonight" }, { agentId: "quinn", label: "Models the launch-week cash impact" }] },
      { id: "d2", agent: "juno", title: "Approve community-call recap post + 4 shorts", detail: "Drafted from last night's call. Bella will publish to the community on approval.", tag: "Content", urgency: "high", workflow: [{ agentId: "juno", label: "Drafted the recap post + 4 short clips" }, { agentId: "sage", label: "On approval: posts to the Replays channel" }] },
      { id: "d3", agent: "ravi", title: "Sign off: shift $400/day to winning Reels hook", detail: "CPL down 22% on hook B. Noah wants to reallocate from the cold-audience set.", tag: "Traffic", urgency: "med", workflow: [{ agentId: "ravi", label: "Hook B beat the rest — CPL down 22%" }, { agentId: "ravi", label: "On approval: shifts $400/day off the cold-audience set" }] },
    ],
    tomorrow: {
      offers: ["Alma builds approved pricing test in GHL", "Odin drafts the order-bump copy", "Abby models launch-week cash"],
      automation: ["Run abandoned-checkout recovery for Nova", "Migrate Lumen's email templates to new editor", "Add SMS step to booking workflow"],
      traffic: ["Scale winning Reels hook + 2 new variants", "Publish 2 SEO cluster pages", "Repurpose call into 9 assets"],
    },
    risks: [
      { id: "r1", title: "Lumen calendar webhook misfired twice overnight", detail: "Bookings still captured via fallback. Alma has a fix queued for 9am.", level: "med" },
      { id: "r2", title: "Apex blog publish blocked — stale API token", detail: "Vercel deploy needs a refreshed token. Quick fix, needs your login.", level: "high" },
    ],
    projects: [
      { id: "agp1", title: "Nova skincare — 7-day launch funnel", status: "active", pm: "vera", updated: "2h ago", who: "Odin + Alma", steps: [ { agentId: "margo", label: "Value ladder + 3-tier pricing test" }, { agentId: "cole", label: "Build the funnel in GoHighLevel" }, { agentId: "juno", label: "Launch emails + 9 repurposed assets" }, { agentId: "ravi", label: "Scale the winning Reels hook" } ], deliverables: [ { id: "agp1d1", type: "form", title: "Launch assets intake", to: "team@novaskincare.com", fields: ["Brand logo (SVG + PNG)", "Hero product photography", "Founder bio — 100 words", "Brand color hex codes", "Approved claims / disclaimers"] } ] },
      { id: "agp2", title: "Apex — executive-coaching SEO cluster", status: "active", pm: "juno", updated: "yesterday", who: "Iris + Noah", steps: [ { agentId: "juno", label: "Write 4 cluster pages" }, { agentId: "ravi", label: "Internal links + publish" } ], deliverables: [ { id: "agp2d1", type: "doc", title: "Content approval doc", to: "ops@apexcoaching.com", body: "Outline + 4 page drafts attached for your sign-off before we publish." } ] },
    ],
  },
  nova: {
    greeting: "Nova's launch is live. One approval is blocking the build.",
    metrics: {
      offers: { value: "$14.2k", label: "Launch pipeline", delta: "day 2 of 7", up: true, sub: "3-tier test pending" },
      automation: { value: "8", label: "Workflows active", delta: "all healthy", up: true, sub: "checkout + email" },
      traffic: { value: "$1.92", label: "CPL", delta: "-18%", up: true, sub: "Reels driving" },
    },
    decisions: [
      { id: "d1", agent: "margo", title: "Approve 3-tier pricing test for Nova funnel", detail: "Odin modeled +$14.2k/mo upside. Needs your go before Alma builds it in GHL.", tag: "Offers", urgency: "high" },
    ],
    tomorrow: {
      offers: ["Build approved pricing test in GHL", "Write order-bump + upsell copy", "Set launch-close countdown"],
      automation: ["Abandoned-checkout recovery sequence", "Tag buyers into post-purchase nurture"],
      traffic: ["Scale Reels hook B", "Retarget add-to-cart non-buyers"],
    },
    risks: [
      { id: "r1", title: "Checkout upsell page load time 3.1s", detail: "Iris flagged it may cost conversions. Image compression queued.", level: "med" },
    ],
    projects: [
      { id: "nvp1", title: "Spring promo landing page", status: "active", pm: "cole", updated: "4h ago", who: "Alma + Iris", steps: [ { agentId: "cole", label: "Build the promo page in GoHighLevel" }, { agentId: "juno", label: "Headline + offer copy" } ], deliverables: [ { id: "nvp1d1", type: "email", title: "Asset request", to: "team@novaskincare.com", subject: "Quick assets for your spring promo page", body: "Hi Nova team — to build your spring promo page we need three things: (1) the promo discount + start/end dates, (2) three product photos, and (3) any testimonials you'd like featured. Reply here or drop them in the shared folder and we'll have a draft to you within 48 hours." } ] },
    ],
  },
  lumen: {
    greeting: "Lumen is steady. One webhook needs watching.",
    metrics: {
      offers: { value: "$9.8k", label: "MRR", delta: "+4%", up: true, sub: "memberships" },
      automation: { value: "11", label: "Workflows active", delta: "1 flaky", up: false, sub: "calendar webhook" },
      traffic: { value: "$3.40", label: "CPL", delta: "+6%", up: false, sub: "needs new creative" },
    },
    decisions: [
      { id: "d3", agent: "ravi", title: "Approve refreshed ad creative for Lumen", detail: "CPL creeping up. Noah has 3 new angles ready to test.", tag: "Traffic", urgency: "med" },
    ],
    tomorrow: {
      offers: ["Draft a win-back offer for paused members"],
      automation: ["Patch calendar booking webhook", "Migrate email templates to new editor"],
      traffic: ["Launch 3 new ad angles", "Refresh tired audience sets"],
    },
    risks: [
      { id: "r1", title: "Calendar webhook misfired twice overnight", detail: "Bookings captured via fallback. Fix queued for 9am.", level: "med" },
    ],
  },
  apex: {
    greeting: "Apex is publishing. A token is blocking the blog.",
    metrics: {
      offers: { value: "$22.1k", label: "Coaching pipeline", delta: "+9%", up: true, sub: "high-ticket" },
      automation: { value: "12", label: "Workflows active", delta: "all healthy", up: true, sub: "application funnel" },
      traffic: { value: "$5.10", label: "Cost / application", delta: "-11%", up: true, sub: "SEO + organic" },
    },
    decisions: [
      { id: "d2", agent: "juno", title: "Approve 2 SEO blog posts for Apex", detail: "Cluster pages targeting 'executive coaching'. Ready once the publish token is fixed.", tag: "Content", urgency: "med" },
    ],
    tomorrow: {
      offers: ["Test a paid discovery-call offer"],
      automation: ["Add nurture for non-booked applications"],
      traffic: ["Publish 2 SEO cluster pages", "Build internal links to pillar page"],
    },
    risks: [
      { id: "r1", title: "Blog publish blocked — stale API token", detail: "Vercel deploy needs a refreshed token. Needs your login.", level: "high" },
    ],
  },
};

/* The hero automation: community call → community Replays channel.
   Only two call types are eligible; private calls are skipped. */
const AUTOMATION = {
  id: "community-call",
  name: "Community Call → Replays",
  cadence: "Recalibration Call · Creator Workshop",
  owner: "cole",
  eligible: ["Monthly Recalibration Call", "Creator Workshop"],
  detected: {
    type: "Monthly Recalibration Call",
    date: "June 2, 2026",
    time: "7:00pm ET",
    duration: "58 min",
    file: "recalibration-2026-06-02.mp4",
    verified: true,
    note: "Matched a scheduled community event. Not a private 1:1 — safe to publish.",
  },
  post: {
    channel: "Replays",
    sharing: "Anyone with the link",
    title: "Recalibration Call | June 2, 2026",
    description: "How to find the leak between your offer and your traffic before it quietly drains a launch — and the one metric that tells you which pillar to fix first.",
    question: "If you could only strengthen one pillar this month — offers, automation, or traffic — which would move the needle most, and what's been stopping you?",
  },
  steps: [
    { id: "s1", title: "Find the recording", detail: "Scan Google Drive › /Calls and recent emails", source: "Drive · Email", dur: 1300 },
    { id: "s2", title: "Verify the call", detail: "Confirm it's a Recalibration Call or Creator Workshop — check date & time, skip anything private", source: "Anubis · safety check", dur: 1600 },
    { id: "s3", title: "Open link sharing", detail: "Set the replay to ‘Anyone with the link’ so members can watch", source: "Google Drive", dur: 1000 },
    { id: "s4", title: "Draft the replay post", detail: "Title + a one-line transformation summary + a question to ponder", source: "Iris · Content", dur: 1500 },
    { id: "s5", title: "Your approval", detail: "Review the post below — edit anything, then approve", source: "You", dur: 0, gate: true },
    { id: "s6", title: "Post to Replays channel", detail: "Publish in the community Replays channel with title + date", source: "GoHighLevel", dur: 1300 },
  ],
};

/* Other automations for the Automations view */
const AUTOMATIONS_LIST = [
  { id: "a1", name: "Community Call → Replays", cadence: "Per call", status: "ready", owner: "cole", runs: 12, note: "verify type → Replays channel" },
  { id: "a2", name: "Idea → Blog → Publish", cadence: "On demand", status: "running", owner: "juno", runs: 47, note: "draft → you approve → live" },
  { id: "a3", name: "Abandoned checkout recovery", cadence: "Continuous", status: "running", owner: "cole", runs: 318, note: "Nova + Apex funnels" },
  { id: "a4", name: "Daily cash & MRR snapshot", cadence: "Daily 6am", status: "running", owner: "quinn", runs: 184, note: "all client accounts" },
  { id: "a5", name: "AI chat knowledge-base sync", cadence: "On publish", status: "ready", owner: "atlas", runs: 9, note: "new blog → update bot KB" },
  { id: "a6", name: "Lumen calendar booking", cadence: "Continuous", status: "attention", owner: "cole", runs: 902, note: "webhook flaky overnight" },
];

/* Per-agent knowledge base — instructions + sources they draw on */
const AGENT_KB = {
  atlas: { instructions: "Run the agency end to end. Prioritize revenue and unblock me. Assemble the 4:00pm brief and only escalate decisions that genuinely need a human call.", sources: ["Agency SOPs", "All client briefs", "Quarterly goals", "Team capacity"] },
  vera: { instructions: "Own marketing strategy and the launch calendar. Keep every message on-brand and tied to the active launches.", sources: ["Brand strategy deck", "Launch calendar", "Competitor swipe file"] },
  margo: { instructions: "Design offers and pricing for max LTV with low churn. Always model before you recommend.", sources: ["Pricing models", "Offer library", "Churn + LTV data"] },
  cole: { instructions: "Build and maintain GoHighLevel workflows across every account. Health-check daily; never let a client automation fail silently.", sources: ["GHL workflow library", "Webhook map", "Per-client GHL locations"] },
  ravi: { instructions: "Keep CPL down and reach up. Test small, kill losers fast, scale winners.", sources: ["Ad accounts", "Creative swipe file", "SEO keyword map"] },
  juno: { instructions: "Write in the founder's voice. Draft → they approve → publish. Repurpose top performers relentlessly.", sources: ["Brand voice guide", "Content pillars", "Top-performer archive"] },
  max: { instructions: "Reply to DMs in the founder's voice. Qualify and hand hot leads to booking. Never promise what we can't deliver.", sources: ["DM playbook", "Brand voice guide", "Objection library"] },
  sage: { instructions: "Run the community with warmth. Post replays, triage threads, escalate refunds and edge cases.", sources: ["Community guidelines", "Replay archive", "FAQ + macros"] },
  quinn: { instructions: "Track cash, MRR and margins. Flag only what doesn't self-recover.", sources: ["Stripe + GHL billing", "P&L", "Per-client margins"] },
  soham: { instructions: "Hotfix first, root-cause second. Own deploys and integrations. Keep secrets rotated.", sources: ["GitHub repos", "Vercel projects", "Supabase schema", "Incident log"] },
};
AGENTS.forEach((a) => { a.kb = AGENT_KB[a.id] || { instructions: "", sources: [] }; });

/* Per-agent operating spec — Claude Managed Agent + MCP, tools, skills, environment */
const AGENT_CONFIG = {
  atlas: { model: "Claude Opus 4.1", mcp: "orchestrator-mcp", tools: ["Agent output bus", "Task router", "Brief composer", "Email (4pm send)"], skills: [{ n: "Assemble EOD brief", s: "ready" }, { n: "Route goal → specialist", s: "ready" }, { n: "Cross-account prioritization", s: "needs-build" }], guardrails: ["Escalates client-facing calls — never decides them", "No spend without your sign-off"], infra: ["Vercel cron (hourly + 5pm)", "Supabase — agency memory"], env: "Prod · agency-wide" },
  vera: { model: "Claude Opus 4.1", mcp: "marketing-mcp", tools: ["Content calendar", "Analytics", "Brand guidelines"], skills: [{ n: "Build go-to-market", s: "ready" }, { n: "Campaign performance review", s: "ready" }], guardrails: ["Stays on-brand", "Ties every push to a live launch"], infra: ["Supabase — campaign store"], env: "Prod · agency-wide" },
  margo: { model: "Claude Sonnet 4", mcp: "ghl-mcp", tools: ["GoHighLevel API", "Stripe", "LTV model"], skills: [{ n: "Model a pricing test", s: "ready" }, { n: "Order-bump builder", s: "needs-build" }], guardrails: ["Never changes live pricing without approval"], infra: ["Supabase — offers + LTV"], env: "Prod · per-client GHL (scoped)" },
  cole: { model: "Claude Sonnet 4", mcp: "ghl-mcp", tools: ["GoHighLevel API", "Webhooks", "Calendar"], skills: [{ n: "Build a workflow", s: "ready" }, { n: "Health-check automations", s: "ready" }, { n: "Migrate email templates", s: "needs-build" }], guardrails: ["Never deletes client data", "Tests in sandbox before prod"], infra: ["Vercel — webhook relays", "Supabase — workflow registry"], env: "Prod · per-client GHL (scoped)" },
  ravi: { model: "Claude Sonnet 4", mcp: "social-mcp", tools: ["Instagram / TikTok", "Distribution scheduler", "SEO / keyword API"], skills: [{ n: "Distribute top performer", s: "ready" }, { n: "Keyword gap scan", s: "ready" }], guardrails: ["Posts on-brand only", "Hands paid ads to a partner"], infra: ["Supabase — distribution log"], env: "Prod · per-client social" },
  juno: { model: "Claude Sonnet 4", mcp: "content-mcp", tools: ["Brand voice KB", "Google Docs", "Repurposer"], skills: [{ n: "Draft → approve → publish", s: "ready" }, { n: "Repurpose long-form → 9 assets", s: "ready" }], guardrails: ["Writes in the founder's voice", "Nothing publishes without approval"], infra: ["Supabase — content archive"], env: "Prod · agency + per-client" },
  max: { model: "Claude Sonnet 4", mcp: "social-mcp", tools: ["IG / Messenger API", "Community inbox", "Booking flow"], skills: [{ n: "Draft DM replies", s: "ready" }, { n: "Qualify & hand off a lead", s: "ready" }, { n: "Auto-reply low-risk (per trust)", s: "needs-build" }], guardrails: ["Never promises what we can't deliver", "Hands hot leads to sales"], infra: ["Supabase — DM threads + voice"], env: "Prod · per-client social" },
  sage: { model: "Claude Sonnet 4", mcp: "ghl-mcp", tools: ["Community API", "Replay archive", "FAQ macros"], skills: [{ n: "Post a call replay", s: "ready" }, { n: "Triage threads", s: "ready" }], guardrails: ["Escalates refunds & edge cases", "Warm, on-brand tone"], infra: ["Supabase — community state"], env: "Prod · per-client community" },
  quinn: { model: "Claude Sonnet 4", mcp: "finance-mcp", tools: ["Stripe", "GHL billing", "P&L sheet"], skills: [{ n: "Daily cash snapshot", s: "ready" }, { n: "Dunning recovery", s: "ready" }], guardrails: ["Read-only on funds", "Flags only what doesn't self-recover"], infra: ["Vercel cron (6am)", "Supabase — ledger"], env: "Prod · agency + per-client billing" },
  soham: { model: "Claude Opus 4.1", mcp: "dev-mcp", tools: ["GitHub", "Vercel", "Supabase admin", "Sentry"], skills: [{ n: "Hotfix + root-cause", s: "ready" }, { n: "Build a custom integration", s: "ready" }, { n: "Secret rotation", s: "needs-build" }], guardrails: ["Hotfix first, root-cause second", "No prod deploy without a smoke test"], infra: ["GitHub Actions", "Vercel", "Supabase"], env: "Prod + staging · all repos" },
};
AGENTS.forEach((a) => { a.config = AGENT_CONFIG[a.id] || { model: "Claude Sonnet 4", mcp: "core-mcp", tools: [], skills: [], guardrails: [], infra: [], env: "Prod" }; });

window.HQ_DATA = { PILLARS, AGENTS, CLIENTS, CONTEXT, AUTOMATION, AUTOMATIONS_LIST };