// @bun
// src/components/docs/libraries/LibrariesWorkflowsPage.tsx
import { CodeBlock, InstallCommand } from "@contractspec/lib.design-system";
import Link from "@contractspec/lib.ui-link";
import { ChevronRight } from "lucide-react";
import { jsx, jsxs } from "react/jsx-runtime";
function LibrariesWorkflowsPage() {
  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: "Workflow Runtime Library"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground text-lg",
            children: [
              "The ",
              /* @__PURE__ */ jsx("code", {
                children: "@contractspec/lib.contracts-spec/workflow"
              }),
              " library provides the core ",
              /* @__PURE__ */ jsx("code", {
                children: "WorkflowRunner"
              }),
              " for executing stateful, durable workflows."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Installation"
          }),
          /* @__PURE__ */ jsx(InstallCommand, {
            package: "@contractspec/lib.contracts-spec"
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "WorkflowRunner"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "The runner manages execution state, step transitions, retries, and compensation."
          }),
          /* @__PURE__ */ jsx(CodeBlock, {
            language: "typescript",
            code: `import { WorkflowRunner } from '@contractspec/lib.contracts-spec/workflow/runner';
import { InMemoryStateStore } from '@contractspec/lib.contracts-spec/workflow/adapters/memory-store';
import { WorkflowRegistry } from '@contractspec/lib.contracts-spec/workflow/spec';

const registry = new WorkflowRegistry();
registry.register(MyWorkflow);

const runner = new WorkflowRunner({
  registry,
  stateStore: new InMemoryStateStore(),
  opExecutor: async (op, input, ctx) => {
    // Execute operation using your adapter (REST, GraphQL, etc.)
    return await myAdapter.execute(op, input);
  },
});

// Start a workflow
const workflowId = await runner.start('my.workflow', 1, { userId: '123' });

// Execute next step (usually called by a worker or queue consumer)
await runner.executeStep(workflowId);`
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "State Persistence"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "The runner relies on a ",
              /* @__PURE__ */ jsx("code", {
                children: "StateStore"
              }),
              " to persist workflow execution history. ContractSpec ships with:"
            ]
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-disc space-y-2 pl-6",
            children: [
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("code", {
                    children: "InMemoryStateStore"
                  }),
                  " - for testing and development."
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("code", {
                    children: "PrismaStateStore"
                  }),
                  " - for production using Prisma ORM."
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Events"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "The runner emits events that you can subscribe to for monitoring:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-disc space-y-2 pl-6",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.started"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.step_completed"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.step_failed"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.step_retrying"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.completed"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.cancelled"
                })
              }),
              /* @__PURE__ */ jsx("li", {
                children: /* @__PURE__ */ jsx("code", {
                  children: "workflow.compensation_step_completed"
                })
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "flex items-center gap-4 pt-4",
        children: [
          /* @__PURE__ */ jsx(Link, {
            href: "/docs/libraries",
            className: "btn-ghost",
            children: "Back to Libraries"
          }),
          /* @__PURE__ */ jsxs(Link, {
            href: "/docs/libraries/data-views",
            className: "btn-primary",
            children: [
              "Next: Data Views ",
              /* @__PURE__ */ jsx(ChevronRight, {
                size: 16
              })
            ]
          })
        ]
      })
    ]
  });
}
export {
  LibrariesWorkflowsPage
};
