{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ranking-table",
  "title": "Ranking table",
  "description": "A landlord ranking with a sentence-style measure picker, direction toggle, sortable columns and mobile cards.",
  "dependencies": [],
  "registryDependencies": [
    "https://bash-ui-registry.vercel.app/r/sort-by-heading.json"
  ],
  "files": [
    {
      "path": "registry/items/ranking-table/ranking-table.tsx",
      "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { SortByHeading } from \"@/components/sort-by-heading\";\n\nexport type LandlordRow = {\n  id: string;\n  href?: string;\n  name: string | null;\n  handle: string;\n  grossKobo: number;\n  platformFeeKobo: number;\n  paymentCount: number;\n};\n\n// Sort is client-side over the rows the server already returned, so switching\n// key/direction is instant — no navigation, no scroll reset.\nconst OPTIONS = [\n  { key: \"fee\", label: \"platform fee\", get: (r: LandlordRow) => r.platformFeeKobo },\n  { key: \"gmv\", label: \"rent collected\", get: (r: LandlordRow) => r.grossKobo },\n  { key: \"avg\", label: \"avg payment\", get: (r: LandlordRow) => (r.paymentCount > 0 ? r.grossKobo / r.paymentCount : 0) },\n  { key: \"payments\", label: \"payments\", get: (r: LandlordRow) => r.paymentCount },\n] as const;\n\nexport type SortKey = (typeof OPTIONS)[number][\"key\"];\n\nexport type RankingTableProps = { rows: LandlordRow[]; prefix?: string; defaultSort?: SortKey; defaultDirection?: \"desc\" | \"asc\"; limit?: number };\nexport function RankingTable({ rows, prefix = \"Top landlords by\", defaultSort = \"fee\", defaultDirection = \"desc\", limit = 10 }: RankingTableProps) {\n  const [sortKey, setSortKey] = useState<SortKey>(defaultSort);\n  const [dir, setDir] = useState<\"desc\" | \"asc\">(defaultDirection);\n\n  const active = OPTIONS.find((o) => o.key === sortKey)!;\n  const sorted = [...rows]\n    .sort((a, b) => (active.get(a) - active.get(b)) * (dir === \"asc\" ? 1 : -1))\n    .slice(0, Math.max(0, limit));\n\n  const arrow = dir === \"desc\" ? \"↓\" : \"↑\";\n\n  return (\n    <section className=\"@container w-full min-w-0 space-y-3 font-body text-ink\">\n      <SortByHeading prefix={prefix} options={OPTIONS.map(option => ({ value: option.key, label: option.label }))} value={sortKey} onValueChange={value => setSortKey(value as SortKey)} direction={dir} onDirectionChange={setDir} />\n\n      <div className=\"rounded-panel border border-rule bg-card hidden overflow-x-auto @3xl:block\">\n        <table className=\"w-full min-w-[620px] text-sm\">\n          <thead>\n            <tr className=\"border-b border-rule text-left text-xs uppercase tracking-wide text-dim\">\n              <th className=\"px-5 py-3 font-medium\">Landlord</th>\n              {OPTIONS.map((o) => (\n                <th key={o.key} className=\"px-5 py-3 text-right font-medium\">\n                  <button\n                    type=\"button\"\n                    onClick={() => setSortKey(o.key)}\n                    className={`uppercase tracking-wide transition-colors hover:text-ink ${\n                      sortKey === o.key ? \"text-ink\" : \"\"\n                    }`}\n                  >\n                    {o.label === \"avg payment\" ? \"Avg\" : o.label}\n                    {sortKey === o.key ? ` ${arrow}` : \"\"}\n                  </button>\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {sorted.map((l) => {\n              const avg = l.paymentCount > 0 ? Math.round(l.grossKobo / l.paymentCount) : 0;\n              return (\n                <tr key={l.id} className=\"border-b border-rule last:border-0\">\n                  <td className=\"px-5 py-3\">\n                    <a\n                      href={l.href}\n                      className=\"transition-colors hover:text-lead\"\n                    >\n                      {l.name ?? l.handle}\n                    </a>\n                  </td>\n                  <td className={`px-5 py-3 text-right tabular-nums ${sortKey === \"fee\" ? \"font-heading\" : \"text-dim\"}`}>\n                    {formatKobo(l.platformFeeKobo)}\n                  </td>\n                  <td className={`px-5 py-3 text-right tabular-nums ${sortKey === \"gmv\" ? \"font-heading\" : \"text-dim\"}`}>\n                    {formatKobo(l.grossKobo)}\n                  </td>\n                  <td className={`px-5 py-3 text-right tabular-nums ${sortKey === \"avg\" ? \"font-heading\" : \"text-dim\"}`}>\n                    {formatKobo(avg)}\n                  </td>\n                  <td className={`px-5 py-3 text-right tabular-nums ${sortKey === \"payments\" ? \"font-heading\" : \"text-dim\"}`}>\n                    {l.paymentCount}\n                  </td>\n                </tr>\n              );\n            })}\n            {sorted.length === 0 && (\n              <tr>\n                <td colSpan={5} className=\"px-5 py-10 text-center text-sm text-dim\">\n                  No revenue in this window yet.\n                </td>\n              </tr>\n            )}\n          </tbody>\n        </table>\n      </div>\n\n      <div className=\"rounded-panel border border-rule bg-card divide-y divide-rule @3xl:hidden\">\n        {sorted.map((l) => {\n          const avg = l.paymentCount > 0 ? Math.round(l.grossKobo / l.paymentCount) : 0;\n          return (\n            <div key={l.id} className=\"p-4\">\n              <a\n                href={l.href}\n                className=\"font-heading text-lg transition-colors hover:text-lead\"\n              >\n                {l.name ?? l.handle}\n              </a>\n              <dl className=\"mt-3 grid grid-cols-2 gap-x-4 gap-y-2 text-sm\">\n                {[\n                  { label: \"Platform fee\", value: formatKobo(l.platformFeeKobo) },\n                  { label: \"Rent collected\", value: formatKobo(l.grossKobo) },\n                  { label: \"Avg payment\", value: formatKobo(avg) },\n                  { label: \"Payments\", value: String(l.paymentCount) },\n                ].map((stat) => (\n                  <div key={stat.label} className=\"flex items-baseline justify-between gap-2\">\n                    <dt className=\"text-xs text-dim\">{stat.label}</dt>\n                    <dd className=\"tabular-nums\">{stat.value}</dd>\n                  </div>\n                ))}\n              </dl>\n            </div>\n          );\n        })}\n        {sorted.length === 0 && (\n          <p className=\"py-10 text-center text-sm text-dim\">\n            No revenue in this window yet.\n          </p>\n        )}\n      </div>\n    </section>\n  );\n}\n\nexport function formatKobo(kobo: number): string {\n  const naira = kobo / 100;\n  return (\n    \"₦\" +\n    naira.toLocaleString(\"en-NG\", {\n      minimumFractionDigits: 0,\n      maximumFractionDigits: 2,\n    })\n  );\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "kind": "pattern",
    "whenToUse": "Use for comparing landlord collections and platform fees. Sorting stays local to the supplied rows, with optional row destinations supplied by the caller.",
    "origin": {
      "project": "Ledge",
      "path": "src/components/admin/top-landlords.tsx"
    },
    "credits": []
  },
  "type": "registry:block"
}
