---
title: "Simple Table · UI SDK — StyleX Blocks"
description: "Focused Cinder Cloud API keys and service tokens table with environment segment filter, status select, live search, sortable column headers, multi-row selection with a contextual floating ActionBar, per-row overflow menus, create-token dialog, destructive confirmation AlertDialog, pagination, and empty state."
url: "https://stylexblocks.com/block/ui-sdk/simple-table/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Simple Table block

Focused Cinder Cloud API keys and service tokens table with environment segment filter, status select, live search, sortable column headers, multi-row selection with a contextual floating ActionBar, per-row overflow menus, create-token dialog, destructive confirmation AlertDialog, pagination, and empty state.

- Behavior engine: UI SDK
- Category: [Data tables](https://stylexblocks.com/blocks/tables.md)
- Built with: [Action Bar](https://stylexblocks.com/components/ui-sdk/action-bar.md), [Alert Dialog](https://stylexblocks.com/components/ui-sdk/alert-dialog.md), [Avatar](https://stylexblocks.com/components/ui-sdk/avatar.md), [Badge](https://stylexblocks.com/components/ui-sdk/badge.md), [Button](https://stylexblocks.com/components/ui-sdk/button.md), [Checkbox](https://stylexblocks.com/components/ui-sdk/checkbox.md), [Code](https://stylexblocks.com/components/ui-sdk/code.md), [Dialog](https://stylexblocks.com/components/ui-sdk/dialog.md), [Empty State](https://stylexblocks.com/components/ui-sdk/empty-state.md), [Field](https://stylexblocks.com/components/ui-sdk/field.md), [Grid](https://stylexblocks.com/components/ui-sdk/grid.md), [Heading](https://stylexblocks.com/components/ui-sdk/heading.md), [Icon](https://stylexblocks.com/components/ui-sdk/icon.md), [Icon Button](https://stylexblocks.com/components/ui-sdk/icon-button.md), [Input](https://stylexblocks.com/components/ui-sdk/input.md), [Menu](https://stylexblocks.com/components/ui-sdk/menu.md), [Pagination](https://stylexblocks.com/components/ui-sdk/pagination.md), [Segment Group](https://stylexblocks.com/components/ui-sdk/segment-group.md), [Select](https://stylexblocks.com/components/ui-sdk/select.md), [Stack](https://stylexblocks.com/components/ui-sdk/stack.md), [Status](https://stylexblocks.com/components/ui-sdk/status.md), [Table](https://stylexblocks.com/components/ui-sdk/table.md), [Text](https://stylexblocks.com/components/ui-sdk/text.md), [Toast](https://stylexblocks.com/components/ui-sdk/toast.md), [Visually Hidden](https://stylexblocks.com/components/ui-sdk/visually-hidden.md)
- HTML page: https://stylexblocks.com/block/ui-sdk/simple-table/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add simple-table
```

Equivalent: `npx shadcn add @stylexblocks/simple-table`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/simple-table.json

## Usage

```tsx
import { SimpleTable } from "#components/blocks/ui-sdk/simple-table.tsx";

export function Example() {
  return (
    <div style={{ minHeight: "100dvh" }}>
      <SimpleTable />
    </div>
  );
}
```

## Source

`components/blocks/ui-sdk/simple-table.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { useCallback, useMemo, useState } from "react";
import { ActionBar } from "#components/ui/ui-sdk/action-bar.tsx";
import { AlertDialog } from "#components/ui/ui-sdk/alert-dialog.tsx";
import { Avatar } from "#components/ui/ui-sdk/avatar.tsx";
import { Badge } from "#components/ui/ui-sdk/badge.tsx";
import { Button } from "#components/ui/ui-sdk/button.tsx";
import { Checkbox } from "#components/ui/ui-sdk/checkbox.tsx";
import { Code } from "#components/ui/ui-sdk/code.tsx";
import { Dialog } from "#components/ui/ui-sdk/dialog.tsx";
import { EmptyState } from "#components/ui/ui-sdk/empty-state.tsx";
import { Field } from "#components/ui/ui-sdk/field.tsx";
import { Grid } from "#components/ui/ui-sdk/grid.tsx";
import { Heading } from "#components/ui/ui-sdk/heading.tsx";
import { Icon } from "#components/ui/ui-sdk/icon.tsx";
import { IconButton } from "#components/ui/ui-sdk/icon-button.tsx";
import { Input } from "#components/ui/ui-sdk/input.tsx";
import { Menu } from "#components/ui/ui-sdk/menu.tsx";
import { Pagination } from "#components/ui/ui-sdk/pagination.tsx";
import { SegmentGroup } from "#components/ui/ui-sdk/segment-group.tsx";
import { Select } from "#components/ui/ui-sdk/select.tsx";
import { HStack, VStack } from "#components/ui/ui-sdk/stack.tsx";
import { Status } from "#components/ui/ui-sdk/status.tsx";
import { Table } from "#components/ui/ui-sdk/table.tsx";
import { Text } from "#components/ui/ui-sdk/text.tsx";
import { Toast, Toaster } from "#components/ui/ui-sdk/toast.tsx";
import { VisuallyHidden } from "#components/ui/ui-sdk/visually-hidden.tsx";
import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";
import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";
import { semanticShadows } from "@stylexblocks/ui/semantic-tokens/shadows.stylex.ts";
import {
  accentPalette,
  amberPalette,
  bluePalette,
  cyanPalette,
  grayPalette,
  greenPalette,
  indigoPalette,
  purplePalette,
  redPalette,
  tealPalette,
} from "@stylexblocks/ui/themes/palettes.ts";
import { durations } from "@stylexblocks/ui/tokens/durations.stylex.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";
import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";

const COMPACT = "@container simple-table (max-width: 720px)";
const NARROW = "@container simple-table (max-width: 520px)";

export type TokenEnvironment = "production" | "staging" | "sandbox";
export type TokenScope = "full" | "write" | "deploy" | "read";
export type TokenStatus = "active" | "expiring" | "revoked";

type AvatarTone = "indigo" | "teal" | "purple" | "blue" | "cyan" | "amber";

export interface TokenOwner {
  name: string;
  email: string;
  initials: string;
  team: string;
  tone: AvatarTone;
}

export interface ApiTokenRecord {
  id: string;
  name: string;
  prefix: string;
  environment: TokenEnvironment;
  owner: TokenOwner;
  scope: TokenScope;
  lastUsedLabel: string;
  /** ISO-8601 UTC timestamp for deterministic sorting; empty string when unused. */
  lastUsedISO: string;
  requests24h: number;
  status: TokenStatus;
}

type EnvironmentFilter = "all" | TokenEnvironment;
type StatusFilter = "all" | TokenStatus;
type SortKey =
  | "name"
  | "environment"
  | "owner"
  | "scope"
  | "lastUsedISO"
  | "requests24h"
  | "status";
type SortDirection = "asc" | "desc";

interface FilterOption<T extends string> {
  value: T;
  label: string;
}

const ENVIRONMENT_LABELS: Record<TokenEnvironment, string> = {
  production: "Production",
  staging: "Staging",
  sandbox: "Sandbox",
};

const ENVIRONMENT_PREFIX: Record<TokenEnvironment, string> = {
  production: "cnd_live_",
  staging: "cnd_stg_",
  sandbox: "cnd_sbx_",
};

const ENVIRONMENT_PALETTES = {
  production: indigoPalette,
  staging: bluePalette,
  sandbox: grayPalette,
} as const;

const ENVIRONMENT_ORDER: Record<TokenEnvironment, number> = {
  production: 0,
  staging: 1,
  sandbox: 2,
};

const SCOPE_LABELS: Record<TokenScope, string> = {
  full: "Full Access",
  write: "Read & Write",
  deploy: "Deploy",
  read: "Read-Only",
};

const SCOPE_PALETTES = {
  full: purplePalette,
  write: tealPalette,
  deploy: cyanPalette,
  read: grayPalette,
} as const;

// Scopes sort by breadth of privilege rather than alphabetically.
const SCOPE_ORDER: Record<TokenScope, number> = {
  full: 0,
  write: 1,
  deploy: 2,
  read: 3,
};

const STATUS_LABELS: Record<TokenStatus, string> = {
  active: "Active",
  expiring: "Expiring",
  revoked: "Revoked",
};

const STATUS_PALETTES = {
  active: greenPalette,
  expiring: amberPalette,
  revoked: redPalette,
} as const;

const STATUS_ORDER: Record<TokenStatus, number> = {
  active: 0,
  expiring: 1,
  revoked: 2,
};

const AVATAR_PALETTES = {
  indigo: indigoPalette,
  teal: tealPalette,
  purple: purplePalette,
  blue: bluePalette,
  cyan: cyanPalette,
  amber: amberPalette,
} as const;

const ENVIRONMENT_OPTIONS: readonly FilterOption<EnvironmentFilter>[] = [
  { value: "all", label: "All" },
  { value: "production", label: "Production" },
  { value: "staging", label: "Staging" },
  { value: "sandbox", label: "Sandbox" },
];

const CREATE_ENVIRONMENT_OPTIONS: readonly FilterOption<TokenEnvironment>[] = [
  { value: "production", label: "Production" },
  { value: "staging", label: "Staging" },
  { value: "sandbox", label: "Sandbox" },
];

const STATUS_OPTIONS: readonly FilterOption<StatusFilter>[] = [
  { value: "all", label: "All statuses" },
  { value: "active", label: "Active" },
  { value: "expiring", label: "Expiring" },
  { value: "revoked", label: "Revoked" },
];

const SCOPE_OPTIONS: readonly FilterOption<TokenScope>[] = [
  { value: "read", label: "Read-Only" },
  { value: "deploy", label: "Deploy" },
  { value: "write", label: "Read & Write" },
  { value: "full", label: "Full Access" },
];

const PAGE_SIZE_OPTIONS: readonly FilterOption<string>[] = [
  { value: "6", label: "6 / page" },
  { value: "8", label: "8 / page" },
  { value: "12", label: "12 / page" },
  { value: "20", label: "20 / page" },
];

const OWNERS: Record<string, TokenOwner> = {
  nadia: {
    name: "Nadia Osei",
    email: "nadia@cindercloud.dev",
    initials: "NO",
    team: "Core Runtime",
    tone: "indigo",
  },
  tomas: {
    name: "Tomas Lindholm",
    email: "tomas@cindercloud.dev",
    initials: "TL",
    team: "Edge Network",
    tone: "teal",
  },
  keiko: {
    name: "Keiko Mori",
    email: "keiko@cindercloud.dev",
    initials: "KM",
    team: "Billing Infra",
    tone: "purple",
  },
  devon: {
    name: "Devon Brooks",
    email: "devon@cindercloud.dev",
    initials: "DB",
    team: "Release Eng",
    tone: "blue",
  },
  ananya: {
    name: "Ananya Deshmukh",
    email: "ananya@cindercloud.dev",
    initials: "AD",
    team: "Data Pipeline",
    tone: "cyan",
  },
  rafi: {
    name: "Rafi Haddad",
    email: "rafi@cindercloud.dev",
    initials: "RH",
    team: "Security Ops",
    tone: "amber",
  },
};

const DEFAULT_TOKENS: ApiTokenRecord[] = [
  {
    id: "tok-01",
    name: "Edge Ingress Signer",
    prefix: "cnd_live_9f2a4c…",
    environment: "production",
    owner: OWNERS.tomas,
    scope: "write",
    lastUsedLabel: "2m ago",
    lastUsedISO: "2026-12-01T23:58:00Z",
    requests24h: 284_910,
    status: "active",
  },
  {
    id: "tok-02",
    name: "Billing Webhook Relay",
    prefix: "cnd_live_4c81e0…",
    environment: "production",
    owner: OWNERS.keiko,
    scope: "write",
    lastUsedLabel: "6m ago",
    lastUsedISO: "2026-12-01T23:54:00Z",
    requests24h: 61_420,
    status: "active",
  },
  {
    id: "tok-03",
    name: "CI Artifact Publisher",
    prefix: "cnd_live_7b03d9…",
    environment: "production",
    owner: OWNERS.devon,
    scope: "deploy",
    lastUsedLabel: "19m ago",
    lastUsedISO: "2026-12-01T23:41:00Z",
    requests24h: 4_812,
    status: "active",
  },
  {
    id: "tok-04",
    name: "Telemetry Ingest Worker",
    prefix: "cnd_live_2e6f1a…",
    environment: "production",
    owner: OWNERS.ananya,
    scope: "write",
    lastUsedLabel: "1m ago",
    lastUsedISO: "2026-12-01T23:59:00Z",
    requests24h: 492_305,
    status: "active",
  },
  {
    id: "tok-05",
    name: "Incident Pager Bot",
    prefix: "cnd_live_8a52c7…",
    environment: "production",
    owner: OWNERS.rafi,
    scope: "read",
    lastUsedLabel: "42m ago",
    lastUsedISO: "2026-12-01T23:18:00Z",
    requests24h: 12_044,
    status: "expiring",
  },
  {
    id: "tok-06",
    name: "Terraform State Runner",
    prefix: "cnd_live_1d94b3…",
    environment: "production",
    owner: OWNERS.nadia,
    scope: "full",
    lastUsedLabel: "3h ago",
    lastUsedISO: "2026-12-01T21:05:00Z",
    requests24h: 1_920,
    status: "active",
  },
  {
    id: "tok-07",
    name: "Preview Deploy Hook",
    prefix: "cnd_stg_5e21f8…",
    environment: "staging",
    owner: OWNERS.devon,
    scope: "deploy",
    lastUsedLabel: "14m ago",
    lastUsedISO: "2026-12-01T23:46:00Z",
    requests24h: 9_640,
    status: "active",
  },
  {
    id: "tok-08",
    name: "Search Index Sync",
    prefix: "cnd_live_3f77a2…",
    environment: "production",
    owner: OWNERS.ananya,
    scope: "write",
    lastUsedLabel: "27m ago",
    lastUsedISO: "2026-12-01T23:33:00Z",
    requests24h: 118_750,
    status: "expiring",
  },
  {
    id: "tok-09",
    name: "QA Synthetic Probe",
    prefix: "cnd_stg_6c40d1…",
    environment: "staging",
    owner: OWNERS.tomas,
    scope: "read",
    lastUsedLabel: "8m ago",
    lastUsedISO: "2026-12-01T23:52:00Z",
    requests24h: 34_200,
    status: "active",
  },
  {
    id: "tok-10",
    name: "Legacy Export Bridge",
    prefix: "cnd_live_0a18e5…",
    environment: "production",
    owner: OWNERS.keiko,
    scope: "read",
    lastUsedLabel: "Nov 18",
    lastUsedISO: "2026-11-18T14:22:00Z",
    requests24h: 0,
    status: "revoked",
  },
  {
    id: "tok-11",
    name: "Local CLI Dev Key",
    prefix: "cnd_sbx_c932b0…",
    environment: "sandbox",
    owner: OWNERS.nadia,
    scope: "write",
    lastUsedLabel: "1h ago",
    lastUsedISO: "2026-12-01T22:55:00Z",
    requests24h: 842,
    status: "active",
  },
  {
    id: "tok-12",
    name: "SOC2 Audit Collector",
    prefix: "cnd_live_b410f6…",
    environment: "production",
    owner: OWNERS.rafi,
    scope: "read",
    lastUsedLabel: "5h ago",
    lastUsedISO: "2026-12-01T19:12:00Z",
    requests24h: 2_310,
    status: "active",
  },
  {
    id: "tok-13",
    name: "Staging Seed Script",
    prefix: "cnd_stg_e784a9…",
    environment: "staging",
    owner: OWNERS.ananya,
    scope: "full",
    lastUsedLabel: "Yesterday",
    lastUsedISO: "2026-11-30T16:40:00Z",
    requests24h: 516,
    status: "expiring",
  },
  {
    id: "tok-14",
    name: "SDK Integration Tests",
    prefix: "cnd_sbx_d105c4…",
    environment: "sandbox",
    owner: OWNERS.devon,
    scope: "write",
    lastUsedLabel: "35m ago",
    lastUsedISO: "2026-12-01T23:25:00Z",
    requests24h: 15_490,
    status: "active",
  },
  {
    id: "tok-15",
    name: "Partner Sandbox Demo",
    prefix: "cnd_sbx_a829e3…",
    environment: "sandbox",
    owner: OWNERS.keiko,
    scope: "read",
    lastUsedLabel: "Never",
    lastUsedISO: "",
    requests24h: 0,
    status: "active",
  },
  {
    id: "tok-16",
    name: "Canary Rollback Agent",
    prefix: "cnd_stg_f261d7…",
    environment: "staging",
    owner: OWNERS.nadia,
    scope: "deploy",
    lastUsedLabel: "2h ago",
    lastUsedISO: "2026-12-01T21:48:00Z",
    requests24h: 3_180,
    status: "active",
  },
  {
    id: "tok-17",
    name: "Decommissioned Mailer",
    prefix: "cnd_stg_4b90c2…",
    environment: "staging",
    owner: OWNERS.rafi,
    scope: "write",
    lastUsedLabel: "Nov 04",
    lastUsedISO: "2026-11-04T09:15:00Z",
    requests24h: 0,
    status: "revoked",
  },
  {
    id: "tok-18",
    name: "GraphQL Schema Sync",
    prefix: "cnd_sbx_7e53f1…",
    environment: "sandbox",
    owner: OWNERS.tomas,
    scope: "deploy",
    lastUsedLabel: "Yesterday",
    lastUsedISO: "2026-11-30T11:30:00Z",
    requests24h: 1_245,
    status: "expiring",
  },
];

const ROTATION_HEX = [
  "a4f9c2",
  "e81b3d",
  "5c70a1",
  "91d4e6",
  "3b8f20",
  "f06c9a",
  "27e5b4",
  "6d12f8",
];

const integerFormatter = new Intl.NumberFormat("en-US");

function pluralize(count: number, singular: string, plural = `${singular}s`): string {
  return `${count} ${count === 1 ? singular : plural}`;
}

function compareTokens(a: ApiTokenRecord, b: ApiTokenRecord, key: SortKey): number {
  switch (key) {
    case "name":
      return a.name.localeCompare(b.name);
    case "environment":
      return (
        ENVIRONMENT_ORDER[a.environment] - ENVIRONMENT_ORDER[b.environment] ||
        a.name.localeCompare(b.name)
      );
    case "owner":
      return a.owner.name.localeCompare(b.owner.name) || a.name.localeCompare(b.name);
    case "scope":
      return SCOPE_ORDER[a.scope] - SCOPE_ORDER[b.scope] || a.name.localeCompare(b.name);
    case "lastUsedISO":
      return a.lastUsedISO.localeCompare(b.lastUsedISO) || a.name.localeCompare(b.name);
    case "requests24h":
      return a.requests24h - b.requests24h || a.name.localeCompare(b.name);
    case "status":
      return STATUS_ORDER[a.status] - STATUS_ORDER[b.status] || a.name.localeCompare(b.name);
  }
}

const styles = stylex.create({
  root: {
    backgroundColor: semanticColors.bg,
    color: semanticColors.fg,
    containerName: "simple-table",
    containerType: "inline-size",
    fontFamily: fonts.body,
    minHeight: "100%",
    paddingBlock: {
      default: spacing._8,
      [NARROW]: spacing._5,
    },
    paddingInline: {
      default: spacing._6,
      [NARROW]: spacing._4,
    },
    width: "100%",
  },
  container: {
    marginInline: "auto",
    maxWidth: "72rem",
    width: "100%",
  },
  heading: {
    marginBlock: 0,
  },
  subtitle: {
    maxWidth: "56ch",
  },
  toolbarFilters: {
    flexGrow: 1,
    justifyContent: {
      default: "flex-end",
      [COMPACT]: "flex-start",
    },
  },
  statusSelect: {
    minWidth: "9.25rem",
    width: "auto",
  },
  searchWrap: {
    flexGrow: {
      default: 0,
      [NARROW]: 1,
    },
    minWidth: "13rem",
    position: "relative",
    width: {
      default: "16.5rem",
      [NARROW]: "100%",
    },
  },
  searchIcon: {
    color: semanticColors.fgSubtle,
    insetInlineStart: spacing._2_5,
    pointerEvents: "none",
    position: "absolute",
    top: "50%",
    transform: "translateY(-50%)",
    zIndex: 1,
  },
  searchInput: {
    paddingInlineEnd: spacing._7,
    paddingInlineStart: spacing._8,
  },
  searchClearBtn: {
    color: semanticColors.fgMuted,
    height: "1.375rem",
    insetInlineEnd: spacing._1_5,
    minWidth: "1.375rem",
    position: "absolute",
    top: "50%",
    transform: "translateY(-50%)",
    width: "1.375rem",
  },
  tableCard: {
    backgroundColor: semanticColors.bgPanel,
    borderColor: semanticColors.border,
    borderRadius: semanticRadii.panel,
    borderStyle: "solid",
    borderWidth: "1px",
    boxShadow: semanticShadows.xs,
    overflowX: "hidden",
    overflowY: "hidden",
  },
  selectionBanner: {
    backgroundColor: semanticColors.bgSubtle,
    borderBottomColor: semanticColors.border,
    borderBottomStyle: "solid",
    borderBottomWidth: "1px",
    paddingBlock: spacing._2,
    paddingInline: spacing._4,
  },
  tableScroll: {
    overflowX: "auto",
    width: "100%",
  },
  tableHeaderRow: {
    backgroundColor: semanticColors.bgMuted,
  },
  tableHeaderCell: {
    borderBottomColor: semanticColors.border,
    borderBottomStyle: "solid",
    color: semanticColors.fgMuted,
    fontSize: fontSizes.xs,
    fontWeight: fontWeights.semibold,
    letterSpacing: "0.01em",
    paddingBlock: spacing._2_5,
    paddingInline: spacing._3,
    whiteSpace: "nowrap",
  },
  tableBodyRow: {
    backgroundColor: {
      default: "transparent",
      ":hover": semanticColors.bgSubtle,
    },
    transitionDuration: durations.fast,
    transitionProperty: "background-color",
  },
  tableBodyRowSelected: {
    backgroundColor: {
      default: semanticColors.interactionSelected,
      ":hover": semanticColors.interactionSelected,
    },
  },
  tableBodyCell: {
    borderBottomColor: semanticColors.borderMuted,
    borderBottomStyle: "solid",
    paddingBlock: spacing._3,
    paddingInline: spacing._3,
    verticalAlign: "middle",
  },
  checkboxCol: {
    paddingInlineEnd: spacing._1,
    paddingInlineStart: spacing._4,
    width: "2.75rem",
  },
  actionsCol: {
    paddingInlineEnd: spacing._3,
    paddingInlineStart: spacing._1,
    textAlign: "end",
    width: "3rem",
  },
  alignEnd: {
    textAlign: "end",
  },
  sortButton: {
    alignItems: "center",
    appearance: "none",
    backgroundColor: "transparent",
    borderStyle: "none",
    borderWidth: 0,
    color: {
      default: semanticColors.fgMuted,
      ":hover": semanticColors.fg,
    },
    cursor: "pointer",
    display: "inline-flex",
    fontFamily: "inherit",
    fontSize: "inherit",
    fontWeight: "inherit",
    gap: spacing._1,
    paddingBlock: 0,
    paddingInline: 0,
  },
  sortButtonActive: {
    color: semanticColors.fg,
  },
  sortButtonEnd: {
    justifyContent: "flex-end",
    width: "100%",
  },
  sortIconMuted: {
    opacity: 0.45,
  },
  tokenCell: {
    minWidth: "12.5rem",
  },
  tokenPrefix: {
    alignSelf: "flex-start",
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  ownerCell: {
    display: "inline-flex",
    whiteSpace: "nowrap",
  },
  nowrap: {
    whiteSpace: "nowrap",
  },
  menuWidth: {
    minWidth: "11.5rem",
  },
  footer: {
    paddingTop: spacing._1,
  },
  pageSizeSelect: {
    minWidth: "6.5rem",
    width: "auto",
  },
  actionBarContent: {
    flexWrap: "wrap",
    maxWidth: "calc(100vw - 2rem)",
  },
  dialogSelectFull: {
    width: "100%",
  },
  dialogHeader: {
    alignItems: "flex-start",
    flexDirection: "column",
    gap: spacing._1,
  },
});

function SearchIcon({ style }: { style?: StyleOverrideProps["style"] }) {
  return (
    <Icon
      size="sm"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.5"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
      style={style}
    >
      <circle cx="7.25" cy="7.25" r="4.75" />
      <path d="m10.75 10.75 3 3" />
    </Icon>
  );
}

function CloseIcon() {
  return (
    <Icon
      size="xs"
      viewBox="0 0 12 12"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.5"
      strokeLinecap="round"
      aria-hidden="true"
    >
      <path d="m3 3 6 6M9 3 3 9" />
    </Icon>
  );
}

function PlusIcon() {
  return (
    <Icon
      size="sm"
      viewBox="0 0 16 16"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.6"
      strokeLinecap="round"
      aria-hidden="true"
    >
      <path d="M8 3.25v9.5M3.25 8h9.5" />
    </Icon>
  );
}

function MoreIcon() {
  return (
    <Icon
      size="sm"
      viewBox="0 0 16 16"
      fill="currentColor"
      aria-hidden="true"
    >
      <circle cx="3.5" cy="8" r="1.25" />
      <circle cx="8" cy="8" r="1.25" />
      <circle cx="12.5" cy="8" r="1.25" />
    </Icon>
  );
}

function TrashIcon() {
  return (
    <Icon
      size="md"
      viewBox="0 0 20 20"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.5"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d="M3.5 5.5h13M7.5 5.5V4a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1.5M5.5 5.5l.7 10.2a1.25 1.25 0 0 0 1.25 1.15h5.1a1.25 1.25 0 0 0 1.25-1.15l.7-10.2" />
      <path d="M8.25 9v4.5M11.75 9v4.5" />
    </Icon>
  );
}

function MinusIcon() {
  return (
    <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" width="100%" height="100%">
      <path
        d="M2.5 6h7"
        stroke="currentColor"
        strokeWidth="2"
        strokeLinecap="round"
      />
    </svg>
  );
}

function CheckIcon() {
  return (
    <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" width="100%" height="100%">
      <path
        d="M2.5 6.4 5 8.9l4.5-5.4"
        stroke="currentColor"
        strokeWidth="2"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

function SortIcon({ active, direction }: { active: boolean; direction: SortDirection }) {
  if (!active) {
    return (
      <Icon
        size="xs"
        viewBox="0 0 12 12"
        fill="none"
        stroke="currentColor"
        strokeWidth="1.4"
        strokeLinecap="round"
        strokeLinejoin="round"
        aria-hidden="true"
        style={styles.sortIconMuted}
      >
        <path d="M3.75 4.5 6 2.25 8.25 4.5" />
        <path d="M3.75 7.5 6 9.75 8.25 7.5" />
      </Icon>
    );
  }
  return (
    <Icon
      size="xs"
      viewBox="0 0 12 12"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.6"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      {direction === "asc" ? (
        <path d="M3.5 7.5 6 4.5l2.5 3" />
      ) : (
        <path d="M3.5 4.5 6 7.5l2.5-3" />
      )}
    </Icon>
  );
}

export interface SimpleTableProps extends StyleOverrideProps {
  /** Primary page heading for the table view. */
  title?: string;
  /** Supporting context line rendered below the heading. */
  subtitle?: string;
  /** Initial set of API key and service token records. */
  initialRows?: ApiTokenRecord[];
  /** Default number of records rendered per page. */
  defaultPageSize?: number;
  /** Optional callback fired when exporting selected tokens. */
  onExport?: (rows: ApiTokenRecord[]) => void;
}

/**
 * SimpleTable — focused Cinder Cloud API keys and service tokens table with
 * environment segmented filter, status select, live search, sortable column
 * headers, multi-row selection with a contextual floating ActionBar, per-row
 * action menus, create-token dialog, destructive confirmation AlertDialog,
 * pagination, and empty state.
 */
export function SimpleTable({
  title = "API Keys & Service Tokens",
  subtitle = "Manage programmatic credentials, scopes, and key rotation across Cinder Cloud environments.",
  initialRows = DEFAULT_TOKENS,
  defaultPageSize = 8,
  onExport,
  palette,
  style,
}: SimpleTableProps) {
  const queue = useMemo(() => Toast.createToaster(), []);

  const [rows, setRows] = useState<ApiTokenRecord[]>(initialRows);
  const [query, setQuery] = useState("");
  const [envFilter, setEnvFilter] = useState<EnvironmentFilter>("all");
  const [statusFilter, setStatusFilter] = useState<StatusFilter>("all");
  const [sortKey, setSortKey] = useState<SortKey>("lastUsedISO");
  const [sortDirection, setSortDirection] = useState<SortDirection>("desc");
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(defaultPageSize);
  const [selectedIds, setSelectedIds] = useState<Set<string>>(() => new Set());
  const [rotationSeq, setRotationSeq] = useState(0);

  // Destructive delete confirmation state; title persists across close motion.
  const [pendingDeleteIds, setPendingDeleteIds] = useState<string[] | null>(null);
  const [deleteDialogTitle, setDeleteDialogTitle] = useState("");

  // Create-token dialog state.
  const [createOpen, setCreateOpen] = useState(false);
  const [newTokenName, setNewTokenName] = useState("");
  const [newTokenEnv, setNewTokenEnv] = useState<TokenEnvironment>("production");
  const [newTokenScope, setNewTokenScope] = useState<TokenScope>("write");
  const [createCounter, setCreateCounter] = useState(0);

  const visible = useMemo(() => {
    const term = query.trim().toLowerCase();
    return rows.filter((row) => {
      if (envFilter !== "all" && row.environment !== envFilter) return false;
      if (statusFilter !== "all" && row.status !== statusFilter) return false;
      if (term !== "") {
        const haystack =
          `${row.name} ${row.prefix} ${row.owner.name} ${row.owner.team} ${ENVIRONMENT_LABELS[row.environment]} ${SCOPE_LABELS[row.scope]} ${STATUS_LABELS[row.status]}`.toLowerCase();
        if (!haystack.includes(term)) return false;
      }
      return true;
    });
  }, [rows, query, envFilter, statusFilter]);

  const sortedRows = useMemo(() => {
    const factor = sortDirection === "asc" ? 1 : -1;
    return [...visible].sort((a, b) => compareTokens(a, b, sortKey) * factor);
  }, [visible, sortKey, sortDirection]);

  const totalPages = Math.max(Math.ceil(sortedRows.length / pageSize), 1);
  const safePage = Math.min(page, totalPages);
  const pageStart = (safePage - 1) * pageSize;
  const pageEnd = Math.min(pageStart + pageSize, sortedRows.length);
  const pageRows = useMemo(
    () => sortedRows.slice(pageStart, pageEnd),
    [sortedRows, pageStart, pageEnd],
  );

  const activeCount = useMemo(
    () => rows.filter((row) => row.status === "active").length,
    [rows],
  );

  const activeFilterCount =
    (query.trim() === "" ? 0 : 1) +
    (envFilter === "all" ? 0 : 1) +
    (statusFilter === "all" ? 0 : 1);

  const selectedRows = useMemo(
    () => rows.filter((row) => selectedIds.has(row.id)),
    [rows, selectedIds],
  );

  const pageSelectedCount = useMemo(
    () => pageRows.filter((row) => selectedIds.has(row.id)).length,
    [pageRows, selectedIds],
  );

  const allPageSelected = pageRows.length > 0 && pageSelectedCount === pageRows.length;
  const somePageSelected = pageSelectedCount > 0 && !allPageSelected;
  const allVisibleSelected =
    visible.length > 0 && visible.every((row) => selectedIds.has(row.id));

  const clearAllFilters = useCallback(() => {
    setQuery("");
    setEnvFilter("all");
    setStatusFilter("all");
    setPage(1);
  }, []);

  const handleSort = useCallback(
    (key: SortKey) => {
      if (sortKey === key) {
        setSortDirection((prev) => (prev === "asc" ? "desc" : "asc"));
      } else {
        setSortKey(key);
        setSortDirection(
          key === "requests24h" || key === "lastUsedISO" ? "desc" : "asc",
        );
      }
      setPage(1);
    },
    [sortKey],
  );

  const toggleRow = useCallback((id: string, checked: boolean) => {
    setSelectedIds((prev) => {
      const next = new Set(prev);
      if (checked) {
        next.add(id);
      } else {
        next.delete(id);
      }
      return next;
    });
  }, []);

  const togglePageSelection = useCallback(() => {
    setSelectedIds((prev) => {
      const next = new Set(prev);
      if (allPageSelected) {
        for (const row of pageRows) next.delete(row.id);
      } else {
        for (const row of pageRows) next.add(row.id);
      }
      return next;
    });
  }, [allPageSelected, pageRows]);

  const selectAllVisible = useCallback(() => {
    setSelectedIds(new Set(visible.map((row) => row.id)));
  }, [visible]);

  const clearSelection = useCallback(() => {
    setSelectedIds(new Set());
  }, []);

  const handleCopyPrefix = useCallback(
    (row: ApiTokenRecord) => {
      const cleanPrefix = row.prefix.replace("…", "");
      if (typeof navigator !== "undefined" && navigator.clipboard) {
        void navigator.clipboard.writeText(cleanPrefix).catch(() => {});
      }
      queue.info(`Copied ${cleanPrefix}`, {
        description: `${row.name} (${ENVIRONMENT_LABELS[row.environment]})`,
      });
    },
    [queue],
  );

  const handleRotateSecret = useCallback(
    (row: ApiTokenRecord) => {
      const suffix = ROTATION_HEX[rotationSeq % ROTATION_HEX.length];
      const nextPrefix = `${ENVIRONMENT_PREFIX[row.environment]}${suffix}…`;
      setRotationSeq((seq) => seq + 1);
      setRows((prev) =>
        prev.map((item) =>
          item.id === row.id
            ? {
                ...item,
                prefix: nextPrefix,
                status: "active",
                lastUsedLabel: "Just now",
                lastUsedISO: "2026-12-02T00:00:00Z",
              }
            : item,
        ),
      );
      queue.success(`Rotated secret for ${row.name}`, {
        description: `New prefix ${nextPrefix} is active; previous key expires in 24h.`,
      });
    },
    [queue, rotationSeq],
  );

  const handleToggleRevoke = useCallback(
    (ids: string[], nextStatus: "revoked" | "active") => {
      const idSet = new Set(ids);
      let changed = 0;
      setRows((prev) =>
        prev.map((row) => {
          if (!idSet.has(row.id) || row.status === nextStatus) return row;
          changed += 1;
          return {
            ...row,
            status: nextStatus,
            requests24h: nextStatus === "revoked" ? 0 : row.requests24h,
          };
        }),
      );
      setSelectedIds((prev) => {
        const next = new Set(prev);
        for (const id of ids) next.delete(id);
        return next;
      });
      if (changed === 0) {
        queue.info(
          nextStatus === "revoked"
            ? "Selected tokens are already revoked"
            : "Token is already active",
        );
        return;
      }
      if (nextStatus === "revoked") {
        queue.warning(
          changed === 1 ? "Revoked 1 token" : `Revoked ${changed} tokens`,
          {
            description: "API calls using revoked keys now return 401 Unauthorized.",
          },
        );
      } else {
        queue.success(
          changed === 1 ? "Restored 1 token" : `Restored ${changed} tokens`,
          {
            description: "Token credentials are active again.",
          },
        );
      }
    },
    [queue],
  );

  const handleExport = useCallback(
    (targetRows: ApiTokenRecord[]) => {
      onExport?.(targetRows);
      queue.info(`Exported ${pluralize(targetRows.length, "token")}`, {
        description: "Metadata CSV snapshot prepared (secret hashes omitted).",
      });
    },
    [onExport, queue],
  );

  const requestDelete = useCallback(
    (ids: string[]) => {
      const single = ids.length === 1 ? rows.find((r) => r.id === ids[0]) : undefined;
      setDeleteDialogTitle(
        ids.length === 1
          ? `Delete ${single?.name ?? "token"}?`
          : `Delete ${pluralize(ids.length, "token")}?`,
      );
      setPendingDeleteIds(ids);
    },
    [rows],
  );

  const confirmDelete = useCallback(() => {
    if (!pendingDeleteIds) return;
    const removedSet = new Set(pendingDeleteIds);
    const removedCount = pendingDeleteIds.length;
    setRows((prev) => prev.filter((row) => !removedSet.has(row.id)));
    setSelectedIds((prev) => {
      const next = new Set(prev);
      for (const id of removedSet) next.delete(id);
      return next;
    });
    setPendingDeleteIds(null);
    queue.warning(`Deleted ${pluralize(removedCount, "token")}`, {
      description: "Removed permanently from Cinder Cloud key inventory.",
    });
  }, [pendingDeleteIds, queue]);

  const handleCreateToken = useCallback(
    (event: React.FormEvent<HTMLFormElement>) => {
      event.preventDefault();
      const trimmed = newTokenName.trim();
      if (!trimmed) return;
      const suffix = ROTATION_HEX[(rotationSeq + createCounter) % ROTATION_HEX.length];
      const nextNum = 19 + createCounter;
      const created: ApiTokenRecord = {
        id: `tok-${nextNum}`,
        name: trimmed,
        prefix: `${ENVIRONMENT_PREFIX[newTokenEnv]}${suffix}…`,
        environment: newTokenEnv,
        owner: OWNERS.nadia,
        scope: newTokenScope,
        lastUsedLabel: "Never",
        lastUsedISO: "",
        requests24h: 0,
        status: "active",
      };
      setRows((prev) => [created, ...prev]);
      setCreateCounter((c) => c + 1);
      setNewTokenName("");
      setCreateOpen(false);
      setPage(1);
      queue.success(`Created ${created.name}`, {
        description: `Prefix ${created.prefix} · ${ENVIRONMENT_LABELS[created.environment]} (${SCOPE_LABELS[created.scope]}).`,
      });
    },
    [createCounter, newTokenEnv, newTokenName, newTokenScope, queue, rotationSeq],
  );

  const handleResetDemo = useCallback(() => {
    setRows(initialRows);
    setSelectedIds(new Set());
    clearAllFilters();
    queue.info("Restored default token inventory");
  }, [clearAllFilters, initialRows, queue]);

  return (
    <div {...stylex.props(palette, styles.root, style)}>
      <VStack gap="5" style={styles.container}>
        {/* Header */}
        <HStack render={<header />} align="start" justify="between" wrap="wrap" gap="4">
          <VStack gap="1.5">
            <HStack wrap="wrap" gap="2.5">
              <Heading render={<h1 />} size="2xl" style={styles.heading}>
                {title}
              </Heading>
              <Badge variant="subtle" size="sm" palette={greenPalette}>
                {activeCount} active
              </Badge>
            </HStack>
            <Text size="sm" tone="muted" style={styles.subtitle}>
              {subtitle}
            </Text>
          </VStack>

          <HStack wrap="wrap" gap="2">
            <Button
              variant="solid"
              size="sm"
              palette={accentPalette}
              onClick={() => setCreateOpen(true)}
            >
              <PlusIcon />
              Create token
            </Button>
          </HStack>
        </HStack>

        {/* Toolbar: environment scope, status filter, search */}
        <HStack
          render={<section />}
          justify="between"
          wrap="wrap"
          gap="3"
          aria-label="Filter and search tokens"
        >
          <SegmentGroup.Root
            size="sm"
            aria-label="Filter by environment"
            value={envFilter}
            onValueChange={(next) => {
              setEnvFilter(next as EnvironmentFilter);
              setPage(1);
            }}
          >
            {ENVIRONMENT_OPTIONS.map((option) => (
              <SegmentGroup.Item key={option.value} value={option.value}>
                {option.label}
              </SegmentGroup.Item>
            ))}
          </SegmentGroup.Root>

          <HStack wrap="wrap" gap="2" style={styles.toolbarFilters}>
            <Select.Root
              size="sm"
              variant="outline"
              items={STATUS_OPTIONS}
              value={statusFilter}
              onValueChange={(next) => {
                setStatusFilter((next as StatusFilter) ?? "all");
                setPage(1);
              }}
              style={styles.statusSelect}
            >
              <Select.Control>
                <Select.Trigger aria-label="Filter by token status">
                  <Select.Value placeholder="All statuses" />
                </Select.Trigger>
                <Select.IndicatorGroup>
                  <Select.Icon />
                </Select.IndicatorGroup>
              </Select.Control>
              <Select.Content>
                {STATUS_OPTIONS.map((option) => (
                  <Select.Item key={option.value} value={option.value}>
                    <Select.ItemText>{option.label}</Select.ItemText>
                    <Select.ItemIndicator />
                  </Select.Item>
                ))}
              </Select.Content>
            </Select.Root>

            <div {...stylex.props(styles.searchWrap)}>
              <SearchIcon style={styles.searchIcon} />
              <Input
                size="sm"
                variant="outline"
                type="search"
                aria-label="Search tokens by name, prefix, owner, or scope"
                placeholder="Search name, prefix, owner…"
                value={query}
                onChange={(event) => {
                  setQuery(event.target.value);
                  setPage(1);
                }}
                style={styles.searchInput}
              />
              {query.length > 0 ? (
                <IconButton
                  variant="ghost"
                  size="2xs"
                  aria-label="Clear search"
                  style={styles.searchClearBtn}
                  onClick={() => {
                    setQuery("");
                    setPage(1);
                  }}
                >
                  <CloseIcon />
                </IconButton>
              ) : null}
            </div>

            {activeFilterCount > 0 ? (
              <Button variant="ghost" size="sm" onClick={clearAllFilters}>
                Reset
              </Button>
            ) : null}
          </HStack>
        </HStack>

        {/* Table Card & Pagination */}
        <VStack render={<section />} gap="4" aria-label="API tokens table">
          <div {...stylex.props(styles.tableCard)}>
            {visible.length === 0 ? (
              <EmptyState.Root size="md" align="center">
                <EmptyState.Content>
                  <EmptyState.Indicator palette={grayPalette}>
                    <EmptyState.Icon
                      viewBox="0 0 24 24"
                      fill="none"
                      stroke="currentColor"
                      strokeWidth="1.6"
                      strokeLinecap="round"
                      strokeLinejoin="round"
                      aria-hidden="true"
                    >
                      <circle cx="11" cy="11" r="7" />
                      <path d="m20 20-3.5-3.5M8.5 11h5" />
                    </EmptyState.Icon>
                  </EmptyState.Indicator>
                  <EmptyState.Title>
                    {rows.length === 0 ? "No API tokens yet" : "No matching tokens"}
                  </EmptyState.Title>
                  <EmptyState.Description>
                    {rows.length === 0
                      ? "Create a new service token or restore the sample Cinder Cloud inventory."
                      : "No API keys match your current search query and active filters."}
                  </EmptyState.Description>
                  <EmptyState.Actions>
                    {rows.length === 0 ? (
                      <Button variant="surface" size="sm" onClick={handleResetDemo}>
                        Restore sample tokens
                      </Button>
                    ) : (
                      <Button variant="surface" size="sm" onClick={clearAllFilters}>
                        Clear filters
                      </Button>
                    )}
                  </EmptyState.Actions>
                </EmptyState.Content>
              </EmptyState.Root>
            ) : (
              <>
                {allPageSelected && visible.length > pageRows.length && !allVisibleSelected ? (
                  <HStack justify="center" wrap="wrap" gap="2" style={styles.selectionBanner}>
                    <Text render={<span />} size="xs" tone="muted">
                      All {pageRows.length} tokens on this page are selected.
                    </Text>
                    <Button
                      variant="plain"
                      size="xs"
                      palette={accentPalette}
                      onClick={selectAllVisible}
                    >
                      Select all {visible.length} matching tokens
                    </Button>
                  </HStack>
                ) : null}

                <div {...stylex.props(styles.tableScroll)}>
                  <Table.Root variant="line" size="md">
                    <Table.Header>
                      <Table.Row style={styles.tableHeaderRow}>
                        <Table.ColumnHeader
                          style={[styles.tableHeaderCell, styles.checkboxCol]}
                        >
                          <Checkbox.Root size="sm" palette={accentPalette}>
                            <Checkbox.Control
                              aria-label="Select all tokens on this page"
                              checked={
                                allPageSelected
                                  ? true
                                  : somePageSelected
                                    ? "indeterminate"
                                    : false
                              }
                              onCheckedChange={togglePageSelection}
                            >
                              <Checkbox.Indicator>
                                {somePageSelected ? <MinusIcon /> : <CheckIcon />}
                              </Checkbox.Indicator>
                            </Checkbox.Control>
                          </Checkbox.Root>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "name"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("name")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "name" && styles.sortButtonActive,
                            )}
                          >
                            <span>Token</span>
                            <SortIcon active={sortKey === "name"} direction={sortDirection} />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "environment"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("environment")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "environment" && styles.sortButtonActive,
                            )}
                          >
                            <span>Environment</span>
                            <SortIcon
                              active={sortKey === "environment"}
                              direction={sortDirection}
                            />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "owner"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("owner")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "owner" && styles.sortButtonActive,
                            )}
                          >
                            <span>Owner</span>
                            <SortIcon active={sortKey === "owner"} direction={sortDirection} />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "scope"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("scope")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "scope" && styles.sortButtonActive,
                            )}
                          >
                            <span>Scope</span>
                            <SortIcon active={sortKey === "scope"} direction={sortDirection} />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "lastUsedISO"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("lastUsedISO")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "lastUsedISO" && styles.sortButtonActive,
                            )}
                          >
                            <span>Last used</span>
                            <SortIcon
                              active={sortKey === "lastUsedISO"}
                              direction={sortDirection}
                            />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "requests24h"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={[styles.tableHeaderCell, styles.alignEnd]}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("requests24h")}
                            {...stylex.props(
                              styles.sortButton,
                              styles.sortButtonEnd,
                              sortKey === "requests24h" && styles.sortButtonActive,
                            )}
                          >
                            <span>Req / 24h</span>
                            <SortIcon
                              active={sortKey === "requests24h"}
                              direction={sortDirection}
                            />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          aria-sort={
                            sortKey === "status"
                              ? sortDirection === "asc"
                                ? "ascending"
                                : "descending"
                              : "none"
                          }
                          style={styles.tableHeaderCell}
                        >
                          <button
                            type="button"
                            onClick={() => handleSort("status")}
                            {...stylex.props(
                              styles.sortButton,
                              sortKey === "status" && styles.sortButtonActive,
                            )}
                          >
                            <span>Status</span>
                            <SortIcon active={sortKey === "status"} direction={sortDirection} />
                          </button>
                        </Table.ColumnHeader>

                        <Table.ColumnHeader
                          style={[styles.tableHeaderCell, styles.actionsCol]}
                        >
                          <VisuallyHidden>Actions</VisuallyHidden>
                        </Table.ColumnHeader>
                      </Table.Row>
                    </Table.Header>

                    <Table.Body>
                      {pageRows.map((row) => {
                        const isSelected = selectedIds.has(row.id);
                        return (
                          <Table.Row
                            key={row.id}
                            data-selected={isSelected ? "" : undefined}
                            style={[
                              styles.tableBodyRow,
                              isSelected && styles.tableBodyRowSelected,
                            ]}
                          >
                            <Table.Cell style={[styles.tableBodyCell, styles.checkboxCol]}>
                              <Checkbox.Root size="sm" palette={accentPalette}>
                                <Checkbox.Control
                                  aria-label={`Select ${row.name}`}
                                  checked={isSelected}
                                  onCheckedChange={(next) => toggleRow(row.id, next === true)}
                                />
                              </Checkbox.Root>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <VStack gap="1" style={styles.tokenCell}>
                                <Text
                                  render={<span />}
                                  size="sm"
                                  weight="medium"
                                  tone={row.status === "revoked" ? "muted" : "default"}
                                >
                                  {row.name}
                                </Text>
                                <Code
                                  variant="subtle"
                                  size="xs"
                                  palette={grayPalette}
                                  style={styles.tokenPrefix}
                                >
                                  {row.prefix}
                                </Code>
                              </VStack>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <Badge
                                variant="subtle"
                                size="sm"
                                palette={ENVIRONMENT_PALETTES[row.environment]}
                              >
                                {ENVIRONMENT_LABELS[row.environment]}
                              </Badge>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <HStack
                                render={<span />}
                                gap="2"
                                style={styles.ownerCell}
                                title={`${row.owner.name} · ${row.owner.team} (${row.owner.email})`}
                              >
                                <Avatar.Root
                                  size="xs"
                                  variant="subtle"
                                  palette={AVATAR_PALETTES[row.owner.tone]}
                                >
                                  <Avatar.Fallback>{row.owner.initials}</Avatar.Fallback>
                                </Avatar.Root>
                                <Text render={<span />} size="sm">
                                  {row.owner.name}
                                </Text>
                              </HStack>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <Badge
                                variant="outline"
                                size="sm"
                                palette={SCOPE_PALETTES[row.scope]}
                              >
                                {SCOPE_LABELS[row.scope]}
                              </Badge>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <Text
                                render={<span />}
                                size="sm"
                                tone="muted"
                                tabular="true"
                                style={styles.nowrap}
                              >
                                {row.lastUsedLabel}
                              </Text>
                            </Table.Cell>

                            <Table.Cell style={[styles.tableBodyCell, styles.alignEnd]}>
                              <Text
                                render={<span />}
                                size="sm"
                                tone={row.requests24h === 0 ? "muted" : "default"}
                                tabular="true"
                                style={styles.nowrap}
                              >
                                {integerFormatter.format(row.requests24h)}
                              </Text>
                            </Table.Cell>

                            <Table.Cell style={styles.tableBodyCell}>
                              <Status.Root size="sm" palette={STATUS_PALETTES[row.status]}>
                                <Status.Indicator />
                                {STATUS_LABELS[row.status]}
                              </Status.Root>
                            </Table.Cell>

                            <Table.Cell style={[styles.tableBodyCell, styles.actionsCol]}>
                              <Menu.Root size="sm">
                                <Menu.Trigger
                                  render={
                                    <IconButton
                                      variant="ghost"
                                      size="xs"
                                      aria-label={`Actions for ${row.name}`}
                                    />
                                  }
                                >
                                  <MoreIcon />
                                </Menu.Trigger>
                                <Menu.Content align="end" style={styles.menuWidth}>
                                  <Menu.Item onSelect={() => handleCopyPrefix(row)}>
                                    <Menu.ItemText>Copy key prefix</Menu.ItemText>
                                  </Menu.Item>
                                  <Menu.Item
                                    disabled={row.status === "revoked"}
                                    onSelect={() => handleRotateSecret(row)}
                                  >
                                    <Menu.ItemText>Rotate secret</Menu.ItemText>
                                  </Menu.Item>
                                  <Menu.Item
                                    onSelect={() =>
                                      handleToggleRevoke(
                                        [row.id],
                                        row.status === "revoked" ? "active" : "revoked",
                                      )
                                    }
                                  >
                                    <Menu.ItemText>
                                      {row.status === "revoked"
                                        ? "Restore token"
                                        : "Revoke token"}
                                    </Menu.ItemText>
                                  </Menu.Item>
                                  <Menu.Separator />
                                  <Menu.Item
                                    destructive
                                    onSelect={() => requestDelete([row.id])}
                                  >
                                    <Menu.ItemText>Delete token</Menu.ItemText>
                                  </Menu.Item>
                                </Menu.Content>
                              </Menu.Root>
                            </Table.Cell>
                          </Table.Row>
                        );
                      })}
                    </Table.Body>
                  </Table.Root>
                </div>
              </>
            )}
          </div>

          {/* Pagination footer */}
          {visible.length > 0 ? (
            <HStack justify="between" wrap="wrap" gap="3" style={styles.footer}>
              <HStack wrap="wrap" gap="3">
                <Text size="xs" tone="muted" tabular="true">
                  Showing {pageStart + 1}–{pageEnd} of {pluralize(visible.length, "token")}
                </Text>

                <Select.Root
                  size="xs"
                  variant="outline"
                  items={PAGE_SIZE_OPTIONS}
                  value={String(pageSize)}
                  onValueChange={(next) => {
                    const parsed = Number(next);
                    if (Number.isFinite(parsed) && parsed > 0) {
                      setPageSize(parsed);
                      setPage(1);
                    }
                  }}
                  style={styles.pageSizeSelect}
                >
                  <Select.Control>
                    <Select.Trigger aria-label="Rows per page">
                      <Select.Value />
                    </Select.Trigger>
                    <Select.IndicatorGroup>
                      <Select.Icon />
                    </Select.IndicatorGroup>
                  </Select.Control>
                  <Select.Content>
                    {PAGE_SIZE_OPTIONS.map((option) => (
                      <Select.Item key={option.value} value={option.value}>
                        <Select.ItemText>{option.label}</Select.ItemText>
                        <Select.ItemIndicator />
                      </Select.Item>
                    ))}
                  </Select.Content>
                </Select.Root>
              </HStack>

              <Pagination.Root
                count={visible.length}
                page={safePage}
                pageSize={pageSize}
                siblingCount={1}
                onPageChange={(details) => setPage(details.page)}
                variant="outline"
                size="sm"
                palette={accentPalette}
              >
                <Pagination.PrevTrigger />
                <Pagination.Items />
                <Pagination.NextTrigger />
              </Pagination.Root>
            </HStack>
          ) : null}
        </VStack>
      </VStack>

      {/* Contextual floating ActionBar when rows are selected */}
      {selectedRows.length > 0 ? (
        <ActionBar.Positioner>
          <ActionBar.Content style={styles.actionBarContent}>
            <ActionBar.SelectionTrigger>
              <span>{selectedRows.length} selected</span>
            </ActionBar.SelectionTrigger>
            <ActionBar.Separator />
            <Button
              variant="ghost"
              size="xs"
              onClick={() => handleExport(selectedRows)}
            >
              Export CSV
            </Button>
            <Button
              variant="ghost"
              size="xs"
              onClick={() =>
                handleToggleRevoke(
                  selectedRows.map((row) => row.id),
                  "revoked",
                )
              }
            >
              Revoke
            </Button>
            <Button
              variant="ghost"
              size="xs"
              palette={redPalette}
              onClick={() => requestDelete(selectedRows.map((row) => row.id))}
            >
              Delete
            </Button>
            <ActionBar.Separator />
            <Button variant="ghost" size="xs" onClick={clearSelection}>
              Clear
            </Button>
          </ActionBar.Content>
        </ActionBar.Positioner>
      ) : null}

      {/* Create token dialog */}
      <Dialog.Root
        size="sm"
        open={createOpen}
        onOpenChange={(open) => setCreateOpen(open)}
      >
        <Dialog.Backdrop />
        <Dialog.Content>
          <Dialog.Header style={styles.dialogHeader}>
            <Dialog.Title>Create API token</Dialog.Title>
            <Dialog.Description>
              Issue a scoped Cinder Cloud service token for programmatic access.
            </Dialog.Description>
          </Dialog.Header>
          <form onSubmit={handleCreateToken}>
            <Dialog.Body>
              <VStack gap="4">
                <Field.Root>
                  <Field.Label>Token name</Field.Label>
                  <Input
                    size="sm"
                    variant="outline"
                    required
                    placeholder="e.g. Payments Webhook Relay"
                    value={newTokenName}
                    onChange={(event) => setNewTokenName(event.target.value)}
                  />
                </Field.Root>

                <Grid columns="2" gap="3">
                  <Field.Root>
                    <Field.Label>Environment</Field.Label>
                    <Select.Root
                      size="sm"
                      variant="outline"
                      items={CREATE_ENVIRONMENT_OPTIONS}
                      value={newTokenEnv}
                      onValueChange={(next) => {
                        if (next) setNewTokenEnv(next as TokenEnvironment);
                      }}
                      style={styles.dialogSelectFull}
                    >
                      <Select.Control>
                        <Select.Trigger>
                          <Select.Value />
                        </Select.Trigger>
                        <Select.IndicatorGroup>
                          <Select.Icon />
                        </Select.IndicatorGroup>
                      </Select.Control>
                      <Select.Content>
                        {CREATE_ENVIRONMENT_OPTIONS.map((option) => (
                          <Select.Item key={option.value} value={option.value}>
                            <Select.ItemText>{option.label}</Select.ItemText>
                            <Select.ItemIndicator />
                          </Select.Item>
                        ))}
                      </Select.Content>
                    </Select.Root>
                  </Field.Root>

                  <Field.Root>
                    <Field.Label>Scope</Field.Label>
                    <Select.Root
                      size="sm"
                      variant="outline"
                      items={SCOPE_OPTIONS}
                      value={newTokenScope}
                      onValueChange={(next) => {
                        if (next) setNewTokenScope(next as TokenScope);
                      }}
                      style={styles.dialogSelectFull}
                    >
                      <Select.Control>
                        <Select.Trigger>
                          <Select.Value />
                        </Select.Trigger>
                        <Select.IndicatorGroup>
                          <Select.Icon />
                        </Select.IndicatorGroup>
                      </Select.Control>
                      <Select.Content>
                        {SCOPE_OPTIONS.map((option) => (
                          <Select.Item key={option.value} value={option.value}>
                            <Select.ItemText>{option.label}</Select.ItemText>
                            <Select.ItemIndicator />
                          </Select.Item>
                        ))}
                      </Select.Content>
                    </Select.Root>
                  </Field.Root>
                </Grid>
              </VStack>
            </Dialog.Body>
            <Dialog.Footer>
              <Button
                type="button"
                variant="ghost"
                size="sm"
                onClick={() => setCreateOpen(false)}
              >
                Cancel
              </Button>
              <Button
                type="submit"
                variant="solid"
                size="sm"
                palette={accentPalette}
                disabled={newTokenName.trim().length === 0}
              >
                Create token
              </Button>
            </Dialog.Footer>
          </form>
        </Dialog.Content>
      </Dialog.Root>

      {/* Destructive deletion confirmation dialog */}
      <AlertDialog.Root
        size="sm"
        open={pendingDeleteIds !== null}
        onOpenChange={(open) => {
          if (!open) setPendingDeleteIds(null);
        }}
      >
        <AlertDialog.Backdrop />
        <AlertDialog.Content>
          <AlertDialog.Header>
            <AlertDialog.Icon palette={redPalette}>
              <TrashIcon />
            </AlertDialog.Icon>
            <AlertDialog.Title>{deleteDialogTitle}</AlertDialog.Title>
          </AlertDialog.Header>
          <AlertDialog.Body>
            <AlertDialog.Description>
              Any services authenticating with{" "}
              {pendingDeleteIds && pendingDeleteIds.length > 1
                ? "these keys"
                : "this key"}{" "}
              will lose API access immediately. This action cannot be undone.
            </AlertDialog.Description>
          </AlertDialog.Body>
          <AlertDialog.Footer>
            <AlertDialog.Cancel render={<Button variant="ghost" size="sm" />}>
              Cancel
            </AlertDialog.Cancel>
            <Button
              variant="solid"
              size="sm"
              palette={redPalette}
              onClick={confirmDelete}
            >
              Delete
            </Button>
          </AlertDialog.Footer>
        </AlertDialog.Content>
      </AlertDialog.Root>

      <Toaster toaster={queue} />
    </div>
  );
}
```

Credit: Inspired by [Simple Table](https://astryx.atmeta.com/playground?template=table) from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.)
