import {
  Card,
  CardBody,
  CardHeader,
  Divider,
  Grid,
  H1,
  H2,
  H3,
  Pill,
  Row,
  Stack,
  Stat,
  Table,
  Text,
} from "cursor/canvas";

const metrics = [
  { value: "600k-700k", label: "tickets per year", tone: "info" as const },
  { value: "50k-58k", label: "tickets per month", tone: "info" as const },
  { value: "~100k", label: "MSP RMM endpoints", tone: "warning" as const },
  { value: "300-400", label: "ServiceNow users", tone: "success" as const },
  { value: "25", label: "AI-displaceable roles in 12 months", tone: "danger" as const },
  { value: "10/min", label: "Zofiq agent throughput cap", tone: "warning" as const },
];

const stackRows = [
  ["ITSM / CSM", "ServiceNow", "Core platform for incidents, requests, routing, assignment, auto-close notes, incident summarization, and Now Assist triage."],
  ["Monitoring", "LogicMonitor", "Alert suppression, correlation, diagnostic suggestions, root-cause hints, and ServiceNow ticket updates or auto-resolution."],
  ["RMM", "N-central", "Current RMM for MSP fleet; renewal / review timing uncertain, but prior ConnectWise RMM review was dismissed due to ServiceNow integration gap."],
  ["Contact center", "Genesys", "Part of the service delivery stack, but not deeply discussed for AI workflow replacement."],
  ["Automation / agents", "LangSmith Fleet POC", "Planned enterprise agent-building layer for M365, back office, ServiceNow, SharePoint, CRM, and customer reporting workflows."],
  ["Models", "Claude, Copilot, Anthropic via AWS", "Frontier-model approach for complex work; cost and model-quality trade-offs are an active concern."],
];

const competitorRows = [
  ["ServiceNow Now Assist / AI Agents", "Incident summarization, resolution notes, chat/email recommendations, incident assist, categorization, assignment group routing, AI Search, AI Agent Studio workflows, and native ITSM context.", "Very strong inside ServiceNow. It is the incumbent workflow layer and Mike already has triage, assignment, categorization, auto-close notes, and incident summaries in place."],
  ["LogicMonitor Edwin AI", "Alert deduplication, event correlation, topology-aware enrichment, root-cause analysis, blast-radius analysis, incident summaries, remediation suggestions, and governed automation via existing tools.", "Strong for monitoring-originated incidents. It can pre-process noise before tickets hit ServiceNow and update or auto-resolve tickets when telemetry changes."],
  ["LangSmith / LangChain platform", "Agent observability, traces, evals, prompt/version management, human annotation, cost/latency/error monitoring, deployment runtime, human-in-the-loop, multi-agent coordination, and self-hosted options.", "Strong as their internal AI engineering control plane. It is not an MSP PSA product by itself; value comes from their team building workflows on top of it."],
];

const zofiqRows = [
  ["Copilot Assistant", "Embedded ConnectWise pod and standalone app with ticket autofetch, blindspot insights, path to resolution, follow-up prompts, ticket summaries, file/image analysis, web lookup, time entry, KB links, like tickets, and RMM device context."],
  ["Learning and context", "The documentation says agents use historical PSA patterns, current ticket context, SOPs, and configured knowledge sources. Managers can also create AI Assistants and Knowledge Bases by uploading documents. This is contextual learning/configuration, not documented partner-built automatic agent creation."],
  ["Ticket lifecycle agents", "Company, urgency/impact/priority, board/type/subtype/item, contact, agreement, dispatch, and summary-line agents write back to ConnectWise with configured scope and SOP guardrails."],
  ["Dispatch depth", "Can assign owner/team/status, evaluate calendars, in/out board, workload, team membership, historical success, pod mapping documents, and optionally create calendar slots."],
  ["Control model", "Shadow Mode, simulations, workflow logs, reasoning, audit trail visibility, one-run-per-ticket behavior, human-edit conflict halt, and per-agent enablement reduce rollout risk."],
  ["Ops reporting", "Insights Agent gives trend reports; Oversight Agent flags breached or near-breach tickets based on ConnectWise SLA states."],
];

const integrationRows = [
  ["ServiceNow to ConnectWise PSA bridge", "Recursyv is being explored as a fully managed service-desk integration provider to sync selected ServiceNow ticket/data flows into ConnectWise PSA."],
  ["Coexistence value", "This lets Nexon keep ServiceNow as the front-end system while ConnectWise PSA provides the ticket record Zofiq needs to run supported PSA workflows."],
  ["Change-management benefit", "The option avoids forcing a full ServiceNow migration before proving whether ConnectWise/Zofiq creates operational value."],
  ["Sync design focus", "The ServiceNow <> ConnectWise PSA mapping must define which system owns each field, which ticket types sync, how notes/status/priority/assignment/closure sync, and how duplicate or conflicting updates are prevented."],
  ["Operational dependency", "Zofiq value depends on the synced ConnectWise PSA ticket being complete enough for supported Copilot and Agent workflows to classify, route, dispatch, summarize, and report against it."],
];

const strategyRows = [
  ["AI program", "Business case is already modeled; objective is profitability, market currency, retention, and workforce replacement over one to two years."],
  ["Hiring", "Recruiting a team of five for AI. This is not exploratory; they are building internal capability."],
  ["Workforce target", "25 roles identified in the next 12 months, with about 15 in core MSP service delivery."],
  ["Automation target", "They believe they have already removed about 20% of L1/L2 work and have another 20% targeted."],
  ["Primary use cases", "M365 automations and customer reporting are the two main AI streams already planned."],
  ["Data approach", "They have run analytics across ticket data to identify automation candidates and believe they know what is achievable."],
  ["Platform posture", "Strong preference not to add platforms unless they solve problems ServiceNow plus Fleet cannot solve."],
];

