// tickets-data.jsx — Ticket data, channels, severities, statuses

const TICKET_CHANNELS = [
  { id: "email",    label: "Email",        icon: "Inbox",    color: "#0073ea" },
  { id: "form",     label: "Web form",     icon: "Table",    color: "#a25ddc" },
  { id: "slack",    label: "Slack",        icon: "MessageSq",color: "#611f69" },
  { id: "internal", label: "Internal",     icon: "Users",    color: "#037f4c" },
  { id: "github",   label: "GitHub",       icon: "GitBranch",color: "#1f1f1f" },
  { id: "zendesk",  label: "Zendesk",      icon: "Help",     color: "#03363d" },
];

// Severity is from the CUSTOMER perspective — different from internal task priority
const TICKET_SEVERITIES = [
  { id: "p0", label: "P0 · Critical",  cls: "sev-p0", short: "P0" },
  { id: "p1", label: "P1 · High",      cls: "sev-p1", short: "P1" },
  { id: "p2", label: "P2 · Medium",    cls: "sev-p2", short: "P2" },
  { id: "p3", label: "P3 · Low",       cls: "sev-p3", short: "P3" },
];

const TICKET_STATUSES = [
  { id: "new",       label: "New",       cls: "ts-new"       },
  { id: "triaging",  label: "Triaging",  cls: "ts-triaging"  },
  { id: "accepted",  label: "Accepted",  cls: "ts-accepted"  },
  { id: "waiting",   label: "Waiting",   cls: "ts-waiting"   },  // waiting on customer
  { id: "resolved",  label: "Resolved",  cls: "ts-resolved"  },
  { id: "rejected",  label: "Rejected",  cls: "ts-rejected"  },
  { id: "duplicate", label: "Duplicate", cls: "ts-duplicate" },
];

// SLA targets (first-response & resolution) per severity, in hours
const SLA_TARGETS = {
  p0: { firstResp: 1,  resolve: 8   },
  p1: { firstResp: 4,  resolve: 24  },
  p2: { firstResp: 24, resolve: 72  },
  p3: { firstResp: 48, resolve: 168 },
};

