zc2 0.0.52

P2P compute broker with yen-denominated billing, WAL, and broker mesh support
import type React from "react";
import type { ButtonHTMLAttributes, ReactNode } from "react";

const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");

/** The zakuro mark: the zakuro-ai.com fruit (same contour as macos/…/Pomegranate.swift), in a 1×1 box.
 * Hollow cuts out the body's largest inscribed circle, less a 0.07 wall. */
export function Pomegranate({ className, hollow = false }: { className?: string; hollow?: boolean }) {
  const d =
    "M0.4969 0L0.4885 0.0063L0.4781 0.0209L0.4468 0.0835L0.4322 0.1253L0.4322 0.1315L0.428 0.1399L0.428 0.1461L0.4238 0.1545L0.4238 0.1608L0.4071 0.2129L0.4029 0.2109L0.4029 0.2025L0.4008 0.2004L0.4008 0.1461L0.4029 0.1441L0.4029 0.1336L0.3612 0.1106L0.3319 0.1002L0.3257 0.1002L0.309 0.0939L0.2902 0.0919L0.2881 0.0898L0.2693 0.0898L0.2672 0.0919L0.2672 0.1106L0.2693 0.1127L0.2777 0.1524L0.2839 0.167L0.2839 0.1733L0.2881 0.1795L0.2944 0.2004L0.3048 0.2192L0.3048 0.2234L0.3194 0.2484L0.3194 0.2526L0.2923 0.2693L0.2463 0.3069L0.1942 0.3591L0.1712 0.3883L0.1545 0.4154L0.1399 0.4447L0.1378 0.4551L0.1294 0.4718L0.1148 0.5219L0.1148 0.5303L0.1106 0.5428L0.1106 0.5553L0.1086 0.5574L0.1086 0.5762L0.1065 0.5783L0.1065 0.6326L0.1086 0.6347L0.1086 0.6534L0.1106 0.6555L0.1127 0.6806L0.1148 0.6827L0.1148 0.691L0.1169 0.6931L0.1211 0.7161L0.1336 0.7537L0.1545 0.7996L0.1712 0.8267L0.2004 0.8622L0.2589 0.9186L0.2881 0.9415L0.3194 0.9582L0.3236 0.9624L0.3278 0.9624L0.3382 0.9687L0.3779 0.9833L0.3841 0.9833L0.4196 0.9937L0.4426 0.9958L0.4447 0.9979L0.4635 0.9979L0.4656 1L0.5324 1L0.5344 0.9979L0.5532 0.9979L0.5553 0.9958L0.5658 0.9958L0.5678 0.9937L0.5783 0.9937L0.5887 0.9896L0.5971 0.9896L0.6117 0.9833L0.618 0.9833L0.6367 0.977L0.6931 0.952L0.7161 0.9374L0.7474 0.9123L0.7724 0.8894L0.7975 0.8622L0.8288 0.8225L0.8476 0.7933L0.8601 0.7683L0.8768 0.7223L0.8789 0.7077L0.8831 0.6994L0.8873 0.6701L0.8894 0.6681L0.8914 0.6367L0.8935 0.6347L0.8935 0.5699L0.8914 0.5678L0.8914 0.5491L0.8894 0.547L0.8852 0.5157L0.8706 0.4656L0.8643 0.4551L0.8622 0.4447L0.8518 0.4259L0.8518 0.4217L0.8267 0.382L0.8017 0.3507L0.7537 0.3027L0.7119 0.2693L0.6889 0.2568L0.6785 0.2484L0.6889 0.2338L0.7035 0.2046L0.7161 0.167L0.7203 0.1608L0.7349 0.1086L0.7349 0.0981L0.737 0.096L0.7349 0.0856L0.7077 0.0877L0.7056 0.0898L0.6806 0.0939L0.6451 0.1065L0.6347 0.1127L0.6305 0.1127L0.5637 0.1482L0.5073 0.1837L0.5052 0.1795L0.5261 0.1545L0.547 0.1336L0.5637 0.1211L0.5678 0.1148L0.5637 0.1086L0.5574 0.0877L0.5282 0.0313L0.5031 0Z";
  return (
    <svg viewBox="0 0 1 1" className={className} aria-hidden="true">
      <path d={hollow ? `${d} M0.5 0.2862 A0.3213 0.3213 0 1 0 0.5001 0.2862 Z` : d} fill="currentColor" fillRule="evenodd" />
    </svg>
  );
}

