{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo-03",
  "description": "Active users by city right now as markers sized by value on a dotted world map, with the busiest city named.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/geo.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/geo/geo-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  DotMap,\n  DotMapLegend,\n  type DotMapMarker,\n} from '@/registry/components/dashboardblocks/geo'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Geo3Props extends BlockStateProps {\n  /** Defaults to a sentence about the most active city. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  locations?: DotMapMarker[]\n  title: string\n  unit: string\n}\n\nconst exampleProps: Geo3Props = {\n  locations: [\n    {\n      country: 'US',\n      id: 'sfo',\n      lat: 37.77,\n      lon: -122.42,\n      name: 'San Francisco',\n      value: 2_840,\n    },\n    {\n      country: 'US',\n      id: 'nyc',\n      lat: 40.71,\n      lon: -74.01,\n      name: 'New York',\n      value: 3_460,\n    },\n    {\n      country: 'CA',\n      id: 'yyz',\n      lat: 43.65,\n      lon: -79.38,\n      name: 'Toronto',\n      value: 1_120,\n    },\n    {\n      country: 'MX',\n      id: 'mex',\n      lat: 19.43,\n      lon: -99.13,\n      name: 'Mexico City',\n      value: 690,\n    },\n    {\n      country: 'BR',\n      id: 'gru',\n      lat: -23.55,\n      lon: -46.63,\n      name: 'São Paulo',\n      value: 1_310,\n    },\n    {\n      country: 'GB',\n      id: 'lon',\n      lat: 51.51,\n      lon: -0.13,\n      name: 'London',\n      value: 2_970,\n    },\n    {\n      country: 'DE',\n      id: 'ber',\n      lat: 52.52,\n      lon: 13.4,\n      name: 'Berlin',\n      value: 1_580,\n    },\n    {\n      country: 'NG',\n      id: 'los',\n      lat: 6.52,\n      lon: 3.38,\n      name: 'Lagos',\n      value: 540,\n    },\n    {\n      country: 'IN',\n      id: 'blr',\n      lat: 12.97,\n      lon: 77.59,\n      name: 'Bengaluru',\n      value: 2_120,\n    },\n    {\n      country: 'SG',\n      id: 'sin',\n      lat: 1.35,\n      lon: 103.82,\n      name: 'Singapore',\n      value: 1_240,\n    },\n    {\n      country: 'JP',\n      id: 'tyo',\n      lat: 35.68,\n      lon: 139.69,\n      name: 'Tokyo',\n      value: 1_760,\n    },\n    {\n      country: 'AU',\n      id: 'syd',\n      lat: -33.87,\n      lon: 151.21,\n      name: 'Sydney',\n      value: 980,\n    },\n  ],\n  title: 'Active users',\n  unit: 'active users',\n}\n\nconst Geo3 = (props: Geo3Props) => {\n  const { locations = [], errorMessage, status, title, unit } = props\n  const state = getBlockState(status, locations)\n  const unitName = unit.charAt(0).toUpperCase() + unit.slice(1)\n  const total = locations.reduce((sum, location) => sum + location.value, 0)\n  const max = Math.max(0, ...locations.map((location) => location.value))\n  const top = locations.reduce<DotMapMarker | null>(\n    (best, location) => (best === null || location.value > best.value ? location : best),\n    null,\n  )\n  const share = (value: number) =>\n    formatPercent(total > 0 ? value / total : 0, { maximumFractionDigits: 0 })\n  const {\n    description = top\n      ? `${top.name} has the most ${unit} right now, ${share(top.value)} of them.`\n      : undefined,\n  } = props\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                {description && (\n                  <p className='text-muted-foreground text-sm'>{description}</p>\n                )}\n              </BlockReady>\n            </header>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <span className='text-muted-foreground text-sm'>\n                {state\n                  ? unitName\n                  : `${unitName} in ${formatNumber(locations.length)} cities`}\n              </span>\n              <KPIValue value={total} format={(value) => formatNumber(value)} />\n            </div>\n            <DotMap\n              describe={(location) =>\n                `${location.name}: ${formatNumber(location.value)} ${unit}, ${share(location.value)}`\n              }\n              footer={<DotMapLegend max={max} />}\n              label={`${title}, by city`}\n              labelLargest\n              markers={locations}\n              max={max}\n              nameHeader='City'\n              showShare\n              valueHeader={unitName}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Geo3, exampleProps as geo3ExampleProps, type Geo3Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/geo/geo-03.tsx"
    }
  ],
  "meta": {
    "shows": "Active users by city right now as markers sized by value on a dotted world map, with the busiest city named.",
    "size": "full",
    "usedWith": [
      "realtime-01",
      "geo-02"
    ],
    "component": "Geo3",
    "props": "{ description?: string; locations?: { country?: string; id: string; lat: number; lon: number; name: string; value: number }[]; title: string; unit: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