// Mock tickets — mix of channels, severities, statuses, some converted to tasks
const TICKETS = [
  {
    id: "TICK-412", subject: "Checkout fails on Safari 17 — 'Payment method invalid'",
    requester: { name: "Mei Tanaka",      email: "mei.tanaka@nova-retail.com", company: "Nova Retail" },
    channel: "email",    severity: "p0", status: "accepted",
    openedAt: "2026-04-22 09:14", firstResponseAt: "2026-04-22 09:32",
    assignee: "mj", project: "checkout",
    slaFirstResp: "met", slaResolve: "at-risk",
    linkedTasks: ["t02", "t03"],
    thread: [
      { from: "Mei Tanaka", role: "customer", at: "09:14", body: "Our whole team is blocked. When I click Pay, I get 'Payment method invalid' even with a valid card. Started ~30 min ago. Chrome works, Safari 17.4 doesn't." },
      { from: "Aya Okafor", role: "internal", at: "09:32", body: "Thanks Mei — this looks like the Safari Apple Pay regression we saw in staging. Assigning to Marcus now." },
      { from: "Marcus Jin", role: "internal", at: "09:41", body: "Confirmed — PaymentRequest API is returning the wrong merchant ID on Safari 17.4+. Patching now." },
    ],
    tags: ["safari", "payments", "regression"],
  },
  {
    id: "TICK-411", subject: "Can you add GDPR deletion self-serve?",
    requester: { name: "Jonas Voight", email: "jvoight@orbit-partners.eu", company: "Orbit Partners" },
    channel: "form",     severity: "p2", status: "triaging",
    openedAt: "2026-04-22 08:02",   firstResponseAt: "2026-04-22 11:18",
    assignee: "hl", project: null,
    slaFirstResp: "met", slaResolve: "on-track",
    linkedTasks: [],
    thread: [
      { from: "Jonas Voight", role: "customer", at: "Apr 22 08:02", body: "We need a self-serve data deletion flow for users in the EU. Currently we have to email support. Target: 30-day auto-delete after request." },
      { from: "Hannah Liu",   role: "internal", at: "Apr 22 11:18", body: "Great request — this is on our roadmap for Q3. Can I get a rough sense of how many deletion requests you field per week?" },
    ],
    tags: ["gdpr", "feature-request"],
  },
  {
    id: "TICK-410", subject: "Mobile app crashes on Android 14 when tapping 'Add payment method'",
    requester: { name: "Carlos Dias",  email: "carlos@fintwist.io",   company: "FinTwist" },
    channel: "zendesk",  severity: "p1", status: "accepted",
    openedAt: "2026-04-22 07:45",   firstResponseAt: "2026-04-22 08:12",
    assignee: "pr", project: "mobile",
    slaFirstResp: "met", slaResolve: "on-track",
    linkedTasks: ["t08"],
    thread: [
      { from: "Carlos Dias",  role: "customer", at: "07:45", body: "App crashes instantly when I tap Add payment method on Android 14 (Pixel 8). Stack trace attached." },
      { from: "Priya Ramesh", role: "internal", at: "08:12", body: "Thanks for the trace. Reproduced. Pushing a fix in today's build (2.14.3)." },
    ],
    tags: ["android", "crash", "payments"],
  },
  {
    id: "TICK-409", subject: "Feature request: bulk invoice export as CSV",
    requester: { name: "Ina Schmidt", email: "i.schmidt@helix-finance.de", company: "Helix Finance" },
    channel: "email",    severity: "p3", status: "new",
    openedAt: "2026-04-22 11:22",   firstResponseAt: null,
    assignee: null, project: null,
    slaFirstResp: "breached", slaResolve: "on-track",
    linkedTasks: [],
    thread: [
      { from: "Ina Schmidt", role: "customer", at: "11:22", body: "We'd love a way to export multiple invoices at once as a single CSV (or ZIP of PDFs). Right now it's one-by-one which doesn't scale for month-end close." },
    ],
    tags: ["export", "invoices", "feature-request"],
  },
  {
    id: "TICK-408", subject: "Double-charge on subscription renewal",
    requester: { name: "Ava Park",  email: "ava@parkstudio.com",    company: "Park Studio" },
    channel: "email",    severity: "p1", status: "resolved",
    openedAt: "2026-04-21 14:08",   firstResponseAt: "2026-04-21 14:34", resolvedAt: "2026-04-22 09:10",
    assignee: "nk", project: "checkout",
    slaFirstResp: "met", slaResolve: "met",
    linkedTasks: ["t14"],
    thread: [
      { from: "Ava Park",       role: "customer", at: "Apr 21 14:08", body: "I was charged twice for my Pro plan renewal on April 20. Invoice IDs INV-22841 and INV-22842." },
      { from: "Nadia Kowalski", role: "internal", at: "Apr 21 14:34", body: "Confirmed — refunding INV-22842 today. You should see it in 3–5 business days. Our engineering team is fixing the root cause." },
      { from: "Nadia Kowalski", role: "internal", at: "Apr 22 09:10", body: "Refund processed, root-cause task linked. Closing ticket — let us know if you don't see the refund by Fri." },
    ],
    tags: ["billing", "refund"],
  },
  {
    id: "TICK-407", subject: "How do I rotate my API key?",
    requester: { name: "Dev Patel",   email: "dev@switchboard.dev",   company: "Switchboard" },
    channel: "slack",    severity: "p3", status: "resolved",
    openedAt: "2026-04-22 10:01",   firstResponseAt: "2026-04-22 10:04", resolvedAt: "2026-04-22 10:11",
    assignee: "df", project: "platform",
    slaFirstResp: "met", slaResolve: "met",
    linkedTasks: [],
    thread: [
      { from: "Dev Patel",   role: "customer", at: "10:01", body: "Where's the API key rotation in the dashboard? Can't find it." },
      { from: "Dmitri Falk", role: "internal", at: "10:04", body: "Settings → Developers → API keys → 'Rotate' on the row. Doc: /docs/api-keys#rotate. Let me know if you hit any issues!" },
    ],
    tags: ["docs", "api"],
  },
  {
    id: "TICK-406", subject: "Timezone wrong on scheduled reports",
    requester: { name: "Raji Kumar",  email: "raji@luminaux.ai",      company: "Luminaux" },
    channel: "form",     severity: "p2", status: "triaging",
    openedAt: "2026-04-22 06:30",   firstResponseAt: "2026-04-22 10:12",
    assignee: "le", project: null,
    slaFirstResp: "met", slaResolve: "on-track",
    linkedTasks: [],
    thread: [
      { from: "Raji Kumar",    role: "customer", at: "06:30", body: "My scheduled weekly report is arriving at 2 AM IST instead of the 9 AM IST I configured. Something is off in timezone handling." },
      { from: "Leo Esposito",  role: "internal", at: "10:12", body: "Looking now — what's the exact timezone string in your settings? (India Standard Time vs 'Asia/Kolkata')" },
    ],
    tags: ["reports", "timezone"],
  },
  {
    id: "TICK-405", subject: "SSO fails with Okta SCIM provisioning",
    requester: { name: "Brooke Hill", email: "bhill@wessex-health.com",company: "Wessex Health" },
    channel: "email",    severity: "p1", status: "accepted",
    openedAt: "2026-04-22 05:58",   firstResponseAt: "2026-04-22 06:40",
    assignee: "hl", project: "platform",
    slaFirstResp: "met", slaResolve: "on-track",
    linkedTasks: ["t11"],
    thread: [
      { from: "Brooke Hill", role: "customer", at: "05:58", body: "Our Okta SCIM provisioning is failing with a 401 since yesterday. 60+ new users blocked." },
      { from: "Hannah Liu",  role: "internal", at: "06:40", body: "Urgent — our Okta cert rotated and your tenant didn't pick up the new one. I'll cut a fix ticket; your tenant will be re-provisioned within 4 hours." },
    ],
    tags: ["sso", "okta", "enterprise"],
  },
  {
    id: "TICK-404", subject: "Checkout broken on old iOS Safari (same as TICK-412)",
    requester: { name: "Kim Schulz", email: "kim@north-star.shop",   company: "North Star" },
    channel: "email",    severity: "p1", status: "duplicate",
    openedAt: "2026-04-22 09:58",   firstResponseAt: "2026-04-22 10:04",
    assignee: "ay", project: null,
    slaFirstResp: "met", slaResolve: "met",
    linkedTasks: [],
    duplicateOf: "TICK-412",
    thread: [
      { from: "Kim Schulz",   role: "customer", at: "09:58", body: "Can't check out on Safari. Payment button doesn't work." },
      { from: "Aya Okafor",   role: "internal", at: "10:04", body: "Thanks Kim — this is a duplicate of a ticket we're actively fixing right now (ETA <2 hours). We'll notify you when resolved." },
    ],
    tags: ["safari", "duplicate"],
  },
  {
    id: "TICK-403", subject: "Export to Xero — mapping error on tax field",
    requester: { name: "Oliver Wren", email: "oliver@boundlessco.au",company: "Boundless Co" },
    channel: "zendesk",  severity: "p2", status: "new",
    openedAt: "2026-04-22 11:47",   firstResponseAt: null,
    assignee: null, project: null,
    slaFirstResp: "on-track", slaResolve: "on-track",
    linkedTasks: [],
    thread: [
      { from: "Oliver Wren", role: "customer", at: "11:47", body: "When I export a paid invoice to Xero, the GST field maps to the wrong account. Attaching screenshots and the Xero mapping config." },
    ],
    tags: ["integrations", "xero", "tax"],
  },
  {
    id: "TICK-402", subject: "Request: webhook for invoice.paid event",
    requester: { name: "Sam Rivera", email: "sam@halo-ops.io",       company: "Halo Ops" },
    channel: "github",   severity: "p3", status: "rejected",
    openedAt: "2026-04-20 14:22",   firstResponseAt: "2026-04-21 11:00", resolvedAt: "2026-04-21 11:00",
    assignee: "mj", project: null,
    slaFirstResp: "met", slaResolve: "met",
    linkedTasks: [],
    thread: [
      { from: "Sam Rivera",  role: "customer", at: "Apr 20 14:22", body: "Please add an invoice.paid webhook so we can sync paid invoices to our ERP in real time." },
      { from: "Marcus Jin",  role: "internal", at: "Apr 21 11:00", body: "Thanks Sam — we already ship invoice.paid; see /docs/webhooks#invoice-events. Closing as not needed. Let me know if something's not working with the existing event!" },
    ],
    tags: ["webhooks", "docs"],
  },
  {
    id: "TICK-401", subject: "Internal: staging env broken — can't deploy",
    requester: { name: "Leo Esposito", email: "leo.e@acme.co", company: "Internal" },
    channel: "internal", severity: "p1", status: "accepted",
    openedAt: "2026-04-22 10:30", firstResponseAt: "2026-04-22 10:32",
    assignee: "df", project: "platform",
    slaFirstResp: "met", slaResolve: "on-track",
    linkedTasks: ["t21"],
    thread: [
      { from: "Leo Esposito", role: "customer", at: "10:30", body: "staging-web won't accept deploys since ~10:15. Getting 'image pull backoff' on every service." },
      { from: "Dmitri Falk",  role: "internal", at: "10:32", body: "On it — registry creds expired. Rotating now, should be back in ~15m." },
    ],
    tags: ["infra", "staging"],
  },
];

Object.assign(window, { TICKETS, TICKET_CHANNELS, TICKET_SEVERITIES, TICKET_STATUSES, SLA_TARGETS });
