{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-01",
  "description": "Failed and blocked sign-ins per day against a typical day, with the failure rate, the spike in blocked attempts called out, and two-factor coverage.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/security/security-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartPlaceholder,\n  chartAxisProps,\n  chartBarCursor,\n  chartBarValueLabel,\n  chartFadedColor,\n  chartGridProps,\n  chartReferenceLabel,\n  chartReferenceProps,\n  ChartTooltipContent,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  formatCompact,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  Bar,\n  BarChart,\n  CartesianGrid,\n  LabelList,\n  ReferenceLine,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface SignInDay {\n  blocked: number\n  failed: number\n  label: string\n  succeeded: number\n}\n\ninterface Security1Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  days?: SignInDay[]\n  description: string\n  /** Share of active users with multi-factor authentication, 0–1. */\n  mfaCoverage?: number\n  title: string\n}\n\nconst DAYS = [\n  'Sep 13',\n  'Sep 14',\n  'Sep 15',\n  'Sep 16',\n  'Sep 17',\n  'Sep 18',\n  'Sep 19',\n  'Sep 20',\n  'Sep 21',\n  'Sep 22',\n  'Sep 23',\n  'Sep 24',\n  'Sep 25',\n  'Sep 26',\n]\nconst SUCCEEDED = [\n  1_820, 910, 2_140, 2_260, 2_190, 2_230, 2_010, 980, 870, 2_310, 2_280, 2_350, 2_270,\n  1_190,\n]\nconst FAILED = [96, 51, 118, 104, 131, 99, 92, 48, 55, 121, 108, 116, 103, 64]\nconst BLOCKED = [12, 8, 15, 11, 9, 14, 188, 242, 31, 17, 12, 10, 13, 6]\n\nconst exampleProps: Security1Props = {\n  days: DAYS.map((label, index) => ({\n    blocked: BLOCKED[index],\n    failed: FAILED[index],\n    label,\n    succeeded: SUCCEEDED[index],\n  })),\n  description: 'Failed and blocked sign-in attempts per day, over the last 14 days.',\n  mfaCoverage: 0.87,\n  title: 'Sign-in activity',\n}\n\nconst BLOCKED_COLOR = 'var(--color-red-600)'\nconst FAILED_COLOR = chartFadedColor(BLOCKED_COLOR)\n\nconst SPIKE_MULTIPLIER = 3\n\nconst median = (values: number[]) => {\n  const sorted = [...values].sort((a, b) => a - b)\n  return sorted[Math.floor(sorted.length / 2)] ?? 0\n}\n\nconst Security1 = (props: Security1Props) => {\n  const { days = [], description, mfaCoverage, errorMessage, status, title } = props\n  const state = getBlockState(status, days)\n  const totals = days.reduce(\n    (sum, day) => ({\n      blocked: sum.blocked + day.blocked,\n      failed: sum.failed + day.failed,\n      succeeded: sum.succeeded + day.succeeded,\n    }),\n    { blocked: 0, failed: 0, succeeded: 0 },\n  )\n  const attempts = totals.succeeded + totals.failed + totals.blocked\n  const refused = totals.failed + totals.blocked\n  const typicalBlocked = median(days.map((day) => day.blocked))\n  const typicalRefused = median(days.map((day) => day.failed + day.blocked))\n  const spikes = days.filter((day) => day.blocked > typicalBlocked * SPIKE_MULTIPLIER)\n  const peakIndex = days.reduce(\n    (best, day, index) => (day.blocked > (days[best]?.blocked ?? -1) ? index : best),\n    0,\n  )\n  const spikeBlocked = spikes.reduce((sum, day) => sum + day.blocked, 0)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\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              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <div className='flex flex-wrap items-start gap-x-10 gap-y-4 border-t pt-4'>\n              <div className='flex flex-col gap-1'>\n                <p className='text-muted-foreground text-sm'>Failed or blocked</p>\n                <KPIValue\n                  value={attempts > 0 ? refused / attempts : 0}\n                  format={(value) =>\n                    formatPercent(value, {\n                      maximumFractionDigits: 1,\n                      minimumFractionDigits: 1,\n                    })\n                  }\n                />\n                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm tabular-nums'>\n                    {formatNumber(refused)} of {formatNumber(attempts)} attempts\n                  </p>\n                </BlockReady>\n              </div>\n              {(!state || state === 'loading') && (\n                <dl className='flex flex-wrap gap-x-10 gap-y-4'>\n                  <div className='flex flex-col gap-1'>\n                    <dt className='text-muted-foreground text-sm'>Blocked</dt>\n                    <dd>\n                      <KPIValue\n                        className='text-2xl'\n                        value={totals.blocked}\n                        format={(value) => formatNumber(value)}\n                      />\n                    </dd>\n                  </div>\n                  {mfaCoverage !== undefined && (\n                    <div className='flex flex-col gap-1'>\n                      <dt className='text-muted-foreground text-sm'>Users with MFA</dt>\n                      <dd>\n                        <KPIValue\n                          className='text-2xl'\n                          value={mfaCoverage}\n                          format={(value) =>\n                            formatPercent(value, { maximumFractionDigits: 0 })\n                          }\n                        />\n                      </dd>\n                    </div>\n                  )}\n                </dl>\n              )}\n            </div>\n            <BlockReady className='text-sm'>\n              <p className='text-sm text-pretty'>\n                {spikes.length > 0 ? (\n                  <>\n                    <span className='font-medium text-red-700 dark:text-red-400'>\n                      {formatNumber(spikeBlocked)} blocked\n                    </span>{' '}\n                    on {spikes.map((day) => day.label).join(' and ')},{' '}\n                    <span className='text-muted-foreground'>\n                      against {formatNumber(typicalBlocked)} on a typical day.\n                    </span>\n                  </>\n                ) : (\n                  <span className='text-muted-foreground'>\n                    No unusual spikes in blocked attempts.\n                  </span>\n                )}\n              </p>\n            </BlockReady>\n            {(!state || state === 'loading') && (\n              <ChartPanelLegend\n                items={[\n                  { color: FAILED_COLOR, label: 'Failed' },\n                  { color: BLOCKED_COLOR, label: 'Blocked' },\n                ]}\n              />\n            )}\n            {state ? (\n              <ChartPlaceholder height={224} />\n            ) : (\n              <>\n                <ChartPanelFigure className='h-56'>\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <BarChart\n                      aria-label={`${title} chart`}\n                      data={days}\n                      margin={{ top: 20, right: 8, bottom: 0, left: 0 }}\n                    >\n                      <CartesianGrid {...chartGridProps} />\n                      <XAxis\n                        {...chartAxisProps}\n                        dataKey='label'\n                        interval='preserveStartEnd'\n                        minTickGap={20}\n                      />\n                      <YAxis\n                        {...chartAxisProps}\n                        tickFormatter={formatCompact}\n                        width={chartValueAxisWidth}\n                      />\n                      <Tooltip\n                        content={(tooltipProps) => (\n                          <ChartTooltipContent {...tooltipProps} />\n                        )}\n                        cursor={chartBarCursor}\n                      />\n                      <Bar\n                        dataKey='failed'\n                        fill={FAILED_COLOR}\n                        maxBarSize={28}\n                        name='Failed'\n                        stackId='refused'\n                      />\n                      <Bar\n                        dataKey='blocked'\n                        fill={BLOCKED_COLOR}\n                        maxBarSize={28}\n                        name='Blocked'\n                        radius={[4, 4, 0, 0]}\n                        stackId='refused'\n                      >\n                        {spikes.length > 0 && (\n                          <LabelList\n                            dataKey='blocked'\n                            content={chartBarValueLabel(\n                              peakIndex,\n                              (value) => `${formatNumber(value)} blocked`,\n                            )}\n                          />\n                        )}\n                      </Bar>\n                      {typicalRefused > 0 && (\n                        <ReferenceLine\n                          {...chartReferenceProps}\n                          y={typicalRefused}\n                          label={{\n                            ...chartReferenceLabel,\n                            value: `typical ${formatNumber(typicalRefused)}`,\n                            position: 'insideBottomLeft',\n                            dy: -4,\n                          }}\n                        />\n                      )}\n                    </BarChart>\n                  </ResponsiveContainer>\n                </ChartPanelFigure>\n                <ChartPanelTable\n                  caption={`${title}: ${description}`}\n                  columns={[\n                    { key: 'label', label: 'Day' },\n                    { key: 'succeeded', label: 'Succeeded' },\n                    { key: 'failed', label: 'Failed' },\n                    { key: 'blocked', label: 'Blocked' },\n                  ]}\n                  rows={days}\n                />\n              </>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Security1,\n  exampleProps as security1ExampleProps,\n  type Security1Props,\n  type SignInDay,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/security/security-01.tsx"
    }
  ],
  "meta": {
    "shows": "Failed and blocked sign-ins per day against a typical day, with the failure rate, the spike in blocked attempts called out, and two-factor coverage.",
    "size": "full",
    "usedWith": [
      "security-02",
      "security-04",
      "alerts-01"
    ],
    "component": "Security1",
    "props": "{ days?: { blocked: number; failed: number; label: string; succeeded: number }[]; description: string; mfaCoverage?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