export function Panel({ title, aside, children, className }: { title?: ReactNode; aside?: ReactNode; children: ReactNode; className?: string }) {
  return (
    <section className={cx("grid min-w-0 content-start gap-2.5 rounded-md border border-hairline bg-surface px-3.5 py-3", className)}>
      {title && (
        <h5 className="m-0 flex items-baseline justify-between gap-2 text-[12.5px] font-semibold">
          {title}
          {aside && <span className="text-[11.5px] font-normal text-fg-dim">{aside}</span>}
        </h5>
      )}
      {children}
    </section>
  );
}

export function Kpi({ label, value, sub, up }: { label: string; value: ReactNode; sub?: ReactNode; up?: boolean }) {
  return (
    <div className="grid gap-0.5 rounded-md border border-hairline bg-surface px-3 py-2.5">
      <span className="font-mono text-[10.5px] uppercase tracking-[0.06em] text-fg-dim">{label}</span>
      <span className="tnum text-[21px] font-semibold tracking-tight">{value}</span>
      {sub && <span className={cx("text-[11.5px]", up ? "text-earn" : "text-fg-dim")}>{sub}</span>}
    </div>
  );
}

type Tone = "neutral" | "ok" | "wine" | "warn" | "bad";
const toneClass: Record<Tone, string> = {
  neutral: "bg-raised text-fg-dim",
  ok: "bg-live/15 text-live",
  wine: "bg-wine/10 text-wine-bright",
  warn: "bg-warn/15 text-warn",
  bad: "bg-wine/15 text-wine-bright",
};

export function Pill({ tone = "neutral", children }: { tone?: Tone; children: ReactNode }) {
  return <span className={cx("whitespace-nowrap rounded-full px-2 py-px text-[11px] font-medium", toneClass[tone])}>{children}</span>;
}

export function Button({ variant = "default", size = "md", className, ...rest }: ButtonHTMLAttributes<HTMLButtonElement> & { variant?: "default" | "primary"; size?: "sm" | "md" }) {
  return (
    <button
      {...rest}
      className={cx(
        "inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-sm border font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",
        size === "sm" ? "px-2 py-0.5 text-[11.5px]" : "px-3 py-1.5 text-[12.5px]",
        variant === "primary"
          ? "border-wine bg-wine font-semibold text-on-wine hover:bg-wine-deep"
          : "border-hairline bg-surface text-fg hover:bg-raised",
        className,
      )}
    />
  );
}

export function Toggle({ on, onChange, disabled, label }: { on: boolean; onChange: (v: boolean) => void; disabled?: boolean; label: string }) {
  return (
    <button
      role="switch"
      aria-checked={on}
      aria-label={label}
      disabled={disabled}
      onClick={() => onChange(!on)}
      className={cx(
        "relative inline-block h-[18px] w-[30px] flex-none rounded-full transition-colors disabled:opacity-50",
        on ? "bg-wine" : "bg-hairline",
      )}
    >
      <span className={cx("absolute top-[2px] h-[14px] w-[14px] rounded-full bg-surface shadow transition-all", on ? "left-[14px]" : "left-[2px]")} />
    </button>
  );
}

export function Meter({ parts }: { parts: { pct: number; dim?: boolean }[] }) {
  return (
    <div className="flex h-1.5 overflow-hidden rounded-full bg-raised">
      {parts.map((p, i) => (
        <i key={i} className={cx("block h-full", p.dim ? "bg-fg-dim/45" : "bg-wine")} style={{ width: `${Math.max(0, Math.min(100, p.pct))}%` }} />
      ))}
    </div>
  );
}

export function Row({ children, cols = "1fr auto auto" }: { children: ReactNode; cols?: string }) {
  return (
    <div className="grid items-center gap-3 border-t border-hairline py-2 text-[12.5px] first:border-t-0 first:pt-0.5" style={{ gridTemplateColumns: cols }}>
      {children}
    </div>
  );
}

export function RowName({ name, sub }: { name: ReactNode; sub?: ReactNode }) {
  return (
    <div className="grid min-w-0 gap-px">
      <b className="truncate font-semibold">{name}</b>
      {sub && <span className="truncate text-[11.5px] text-fg-dim">{sub}</span>}
    </div>
  );
}

