// src/components/docs/advanced/AdvancedSpecExperimentsPage.tsx
import { jsx, jsxs } from "react/jsx-runtime";
function AdvancedSpecExperimentsPage() {
  return /* @__PURE__ */ jsxs("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h1", {
            className: "text-4xl font-bold",
            children: "Spec Experiments"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground text-lg",
            children: "Run controlled experiments on ContractSpec operations, gradually shift traffic, and roll back automatically when guardrails trip."
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Define control + variants"
          }),
          /* @__PURE__ */ jsx("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import { SpecExperimentRegistry } from '@contractspec/lib.growth/spec-experiments';

const registry = new SpecExperimentRegistry().register({
  target: { name: 'billing.createInvoice', version: 4 },
  experiment: {
    key: 'billing.createInvoice.evolution',
    version: '1.0.0',
    goal: 'Reduce PO validation failures',
    primaryMetric: 'latency_ms',
    variants: [
      { id: 'control' },
      { id: 'po-required', description: 'Force PO field', weight: 1 },
    ],
  },
  control: BillingCreateInvoiceV4,
  variants: [
    { id: 'po-required', spec: BillingCreateInvoiceForAcme },
  ],
  rolloutStages: [0.01, 0.1, 0.5, 1],
  guardrails: { errorRateThreshold: 0.02, latencyP99ThresholdMs: 500 },
});`
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Attach to runtime"
          }),
          /* @__PURE__ */ jsx("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import { createSpecVariantResolver } from '@contractspec/lib.growth/spec-experiments';

adapterContext.specVariantResolver = createSpecVariantResolver({
  adapter,
  resolveUserId: (ctx) => ctx.userId ?? ctx.organizationId ?? 'anon',
});`
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Track outcomes + auto-rollback"
          }),
          /* @__PURE__ */ jsx("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import {
  SpecExperimentAnalyzer,
  SpecExperimentController,
} from '@contractspec/lib.growth/spec-experiments';

const analyzer = new SpecExperimentAnalyzer(tracker);
const controller = new SpecExperimentController({
  registry,
  analyzer,
  onRollback: (target, evaluation) => notifyOps(target, evaluation.reasons),
});`
          })
        ]
      }),
      /* @__PURE__ */ jsx("div", {
        className: "grid gap-4 md:grid-cols-2",
        children: [
          {
            title: "Deterministic bucketing",
            description: "ExperimentRunner reuses the same hashing logic as growth experiments—every user sticks to a variant."
          },
          {
            title: "Multi-stage rollouts",
            description: "Use `rolloutStages` to shift 1% → 10% → 50% → 100%. Guardrails trigger rollbacks automatically."
          }
        ].map((card) => /* @__PURE__ */ jsxs("div", {
          className: "card-subtle space-y-2 p-4",
          children: [
            /* @__PURE__ */ jsx("h3", {
              className: "text-lg font-semibold",
              children: card.title
            }),
            /* @__PURE__ */ jsx("p", {
              className: "text-muted-foreground text-sm",
              children: card.description
            })
          ]
        }, card.title))
      })
    ]
  });
}
export {
  AdvancedSpecExperimentsPage
};
