zc2 0.0.48

P2P compute broker with yen-denominated 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 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>;
}