{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "geo-02",
  "description": "The leading countries with flags, values and shares, and the rest summed into one row.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/country-flag.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/leaderboard.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/geo/geo-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { CountryFlag } from '@/registry/components/dashboardblocks/country-flag'\nimport {\n  Leaderboard,\n  LeaderboardBar,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface CountryRow {\n  /** ISO 3166-1 alpha-2 code, such as `GB`. */\n  code: string\n  name: string\n  value: number\n}\n\ninterface Geo2Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  countries?: CountryRow[]\n  /** Defaults to a sentence about the leading country's share. */\n  description?: string\n  formatter?: (value: number) => string\n  /** How many countries get a row of their own. @default 8 */\n  limit?: number\n  /** Names the row that sums the rest; `null` leaves it out. @default 'Other countries' */\n  otherLabel?: string | null\n  title: string\n  total?: number\n  /** @default 'sessions' */\n  unit?: string\n}\n\nconst exampleProps: Geo2Props = {\n  countries: [\n    { code: 'US', name: 'United States', value: 48_210 },\n    { code: 'GB', name: 'United Kingdom', value: 14_380 },\n    { code: 'DE', name: 'Germany', value: 11_920 },\n    { code: 'IN', name: 'India', value: 10_470 },\n    { code: 'CA', name: 'Canada', value: 7_860 },\n    { code: 'FR', name: 'France', value: 6_940 },\n    { code: 'BR', name: 'Brazil', value: 5_310 },\n    { code: 'AU', name: 'Australia', value: 4_820 },\n    { code: 'NL', name: 'Netherlands', value: 3_560 },\n    { code: 'JP', name: 'Japan', value: 3_110 },\n    { code: 'ES', name: 'Spain', value: 2_740 },\n    { code: 'SE', name: 'Sweden', value: 1_980 },\n    { code: 'MX', name: 'Mexico', value: 1_870 },\n    { code: 'SG', name: 'Singapore', value: 1_420 },\n  ],\n  title: 'Top countries',\n}\n\nconst Geo2 = (props: Geo2Props) => {\n  const {\n    countries = [],\n    formatter = (value: number) => formatNumber(value),\n    limit = 8,\n    otherLabel = 'Other countries',\n    errorMessage,\n    status,\n    title,\n    unit = 'sessions',\n  } = props\n  const sorted = [...countries].sort((a, b) => b.value - a.value)\n  const total = props.total ?? countries.reduce((sum, country) => sum + country.value, 0)\n  const shown = sorted.slice(0, limit)\n  const other =\n    otherLabel === null\n      ? 0\n      : total - shown.reduce((sum, country) => sum + country.value, 0)\n  const largest = Math.max(shown[0]?.value ?? 0, other)\n  const share = (value: number) =>\n    formatPercent(total > 0 ? value / total : 0, {\n      maximumFractionDigits: 1,\n      minimumFractionDigits: 1,\n    })\n  const [first] = sorted\n  const {\n    description = first\n      ? `${first.name} sent ${formatPercent(total > 0 ? first.value / total : 0, { maximumFractionDigits: 0 })} of ${formatter(total)} ${unit}.`\n      : undefined,\n  } = props\n\n  const rows = [\n    ...shown.map((country) => ({ ...country, key: country.code })),\n    ...(other > 0\n      ? [{ code: undefined, key: 'other', name: otherLabel, value: other }]\n      : []),\n  ]\n\n  return (\n    <BlockStateProvider\n      errorMessage={errorMessage}\n      state={getBlockState(status, countries)}\n    >\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.5 border-t pt-4'>\n              <div className='text-muted-foreground flex justify-between px-2 text-xs'>\n                <span>Country</span>\n                <span className='capitalize'>{unit}</span>\n              </div>\n              <BlockStateRows rows={9} />\n              {!status && rows.length > 0 && (\n                <Leaderboard>\n                  {rows.map((row, index) => (\n                    <LeaderboardItem key={row.key}>\n                      <LeaderboardBar\n                        className={\n                          row.code === undefined\n                            ? 'bg-muted'\n                            : index === 0\n                              ? 'bg-[color-mix(in_oklab,var(--color-chart-2)_32%,transparent)]'\n                              : undefined\n                        }\n                        delay={index * 100}\n                        value={largest > 0 ? (row.value / largest) * 100 : 0}\n                      />\n                      <CountryFlag code={row.code} />\n                      <LeaderboardLabel\n                        className={cn(\n                          'truncate',\n                          row.code === undefined && 'text-muted-foreground',\n                        )}\n                      >\n                        {row.name}\n                      </LeaderboardLabel>\n                      <span className='text-muted-foreground shrink-0 text-xs tabular-nums'>\n                        {share(row.value)}\n                        <span className='sr-only'> of total</span>\n                      </span>\n                      <LeaderboardValue className='w-14'>\n                        {formatter(row.value)}\n                      </LeaderboardValue>\n                    </LeaderboardItem>\n                  ))}\n                </Leaderboard>\n              )}\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Geo2, exampleProps as geo2ExampleProps, type Geo2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/geo/geo-02.tsx"
    }
  ],
  "meta": {
    "shows": "The leading countries with flags, values and shares, and the rest summed into one row.",
    "size": "half",
    "usedWith": [
      "geo-03",
      "chart-panel-02",
      "breakdown-01"
    ],
    "component": "Geo2",
    "props": "{ countries?: { code: string; name: string; value: number }[]; description?: string; formatter?: (value: number) => string; limit?: number; otherLabel?: null | string; title: string; total?: number; unit?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