const gapRows = [
  ["ConnectWise PSA / ServiceNow", "ServiceNow integration", "Must prove tight read/write integration with ServiceNow. Without it, the opportunity stalls."],
  ["Zofiq", "Differentiated workflows", "M365 automation and reporting are already covered in their plan; ConnectWise needs use cases beyond generic triage or dispatch."],
  ["Zofiq / N-central", "RMM fit", "N-central integration is not documented in the Zofiq KBs reviewed. If Nexon keeps N-central, Zofiq's documented RMM context features may not apply unless support is confirmed separately."],
  ["Zofiq", "Knowledge workflow", "Zofiq can surface documentation and use uploaded KB context, but the docs reviewed do not show KB write-back or automated documentation maintenance."],
  ["Zofiq / ConnectWise PSA", "Cross-company PSA analysis", "Copilot appears focused on the current ticket/company context. It should not be positioned as a PSA-wide business analysis tool that can freely compare trends, performance, or operational patterns across all companies in chat."],
  ["Zofiq", "Agent creation", "The documentation describes configuring available agents, trigger conditions, outcome controls, and SOPs. It does not describe partners creating their own custom agents that run automatically."],
  ["Zofiq", "Model transparency", "The documentation reviewed does not state which LLMs, SLMs, or model providers Zofiq uses for Copilot or Agents. This remains a direct product/security/commercial question."],
  ["Zofiq", "Throughput and burst handling", "Zofiq's documented ConnectWise agent throughput is up to 10 tickets/minute. If a burst exceeds capacity, Zofiq prioritizes newer tickets; older skipped tickets remain untouched and are not automatically retried."],
  ["Zofiq / ConnectWise PSA", "Feedback submission/recovery", "If an engineer submits incorrect feedback or a live agent overwrites a PSA field incorrectly, there is no documented native revert button. Recovery should be assumed to require manual correction using PSA history/logs."],
  ["Zofiq / ConnectWise Platform", "Data residency", "Australian data residency and processing are explicit requirements. APAC/Australia availability from July 1 is important but must be evidenced."],
  ["Zofiq", "Quality vs cost", "They believe frontier models are worth paying for on complex work and cheaper models belong on simpler work."],
  ["Zofiq", "Token economics", "Their token bill is rising. Zofiq per-ticket pricing is a strong commercial counterpoint if outcomes are comparable."],
  ["ConnectWise RMM", "RMM replacement", "N-central displacement is a separate play, but ServiceNow integration is the critical unlock for revisiting it."],
];

function SectionTable({
  headers,
  rows,
}: {
  headers: string[];
  rows: string[][];
}) {
  return <Table headers={headers} rows={rows} striped />;
}

export default function NexonConnectWiseZofiqBusinessCase() {
  return (
    <Stack gap={20} style={{ padding: 20, maxWidth: 1180, margin: "0 auto" }}>
      <Stack gap={8}>
        <Row gap={8} wrap>
          <Pill tone="info" active>Business case view</Pill>
          <Pill tone="warning">Source: May 27 transcript</Pill>
          <Pill>MSP operations only</Pill>
        </Row>
        <H1>Nexon Automation Strategy Fit</H1>
        <Text tone="secondary">
          The current stack is mature and intentional. The strongest ConnectWise motion is not "replace everything now";
          it is to prove Zofiq can reduce ServiceNow-attached MSP effort faster, with simpler economics and Australian data handling.
        </Text>
      </Stack>

      <Grid columns={3} gap={12}>
        {metrics.map((metric) => (
          <Stat key={metric.label} value={metric.value} label={metric.label} tone={metric.tone} />
        ))}
      </Grid>

      <Card size="lg">
        <CardHeader trailing="Key read">How we fare</CardHeader>
        <CardBody>
          <Stack gap={10}>
            <Text>
              ConnectWise has a credible wedge if Recursyv can sync the right ServiceNow tickets into ConnectWise PSA and Zofiq is kept to its documented strengths: predefined PSA ticket lifecycle agents, Copilot assistance, workflow logs, simulations, and controlled write-back.
            </Text>
            <Text>
              The fit is weaker if positioned as a replacement for Nexon's broader LangSmith/Fleet strategy. Zofiq does not appear to provide partner-built automatic agents, N-central integration, KB write-back, cross-company PSA analysis in chat, or disclosed model selection in the reviewed docs.
            </Text>
            <Divider />
            <Text weight="semibold">Best initial thesis</Text>
            <Text tone="secondary">
              "Keep ServiceNow as the front-end system, use Recursyv to sync selected tickets into ConnectWise PSA, and use Zofiq only where its prebuilt PSA agents can reduce triage, classification, dispatch, summary, oversight, and technician-assist effort."
            </Text>
          </Stack>
        </CardBody>
      </Card>

      <H2>Current Tooling</H2>
      <SectionTable headers={["Area", "Current tool", "Observed role"]} rows={stackRows} />

      <H2>Strategy And Hiring</H2>
      <SectionTable headers={["Signal", "What it means"]} rows={strategyRows} />

      <H2>What Their Three AI Layers Can Do</H2>
      <SectionTable headers={["AI layer", "Actual capabilities", "Competitive read"]} rows={competitorRows} />

      <H2>What Zofiq Can Credibly Counter With</H2>
      <SectionTable headers={["Zofiq capability", "Relevant detail"]} rows={zofiqRows} />

      <H2>Recursyv Coexistence Option And Capacity Read</H2>
      <SectionTable headers={["Area", "Assessment"]} rows={integrationRows} />

      <H2>Gaps And Objections</H2>
      <SectionTable headers={["Technology", "Gap", "Why it matters"]} rows={gapRows} />

    </Stack>
  );
}