export function ScreenHead({ title, sub, children }: { title: string; sub?: ReactNode; children?: ReactNode }) {
  return (
    <div className="flex flex-wrap items-center justify-between gap-3">
      <div className="grid gap-0.5">
        <h4 className="m-0 text-[19px] font-semibold tracking-tight">{title}</h4>
        {sub && <span className="text-[12px] text-fg-dim">{sub}</span>}
      </div>
      {children && <div className="flex flex-wrap items-center gap-2">{children}</div>}
    </div>
  );
}

/** A feature this zc does not have yet: the agent answers its `/v2` route
 * with 501 until the named issue ships (docs/agent-api.md, "v2"). */
export function NotYet({ what, route, until, children }: { what: string; route: string; until: string; children?: ReactNode }) {
  return (
    <Panel>
      <div className="grid gap-2 py-6 text-center">
        <span className="font-mono text-[11px] uppercase tracking-[0.08em] text-fg-dim">Not in this zc yet</span>
        <p className="m-0 text-[13.5px]">{what}</p>
        <p className="m-0 text-[12px] text-fg-dim">
          The agent serves <code className="font-mono">{route}</code> from {until} on.
        </p>
        {children}
      </div>
    </Panel>
  );
}

/** A full-width notice above a screen (a link that landed here, a proposal). */
export function Notice({ tone = "wine", title, children, onClose }: { tone?: "wine" | "warn"; title: ReactNode; children?: ReactNode; onClose?: () => void }) {
  return (
    <div role="status" className={cx("flex items-start justify-between gap-3 rounded-r-md border-l-[3px] px-4 py-2.5 text-[12.5px]", tone === "warn" ? "border-warn bg-warn/10" : "border-wine bg-wine/10")}>
      <div className="grid gap-1">
        <b className="font-semibold">{title}</b>
        {children && <div className="text-fg-dim">{children}</div>}
      </div>
      {onClose && (
        <button aria-label="Dismiss" className="text-fg-dim hover:text-fg" onClick={onClose}>
          ×
        </button>
      )}
    </div>
  );
}

/** Segmented control (7 d / 30 d). */
export function Seg<T extends string>({ value, options, onChange }: { value: T; options: { value: T; label: string }[]; onChange: (v: T) => void }) {
  return (
    <div className="inline-flex overflow-hidden rounded-sm border border-hairline bg-surface" role="tablist">
      {options.map((o, i) => (
        <button
          key={o.value}
          role="tab"
          aria-selected={o.value === value}
          onClick={() => onChange(o.value)}
          className={cx("px-2.5 py-1 text-[12px]", i > 0 && "border-l border-hairline", o.value === value ? "bg-wine/10 font-semibold text-wine-bright" : "text-fg hover:bg-raised")}
        >
          {o.label}
        </button>
      ))}
    </div>
  );
}

/** One quiet line where a list has nothing yet: says what will appear. */
export function Empty({ children }: { children: ReactNode }) {
  return <div className="rounded-sm border border-dashed border-hairline px-3 py-4 text-center text-[12px] text-fg-dim">{children}</div>;
}

/** An inline link to another screen ("All nodes ›"). */
export function Go({ children, onClick }: { children: ReactNode; onClick: () => void }) {
  return (
    <button type="button" onClick={onClick} className="whitespace-nowrap text-[11.5px] font-medium text-wine-bright hover:underline">
      {children} ›
    </button>
  );
}

/** − n + for a small count. */
export function Stepper({ value, min, max, disabled, onChange, label }: { value: number | null; min: number; max: number; disabled?: boolean; onChange: (v: number) => void; label: string }) {
  return (
    <div className="flex items-center gap-2" role="group" aria-label={label}>
      <Button size="sm" aria-label={`Fewer ${label.toLowerCase()}`} disabled={disabled || value === null || value <= min} onClick={() => value !== null && onChange(value - 1)}>
        −
      </Button>
      <span className="tnum w-6 text-center font-mono">{value ?? "—"}</span>
      <Button size="sm" aria-label={`More ${label.toLowerCase()}`} disabled={disabled || value === null || value >= max} onClick={() => value !== null && onChange(value + 1)}>
        +
      </Button>
    </div>
  );
}

/** A small text field for one setting (a price, a number of days). */
export function Field({ invalid, className, ...rest }: React.InputHTMLAttributes<HTMLInputElement> & { invalid?: boolean }) {
  return (
    <input
      {...rest}
      className={cx("tnum rounded-sm border bg-bg px-2 py-1 font-mono text-[12.5px] outline-none focus:border-wine disabled:opacity-60", invalid ? "border-wine" : "border-hairline", className ?? "w-20")}
    />
  );
}