# A plan card in five minutes

> A page with a plan card, its agreement, the run and its proof, first with the fake client, then with the owner's server.

A page that shows what a run would install, asks for the owner's yes, follows the run and says what the proof found.
First with the fake client of the library (nothing runs anywhere), then against the owner's server.

You need the repository and its dependencies (`npm install`). The packages are not published yet: the example imports
them from `packages/`.

## 1. The page

Three elements inside an `<alta-provider>`, which gives them a theme, a colour scheme and a language:

```html [examples/ui/plan-card/index.html]
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>A plan card</title>
  <style>body { margin: 0; padding: 32px; font-family: system-ui, sans-serif; } main { max-width: 520px; display: grid; gap: 16px; }</style>
</head>
<body>
  <main>
    <alta-provider theme="alta" scheme="light" lang="en">
      <alta-plan-card></alta-plan-card>
      <alta-run-progress what="the install"></alta-run-progress>
      <alta-proof-badge proof-role="installed"></alta-proof-badge>
    </alta-provider>
  </main>
  <script type="module" src="./main.ts"></script>
</body>
</html>
```

## 2. One run, three views

The card, the progress and the badge draw the same run: one store, made by `createRunStore`, given to each with
`use(store)`. `auto: true` asks for the plan at once. The card draws its own agreement: nothing runs before the click.

```ts [examples/ui/plan-card/main.ts]
// A plan card on a page (docs-site/ui/quickstart.md). Run it from the repository: npx vite examples/ui/plan-card
// With ?server=1&t=<token> it talks to the owner's server that serves the page; without it, to the fake client of the
// library, which plays a whole run: plan, agree, run, proof.
import "../../../packages/ui/styles/index.css";
import "../../../packages/ui/styles/themes/alta.css";
import "../../../packages/ui/src/register";
import { createAltaClient, createRunStore } from "../../../packages/ui-core/src/index";
import { createFakeClient } from "../../../packages/ui-core/src/testing/fake-client";

const q = new URLSearchParams(location.search);
const client = q.get("server") ? createAltaClient({ token: q.get("t") ?? "" }) : createFakeClient("ok");

// One run, three views of it: the card plans at once (auto), its agreement starts the run, the progress follows it,
// the badge says what the proof found.
const store = createRunStore({ client, target: { executor: "setup.base", args: {} }, auto: true });
for (const tag of ["alta-plan-card", "alta-run-progress", "alta-proof-badge"]) {
  (document.querySelector(tag) as HTMLElement & { use(s: unknown): void }).use(store);
}

// What they say, as events.
for (const name of ["alta-plan", "alta-agreed", "alta-run-done", "alta-proof"]) {
  document.addEventListener(name, e => console.log(name, (e as CustomEvent).detail));
}
```

## 3. Run it

```sh
npx vite examples/ui/plan-card
```

Open the address Vite prints. The card lists what it installs and what it costs; **Install** starts the fake run; the
progress goes to **Done.**; the badge says **Proven by the machine**. The console shows `alta-plan`, `alta-run-done`
and `alta-proof`.

## 4. Against the owner's server

On a page served by the owner's own server, the client is `createAltaClient({ token })`: the same routes the game
uses (`/api/runs/plan`, `/api/runs/run`, `/api/runs/:id`), the token in the `X-World-Token` header. Open the example
with `?server=1&t=<token>` from a page of that server. The target can be an executor with its arguments, as here, or
a quest step: `{ quest: "core.wake", step: "base" }`, and the server reads the step's arguments itself.

Nothing changes in the page: the same elements, the same events.

## Next

- [Theming](https://docs.altasystem.ai/ui/theming): the same card in your own look.
- [Secrets](https://docs.altasystem.ai/ui/secrets): a step that needs a key.
- [Every component](https://docs.altasystem.ai/ui/components/).
