zc2 0.0.45

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

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

/** The zakuro mark (same contour as macos/…/Pomegranate.swift), in a 1×1 box. */
export function Pomegranate({ className, hollow = false }: { className?: string; hollow?: boolean }) {
  const d =
    "M0.6197 0.3211 A0.35 0.35 0 1 1 0.3803 0.3211 L0.358 0.19 L0.375 0.09 L0.437 0.175 L0.5 0.045 L0.563 0.175 L0.625 0.09 L0.642 0.19 Z";
  return (
    <svg viewBox="0 0 1 1" className={className} aria-hidden="true">
      <path d={hollow ? `${d} M0.5 0.37 A0.28 0.28 0 1 0 0.5001 0.37 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 screen whose data only agent API v2 carries (ADR ZC-0019). */
export function ComingWithV2({ what, route, children }: { what: string; route: 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">Agent API v2</span>
        <p className="m-0 text-[13.5px]">{what}</p>
        <p className="m-0 text-[12px] text-fg-dim">
          This build talks to agent API v1. The screen fills in once the agent serves <code className="font-mono">{route}</code>.
        </p>
        {children}
      </div>
    </Panel>
  );
}