{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "boleto-payment",
  "title": "Boleto Payment",
  "description": "A boleto with the grouped linha digitável and copy, an ITF barcode drawn from the code, due-date urgency, a BolePix tab, and card, plain, and compact variants.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "badge",
    "button",
    "toggle",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/components/boleto-payment.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { Barcode, Check, CheckCircle2, Copy, Download, QrCode, XCircle } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  createContext,\n  type KeyboardEvent,\n  type ReactNode,\n  useContext,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\n\nimport { Badge } from \"@/components/ui/badge\";\nimport { Button } from \"@/components/ui/button\";\nimport { toggleVariants } from \"@/components/ui/toggle\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const BOLETO_PAYMENT_VARIANTS = [\"card\", \"plain\", \"compact\"] as const;\nexport const BOLETO_PAYMENT_STATUSES = [\"pending\", \"paid\", \"overdue\", \"cancelled\"] as const;\nexport const BOLETO_PAYMENT_METHODS = [\"boleto\", \"pix\"] as const;\n\nexport type BoletoPaymentVariant = (typeof BOLETO_PAYMENT_VARIANTS)[number];\nexport type BoletoPaymentStatus = (typeof BOLETO_PAYMENT_STATUSES)[number];\nexport type BoletoPaymentMethod = (typeof BOLETO_PAYMENT_METHODS)[number];\n/** What the badge shows: the consumer status, plus \"due-today\" and \"overdue\" derived from the dates. */\nexport type BoletoPaymentDisplayStatus = BoletoPaymentStatus | \"due-today\";\n\ntype DateInput = Date | string | number;\n\nexport function formatBrl(value: number) {\n  return new Intl.NumberFormat(\"pt-BR\", { style: \"currency\", currency: \"BRL\" }).format(value);\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Linha digitável and barcode: pure string math (FEBRABAN layout, check digits mod 10 and mod 11).\n * -----------------------------------------------------------------------------------------------*/\n\nconst onlyDigits = (value: string) => value.replace(/\\D/g, \"\");\n\nfunction mod10(digits: string) {\n  let total = 0;\n  let weight = 2;\n  for (let index = digits.length - 1; index >= 0; index--) {\n    const product = Number(digits[index]) * weight;\n    total += Math.floor(product / 10) + (product % 10);\n    weight = weight === 2 ? 1 : 2;\n  }\n  return (10 - (total % 10)) % 10;\n}\n\nfunction mod11(digits: string) {\n  let total = 0;\n  let weight = 2;\n  for (let index = digits.length - 1; index >= 0; index--) {\n    total += Number(digits[index]) * weight;\n    weight = weight === 9 ? 2 : weight + 1;\n  }\n  const rest = 11 - (total % 11);\n  return rest === 0 || rest === 10 || rest === 11 ? 1 : rest;\n}\n\n/** The 44-digit barcode for a 47-digit linha digitável (dots and spaces are ignored). */\nexport function boletoBarcodeFromLine(line: string) {\n  const digits = onlyDigits(line);\n  if (digits.length !== 47) throw new Error(\"A linha digitável has 47 digits.\");\n  return (\n    digits.slice(0, 4) +\n    digits.slice(32, 47) +\n    digits.slice(4, 9) +\n    digits.slice(10, 20) +\n    digits.slice(21, 31)\n  );\n}\n\n/** The 47-digit linha digitável for a 44-digit barcode, with the three field check digits. */\nexport function boletoLineFromBarcode(barcode: string) {\n  const digits = onlyDigits(barcode);\n  if (digits.length !== 44) throw new Error(\"A boleto barcode has 44 digits.\");\n  const field1 = digits.slice(0, 4) + digits.slice(19, 24);\n  const field2 = digits.slice(24, 34);\n  const field3 = digits.slice(34, 44);\n  return (\n    field1 +\n    mod10(field1) +\n    field2 +\n    mod10(field2) +\n    field3 +\n    mod10(field3) +\n    digits.slice(4, 5) +\n    digits.slice(5, 19)\n  );\n}\n\n/** Checks the three field digits and the general mod-11 digit of a linha digitável. */\nexport function isValidBoletoLine(line: string) {\n  const digits = onlyDigits(line);\n  if (digits.length !== 47) return false;\n  const fields = [digits.slice(0, 10), digits.slice(10, 21), digits.slice(21, 32)];\n  if (fields.some((field) => mod10(field.slice(0, -1)) !== Number(field.slice(-1)))) return false;\n  const barcode = boletoBarcodeFromLine(digits);\n  return mod11(barcode.slice(0, 4) + barcode.slice(5)) === Number(barcode[4]);\n}\n\n/** The five printed groups: `AAAAA.AAAAA BBBBB.BBBBBB CCCCC.CCCCCC D EEEEEEEEEEEEEE`. */\nexport function boletoLineGroups(line: string) {\n  const d = onlyDigits(line);\n  return [\n    `${d.slice(0, 5)}.${d.slice(5, 10)}`,\n    `${d.slice(10, 15)}.${d.slice(15, 21)}`,\n    `${d.slice(21, 26)}.${d.slice(26, 32)}`,\n    d.slice(32, 33),\n    d.slice(33, 47),\n  ];\n}\n\nconst ITF_PATTERNS = [\n  \"nnwwn\",\n  \"wnnnw\",\n  \"nwnnw\",\n  \"wwnnn\",\n  \"nnwnw\",\n  \"wnwnn\",\n  \"nwwnn\",\n  \"nnnww\",\n  \"wnnwn\",\n  \"nwnwn\",\n];\n\n/**\n * ITF-25 (Interleaved 2 of 5) bars for a 44-digit barcode: start pattern, pairs of digits\n * interleaved as bars and spaces, stop pattern. Narrow is 1 unit and wide is 3.\n */\nexport function boletoBarcodeBars(barcode: string) {\n  const digits = onlyDigits(barcode);\n  let sequence = \"nnnn\";\n  for (let index = 0; index + 1 < digits.length; index += 2) {\n    const bars = ITF_PATTERNS[Number(digits[index])] ?? \"\";\n    const spaces = ITF_PATTERNS[Number(digits[index + 1])] ?? \"\";\n    for (let k = 0; k < 5; k++) sequence += `${bars[k]}${spaces[k]}`;\n  }\n  sequence += \"wnn\";\n  const bars: { x: number; width: number }[] = [];\n  let x = 0;\n  for (let index = 0; index < sequence.length; index++) {\n    const width = sequence[index] === \"w\" ? 3 : 1;\n    if (index % 2 === 0) bars.push({ x, width });\n    x += width;\n  }\n  return { bars, width: x };\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Dates: calendar days in the boleto's time zone, so server and client agree when `now` is passed.\n * -----------------------------------------------------------------------------------------------*/\n\nfunction calendarDay(value: DateInput, timeZone: string) {\n  if (typeof value === \"string\" && /^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n    const [year, month, day] = value.split(\"-\").map(Number);\n    return { year: year ?? 0, month: month ?? 1, day: day ?? 1 };\n  }\n  const parts = new Intl.DateTimeFormat(\"en-CA\", {\n    timeZone,\n    year: \"numeric\",\n    month: \"2-digit\",\n    day: \"2-digit\",\n  }).formatToParts(new Date(value));\n  const part = (type: string) => Number(parts.find((entry) => entry.type === type)?.value);\n  return { year: part(\"year\"), month: part(\"month\"), day: part(\"day\") };\n}\n\ntype CalendarDay = ReturnType<typeof calendarDay>;\n\nconst dayNumber = (day: CalendarDay) => Date.UTC(day.year, day.month - 1, day.day) / 86_400_000;\nconst pad = (value: number) => String(value).padStart(2, \"0\");\nexport function formatBoletoDate(day: CalendarDay) {\n  return `${pad(day.day)}/${pad(day.month)}/${day.year}`;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Root\n * -----------------------------------------------------------------------------------------------*/\n\nexport type BoletoPaymentProps = Omit<ComponentProps<\"section\">, \"onCopy\"> & {\n  variant?: BoletoPaymentVariant;\n  /** Payment state owned by the application. Due today and overdue are derived from the dates. */\n  status?: BoletoPaymentStatus;\n  /** The 47-digit linha digitável. Pass this or `barcode`. */\n  digitableLine?: string;\n  /** The 44-digit barcode. Pass this or `digitableLine`. */\n  barcode?: string;\n  /** The due date, as `YYYY-MM-DD` or a date. */\n  dueDate: DateInput;\n  /** Fixes \"today\" so server and client render the same due state. */\n  now?: DateInput;\n  /** When it was paid, for the paid caption. */\n  paidAt?: DateInput;\n  /** The BolePix copy-and-paste code. When set, a Pix tab can be shown. */\n  pixCode?: string;\n  /** Whether an overdue boleto can still be paid (with fees). */\n  payableAfterDue?: boolean;\n  /** The time zone that decides which calendar day it is. */\n  timeZone?: string;\n  /** Shows the barcode in compact, which hides it by default. */\n  showBarcode?: boolean;\n  method?: BoletoPaymentMethod;\n  defaultMethod?: BoletoPaymentMethod;\n  onMethodChange?: (method: BoletoPaymentMethod) => void;\n  /** Called after a successful copy with the copied text and what it was. */\n  onCopy?: (text: string, kind: BoletoPaymentMethod) => void;\n};\n\ntype CopyState = \"idle\" | \"copied\" | \"failed\";\n\ntype BoletoPaymentContextValue = {\n  variant: BoletoPaymentVariant;\n  status: BoletoPaymentStatus;\n  displayStatus: BoletoPaymentDisplayStatus;\n  line: string;\n  barcode: string;\n  groups: string[];\n  due: CalendarDay;\n  daysLeft: number;\n  paidAt: CalendarDay | null;\n  pixCode: string | undefined;\n  copyable: boolean;\n  showBarcode: boolean;\n  method: BoletoPaymentMethod;\n  setMethod: (method: BoletoPaymentMethod) => void;\n  copyState: Record<BoletoPaymentMethod, CopyState>;\n  flash: boolean;\n  copy: (kind: BoletoPaymentMethod) => Promise<void>;\n  titleId: string;\n  amountId: string;\n};\n\nconst BoletoPaymentContext = createContext<BoletoPaymentContextValue | null>(null);\n\nfunction useBoletoPayment(name: string) {\n  const context = useContext(BoletoPaymentContext);\n  if (!context) throw new Error(`${name} must be used within BoletoPayment`);\n  return context;\n}\n\nconst boletoPaymentVariants = cva(\"@container/boleto grid w-full min-w-0 text-card-foreground\", {\n  variants: {\n    variant: {\n      card: \"gap-4 rounded-[14px] border border-border bg-card p-5\",\n      plain: \"gap-4\",\n      compact: \"gap-3 rounded-xl border border-border bg-card p-3.5\",\n    },\n  },\n});\n\nexport function BoletoPayment({\n  variant = \"card\",\n  status = \"pending\",\n  digitableLine,\n  barcode,\n  dueDate,\n  now,\n  paidAt,\n  pixCode,\n  payableAfterDue = true,\n  timeZone = \"America/Sao_Paulo\",\n  showBarcode,\n  method,\n  defaultMethod = \"boleto\",\n  onMethodChange,\n  onCopy,\n  children,\n  className,\n  ...props\n}: BoletoPaymentProps) {\n  const line = digitableLine\n    ? onlyDigits(digitableLine)\n    : barcode\n      ? boletoLineFromBarcode(barcode)\n      : \"\";\n  const code = barcode ? onlyDigits(barcode) : line ? boletoBarcodeFromLine(line) : \"\";\n  const [mountedAt] = useState(() => Date.now());\n  const today = calendarDay(now ?? mountedAt, timeZone);\n  const due = calendarDay(dueDate, timeZone);\n  const daysLeft = dayNumber(due) - dayNumber(today);\n  const displayStatus: BoletoPaymentDisplayStatus =\n    status === \"pending\" && daysLeft < 0\n      ? \"overdue\"\n      : status === \"pending\" && daysLeft === 0\n        ? \"due-today\"\n        : status;\n  const copyable =\n    displayStatus === \"pending\" ||\n    displayStatus === \"due-today\" ||\n    (displayStatus === \"overdue\" && payableAfterDue);\n\n  const [internalMethod, setInternalMethod] = useState<BoletoPaymentMethod>(defaultMethod);\n  const currentMethod = pixCode ? (method ?? internalMethod) : \"boleto\";\n  const setMethod = (next: BoletoPaymentMethod) => {\n    if (next === currentMethod) return;\n    if (method === undefined) setInternalMethod(next);\n    onMethodChange?.(next);\n  };\n\n  const [copyState, setCopyState] = useState<Record<BoletoPaymentMethod, CopyState>>({\n    boleto: \"idle\",\n    pix: \"idle\",\n  });\n  const [flash, setFlash] = useState(false);\n  const onCopyRef = useRef(onCopy);\n  onCopyRef.current = onCopy;\n\n  useEffect(() => {\n    if (copyState.boleto !== \"copied\" && copyState.pix !== \"copied\") return;\n    const timer = window.setTimeout(() => setCopyState({ boleto: \"idle\", pix: \"idle\" }), 2000);\n    return () => window.clearTimeout(timer);\n  }, [copyState]);\n\n  useEffect(() => {\n    if (!flash) return;\n    // Each group holds the tint for 600ms, then fades over 240ms.\n    const timer = window.setTimeout(() => setFlash(false), 600);\n    return () => window.clearTimeout(timer);\n  }, [flash]);\n\n  const copy = async (kind: BoletoPaymentMethod) => {\n    const text = kind === \"pix\" ? (pixCode ?? \"\") : line;\n    try {\n      await navigator.clipboard.writeText(text);\n      setCopyState({ boleto: \"idle\", pix: \"idle\", [kind]: \"copied\" });\n      if (kind === \"boleto\") setFlash(true);\n      onCopyRef.current?.(text, kind);\n    } catch {\n      // Without clipboard access the digits stay selectable, and the hint says so.\n      setCopyState({ boleto: \"idle\", pix: \"idle\", [kind]: \"failed\" });\n    }\n  };\n\n  const titleId = useId();\n  const amountId = useId();\n\n  return (\n    <BoletoPaymentContext.Provider\n      value={{\n        variant,\n        status,\n        displayStatus,\n        line,\n        barcode: code,\n        groups: line ? boletoLineGroups(line) : [],\n        due,\n        daysLeft,\n        paidAt: paidAt === undefined ? null : calendarDay(paidAt, timeZone),\n        pixCode,\n        copyable,\n        showBarcode: showBarcode ?? variant !== \"compact\",\n        method: currentMethod,\n        setMethod,\n        copyState,\n        flash,\n        copy,\n        titleId,\n        amountId,\n      }}\n    >\n      <section\n        data-slot=\"boleto-payment\"\n        data-variant={variant}\n        data-status={displayStatus}\n        data-invalid={line && !isValidBoletoLine(line) ? \"\" : undefined}\n        aria-labelledby={`${titleId} ${amountId}`}\n        className={cn(boletoPaymentVariants({ variant }), className)}\n        {...props}\n      >\n        {children}\n      </section>\n    </BoletoPaymentContext.Provider>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nexport function BoletoPaymentHeader({ className, ...props }: ComponentProps<\"header\">) {\n  return (\n    <header\n      data-slot=\"boleto-payment-header\"\n      className={cn(\n        \"flex min-w-0 flex-wrap items-start justify-between gap-x-3 gap-y-2\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function BoletoPaymentTitle({\n  children = \"Pague com boleto\",\n  className,\n  ...props\n}: ComponentProps<\"h3\">) {\n  const context = useBoletoPayment(\"BoletoPaymentTitle\");\n  return (\n    <h3\n      data-slot=\"boleto-payment-title\"\n      id={context.titleId}\n      className={cn(\n        \"m-0 font-medium text-muted-foreground\",\n        context.variant === \"compact\"\n          ? \"text-[12.5px] leading-[18px]\"\n          : \"text-[13px] leading-[18px]\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </h3>\n  );\n}\n\nexport type BoletoPaymentAmountProps = Omit<ComponentProps<\"p\">, \"children\"> & { value: number };\n\nexport function BoletoPaymentAmount({ value, className, ...props }: BoletoPaymentAmountProps) {\n  const context = useBoletoPayment(\"BoletoPaymentAmount\");\n  return (\n    <p\n      data-slot=\"boleto-payment-amount\"\n      id={context.amountId}\n      className={cn(\n        \"m-0 mt-0.5 font-semibold tracking-[-0.01em] text-foreground tabular-nums\",\n        context.variant === \"compact\" ? \"text-[20px] leading-6\" : \"text-[28px] leading-8\",\n        className,\n      )}\n      {...props}\n    >\n      {formatBrl(value)}\n    </p>\n  );\n}\n\nconst statusCopy: Record<BoletoPaymentDisplayStatus, string> = {\n  pending: \"Aguardando pagamento\",\n  \"due-today\": \"Vence hoje\",\n  paid: \"Pago\",\n  overdue: \"Vencido\",\n  cancelled: \"Cancelado\",\n};\n\n/** A polite live region, so payment is announced when the status changes. */\nexport function BoletoPaymentStatusBadge({\n  children,\n  className,\n  ...props\n}: ComponentProps<\"span\">) {\n  const context = useBoletoPayment(\"BoletoPaymentStatusBadge\");\n  const status = context.displayStatus;\n  return (\n    <Badge\n      variant=\"secondary\"\n      data-slot=\"boleto-payment-status-badge\"\n      data-status={status}\n      className={cn(\n        \"h-6 shrink-0 gap-1.5 rounded-full border-0 px-2.5 py-0 text-[11.5px] font-medium\",\n        (status === \"pending\" || status === \"due-today\") && \"bg-warning/14 text-warning-ink\",\n        status === \"paid\" && \"bg-success/14 text-success-ink\",\n        status === \"overdue\" && \"bg-destructive/14 text-destructive-ink\",\n        status === \"cancelled\" && \"bg-muted text-muted-foreground\",\n        className,\n      )}\n      {...props}\n      role=\"status\"\n      aria-live=\"polite\"\n    >\n      <span\n        key={status}\n        className=\"inline-flex animate-in items-center gap-1.5 duration-200 fade-in-0 motion-reduce:animate-none\"\n      >\n        <span\n          aria-hidden=\"true\"\n          className={cn(\n            \"size-1.5 rounded-full bg-current\",\n            (status === \"pending\" || status === \"due-today\") &&\n              \"animate-pulse motion-reduce:animate-none\",\n          )}\n        />\n        {children ?? statusCopy[status]}\n      </span>\n    </Badge>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Methods (BolePix)\n * -----------------------------------------------------------------------------------------------*/\n\nconst METHOD_LABELS: Record<BoletoPaymentMethod, { label: string; icon: typeof Barcode }> = {\n  boleto: { label: \"Boleto\", icon: Barcode },\n  pix: { label: \"Pix\", icon: QrCode },\n};\n\nexport type BoletoPaymentMethodsProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** The group's accessible name. */\n  label?: string;\n};\n\n/**\n * \"Boleto | Pix\" for a BolePix. Renders only when `pixCode` is set. A radio group of segment\n * buttons (ToggleGroup's value differs between Radix and Base UI, so the selection stays here).\n */\nexport function BoletoPaymentMethods({\n  label = \"Forma de pagamento\",\n  className,\n  onKeyDown,\n  ...props\n}: BoletoPaymentMethodsProps) {\n  const context = useBoletoPayment(\"BoletoPaymentMethods\");\n  const refs = useRef<Record<string, HTMLButtonElement | null>>({});\n  if (!context.pixCode) return null;\n  const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(event);\n    if (event.defaultPrevented) return;\n    const keys = [\"ArrowRight\", \"ArrowLeft\", \"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n    if (!keys.includes(event.key)) return;\n    event.preventDefault();\n    const next: BoletoPaymentMethod =\n      event.key === \"Home\"\n        ? \"boleto\"\n        : event.key === \"End\"\n          ? \"pix\"\n          : context.method === \"boleto\"\n            ? \"pix\"\n            : \"boleto\";\n    context.setMethod(next);\n    refs.current[next]?.focus();\n  };\n  return (\n    <div\n      role=\"radiogroup\"\n      aria-label={label}\n      data-slot=\"boleto-payment-methods\"\n      className={cn(\n        \"relative isolate inline-grid grid-cols-2 justify-self-start rounded-full bg-muted p-0.5\",\n        className,\n      )}\n      {...props}\n      onKeyDown={handleKeyDown}\n    >\n      <span\n        aria-hidden=\"true\"\n        className={cn(\n          \"pointer-events-none absolute inset-y-0.5 left-0.5 -z-1 w-[calc(50%-2px)] rounded-full bg-card shadow-[0_0_0_1px_var(--border)] [transition:translate_240ms_cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none dark:bg-foreground/12 dark:shadow-none\",\n          context.method === \"pix\" && \"translate-x-full\",\n        )}\n      />\n      {BOLETO_PAYMENT_METHODS.map((value) => {\n        const { label: text, icon: Icon } = METHOD_LABELS[value];\n        const checked = context.method === value;\n        return (\n          // biome-ignore lint/a11y/useSemanticElements: a segment button in a radio group; ToggleGroupItem renders the same role=\"radio\" button.\n          <button\n            key={value}\n            ref={(node) => {\n              refs.current[value] = node;\n            }}\n            type=\"button\"\n            role=\"radio\"\n            aria-checked={checked}\n            data-state={checked ? \"on\" : \"off\"}\n            tabIndex={checked ? 0 : -1}\n            onClick={() => context.setMethod(value)}\n            className={cn(\n              toggleVariants(),\n              \"h-6 min-w-0 cursor-pointer gap-1.5 rounded-full border-0 bg-transparent px-3 text-[12px] font-medium text-subtle-foreground [transition:color_120ms_ease-out,scale_140ms_cubic-bezier(0.23,1,0.32,1)] hover:bg-transparent hover:text-foreground focus-visible:ring-0 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring focus-visible:outline-solid active:scale-[0.97] aria-checked:text-foreground data-[state=on]:bg-transparent motion-reduce:transition-none motion-reduce:active:scale-100 [&_svg]:size-3.5\",\n            )}\n          >\n            <Icon aria-hidden=\"true\" strokeWidth={1.75} />\n            {text}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\nexport function BoletoPaymentPanels({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"boleto-payment-panels\" className={cn(\"grid\", className)} {...props} />;\n}\n\nexport type BoletoPaymentPanelProps = ComponentProps<\"div\"> & { value: BoletoPaymentMethod };\n\n/**\n * One method's content. The active panel opens with `grid-template-rows`, so the card height\n * follows the switch; the incoming panel fades up 4px. The Pix panel renders only with `pixCode`.\n */\nexport function BoletoPaymentPanel({\n  value,\n  className,\n  children,\n  ...props\n}: BoletoPaymentPanelProps) {\n  const context = useBoletoPayment(\"BoletoPaymentPanel\");\n  if (value === \"pix\" && !context.pixCode) return null;\n  const active = context.method === value;\n  return (\n    <div\n      data-slot=\"boleto-payment-panel\"\n      data-value={value}\n      data-state={active ? \"active\" : \"inactive\"}\n      aria-hidden={!active || undefined}\n      inert={!active}\n      className={cn(\n        \"grid [transition:grid-template-rows_300ms_cubic-bezier(0.23,1,0.32,1),opacity_200ms_ease-out,translate_200ms_cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none\",\n        active\n          ? \"grid-rows-[1fr] translate-y-0 opacity-100\"\n          : \"pointer-events-none grid-rows-[0fr] translate-y-1 opacity-0\",\n        className,\n      )}\n      {...props}\n    >\n      <div className=\"-m-px grid min-h-0 gap-4 overflow-hidden p-px\">{children}</div>\n    </div>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Barcode\n * -----------------------------------------------------------------------------------------------*/\n\n/** The ITF-25 barcode drawn from the code, on a white tile scanners can read in both themes. */\nexport function BoletoPaymentBarcode({ children, className, ...props }: ComponentProps<\"figure\">) {\n  const context = useBoletoPayment(\"BoletoPaymentBarcode\");\n  if (!context.showBarcode) return null;\n  const settled = context.status === \"paid\" || context.status === \"cancelled\";\n  const { bars, width } = boletoBarcodeBars(context.barcode);\n  return (\n    <figure\n      data-slot=\"boleto-payment-barcode\"\n      className={cn(\n        \"isolate m-0 grid overflow-hidden rounded-[10px] bg-white px-3 py-2.5 shadow-[0_0_0_1px_var(--border)] *:[grid-area:1/1]\",\n        className,\n      )}\n      {...props}\n    >\n      <div\n        aria-hidden=\"true\"\n        className={cn(\n          \"transition-[filter,opacity] duration-240 ease-out-quint motion-reduce:transition-none\",\n          settled && \"opacity-22 blur-[2px]\",\n        )}\n      >\n        {children ?? (\n          <svg\n            viewBox={`0 0 ${width} 48`}\n            preserveAspectRatio=\"none\"\n            className=\"block h-12 w-full fill-black\"\n            aria-hidden=\"true\"\n            focusable=\"false\"\n          >\n            {bars.map((bar) => (\n              <rect key={bar.x} x={bar.x} y={0} width={bar.width} height={48} />\n            ))}\n          </svg>\n        )}\n      </div>\n      {settled ? (\n        <figcaption className=\"flex animate-in items-center justify-center gap-2 text-[12px] leading-4 font-medium text-black/85 duration-180 ease-out-quint fade-in-0 zoom-in-96 motion-reduce:animate-none\">\n          {context.status === \"paid\" ? (\n            <CheckCircle2\n              className=\"size-[18px] animate-in text-success-ink delay-60 duration-200 ease-out-quint fill-mode-both fade-in-0 zoom-in-50 motion-reduce:animate-none\"\n              strokeWidth={1.75}\n              aria-hidden=\"true\"\n            />\n          ) : (\n            <XCircle className=\"size-[18px] opacity-70\" strokeWidth={1.75} aria-hidden=\"true\" />\n          )}\n          {context.status === \"paid\"\n            ? context.paidAt\n              ? `Pago em ${formatBoletoDate(context.paidAt)}`\n              : \"Pago\"\n            : \"Boleto cancelado\"}\n        </figcaption>\n      ) : null}\n    </figure>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Linha digitável\n * -----------------------------------------------------------------------------------------------*/\n\n/** Stagger for the copy flash: 30ms per group, five groups. */\nconst FLASH_DELAYS = [\"delay-0\", \"delay-[30ms]\", \"delay-[60ms]\", \"delay-[90ms]\", \"delay-[120ms]\"];\n\nfunction CopyButton({\n  kind,\n  label,\n  compact,\n}: {\n  kind: BoletoPaymentMethod;\n  label: string;\n  compact?: boolean;\n}) {\n  const context = useBoletoPayment(\"BoletoPaymentCopy\");\n  const copied = context.copyState[kind] === \"copied\";\n  return (\n    <Button\n      type=\"button\"\n      data-slot=\"boleto-payment-copy\"\n      data-copied={copied || undefined}\n      disabled={!context.copyable}\n      onClick={() => void context.copy(kind)}\n      className={cn(\n        \"shrink-0 gap-1.5 rounded-full border-0 py-0 font-medium transition-[scale,background-color,color,filter] duration-[140ms] ease-out-quint focus-visible:ring-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring focus-visible:outline-solid active:scale-[0.97] disabled:pointer-events-auto disabled:cursor-not-allowed disabled:bg-secondary disabled:text-subtle-foreground disabled:opacity-100 motion-reduce:transition-none motion-reduce:active:scale-100\",\n        compact\n          ? \"h-7 px-3 text-[12px] has-[>svg]:px-3\"\n          : \"h-8 px-3.5 text-[12.5px] has-[>svg]:px-3.5\",\n        copied\n          ? \"bg-success/14 text-success-ink hover:bg-success/14\"\n          : \"bg-primary text-primary-foreground hover:bg-primary hover:brightness-[1.08]\",\n      )}\n    >\n      {copied ? (\n        <Check\n          key=\"copied\"\n          className=\"size-3.5 animate-in duration-200 ease-out-quint fade-in-0 zoom-in-50 motion-reduce:animate-none\"\n          strokeWidth={2.2}\n          aria-hidden=\"true\"\n        />\n      ) : (\n        <Copy key=\"copy\" className=\"size-3.5\" strokeWidth={2} aria-hidden=\"true\" />\n      )}\n      {/* Both labels share one cell, so the button keeps its width when the label swaps. */}\n      <span className=\"grid [&>*]:[grid-area:1/1]\">\n        <span className={cn(copied && \"invisible\")} aria-hidden={copied}>\n          {label}\n        </span>\n        <span className={cn(!copied && \"invisible\")} aria-hidden={!copied}>\n          Copiado\n        </span>\n      </span>\n    </Button>\n  );\n}\n\nexport type BoletoPaymentDigitableLineProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  label?: string;\n};\n\n/**\n * The linha digitável in five groups, always breaking after the third, with a copy button and a\n * spoken confirmation. Screen readers get the digits in blocks of five instead of one long number.\n */\nexport function BoletoPaymentDigitableLine({\n  label = \"Linha digitável\",\n  className,\n  ...props\n}: BoletoPaymentDigitableLineProps) {\n  const context = useBoletoPayment(\"BoletoPaymentDigitableLine\");\n  const compact = context.variant === \"compact\";\n  const labelId = useId();\n  const struck = !context.copyable;\n  const spoken = context.line.match(/.{1,5}/g)?.join(\" \") ?? \"\";\n  const state = context.copyState.boleto;\n\n  const digits = (\n    <code\n      aria-hidden=\"true\"\n      className={cn(\n        \"flex min-w-0 flex-1 flex-wrap font-mono text-muted-foreground tabular-nums select-all\",\n        compact ? \"gap-x-[7px] gap-y-0.5 text-[11.5px] leading-4\" : \"gap-x-2 text-[13px] leading-5\",\n        struck && \"line-through decoration-subtle-foreground/60\",\n      )}\n    >\n      {context.groups.map((group, index) => (\n        <span key={group + String(index)} className=\"contents\">\n          {index === 3 ? <span aria-hidden=\"true\" className=\"h-0 basis-full\" /> : null}\n          <span\n            aria-hidden=\"true\"\n            className={cn(\n              \"-mx-px rounded-[4px] px-px transition-[background-color,color] ease-out motion-reduce:transition-none\",\n              context.flash ? \"duration-120\" : \"duration-240\",\n              FLASH_DELAYS[index],\n              !struck && \"hover:bg-muted hover:text-foreground\",\n              context.flash && \"text-foreground motion-safe:bg-success/14\",\n            )}\n          >\n            {group}\n          </span>\n        </span>\n      ))}\n    </code>\n  );\n\n  return (\n    // biome-ignore lint/a11y/useSemanticElements: a fieldset would imply form controls the code does not have.\n    <div\n      data-slot=\"boleto-payment-digitable-line\"\n      className={cn(\"grid min-w-0 gap-2\", className)}\n      {...props}\n      role=\"group\"\n      aria-labelledby={labelId}\n    >\n      <div className={cn(\"flex min-w-0 items-center justify-between gap-2\", compact && \"sr-only\")}>\n        <span id={labelId} className=\"text-[12px] leading-4 font-medium text-muted-foreground\">\n          {label}\n        </span>\n        {compact ? null : <CopyButton kind=\"boleto\" label=\"Copiar código\" />}\n      </div>\n      <div\n        className={cn(\n          \"flex min-w-0 items-center gap-2 bg-background\",\n          compact ? \"rounded-[10px] py-[3px] pr-[3px] pl-2.5\" : \"rounded-xl px-3 py-2.5\",\n        )}\n      >\n        <span className=\"sr-only\">{spoken}</span>\n        {digits}\n        {compact ? <CopyButton kind=\"boleto\" label=\"Copiar\" compact /> : null}\n      </div>\n      {state === \"failed\" ? (\n        <p className=\"m-0 text-[11.5px] leading-4 text-subtle-foreground\">\n          Selecione e copie o código\n        </p>\n      ) : null}\n      <span role=\"status\" className=\"sr-only\">\n        {state === \"copied\"\n          ? \"Linha digitável copiada\"\n          : state === \"failed\"\n            ? \"Não foi possível copiar a linha digitável\"\n            : \"\"}\n      </span>\n    </div>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Pix tab\n * -----------------------------------------------------------------------------------------------*/\n\nexport type BoletoPaymentPixProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** The provider's QR image. */\n  children?: ReactNode;\n  description?: ReactNode;\n};\n\n/** The BolePix QR (from the provider) and \"Copiar Pix\". */\nexport function BoletoPaymentPix({\n  children,\n  description = \"Pagando com Pix, a confirmação chega na hora. O valor e o vencimento são os mesmos.\",\n  className,\n  ...props\n}: BoletoPaymentPixProps) {\n  const context = useBoletoPayment(\"BoletoPaymentPix\");\n  const state = context.copyState.pix;\n  if (!context.pixCode) return null;\n  return (\n    <div\n      data-slot=\"boleto-payment-pix\"\n      className={cn(\n        \"grid items-start gap-4 grid-cols-[minmax(0,1fr)] @min-[340px]/boleto:grid-cols-[132px_minmax(0,1fr)]\",\n        className,\n      )}\n      {...props}\n    >\n      <figure className=\"m-0 grid size-[132px] place-items-center justify-self-center overflow-hidden rounded-xl bg-white p-2.5 shadow-[0_0_0_1px_var(--border)] @min-[340px]/boleto:justify-self-start [&_img]:size-full [&_svg]:size-full\">\n        {children}\n      </figure>\n      <div className=\"grid content-start gap-2.5\">\n        <p className=\"m-0 text-[12.5px] leading-[18px] text-muted-foreground\">{description}</p>\n        <div className=\"justify-self-start\">\n          <CopyButton kind=\"pix\" label=\"Copiar Pix\" />\n        </div>\n        {state === \"failed\" ? (\n          <p className=\"m-0 text-[11.5px] leading-4 text-subtle-foreground\">\n            Selecione e copie o código\n          </p>\n        ) : null}\n        <span role=\"status\" className=\"sr-only\">\n          {state === \"copied\"\n            ? \"Código Pix copiado\"\n            : state === \"failed\"\n              ? \"Não foi possível copiar o código Pix\"\n              : \"\"}\n        </span>\n      </div>\n    </div>\n  );\n}\n\n/* -------------------------------------------------------------------------------------------------\n * Details and footer\n * -----------------------------------------------------------------------------------------------*/\n\nexport type BoletoPaymentDetailsProps = ComponentProps<\"dl\"> & {\n  /** Who receives the payment, for example \"Casa Aroeira Ltda · 12.345.678/0001-95\". */\n  beneficiary?: ReactNode;\n};\n\n/** Vencimento (with how long is left), Beneficiário, then any consumer rows. */\nexport function BoletoPaymentDetails({\n  beneficiary,\n  children,\n  className,\n  ...props\n}: BoletoPaymentDetailsProps) {\n  const context = useBoletoPayment(\"BoletoPaymentDetails\");\n  const date = formatBoletoDate(context.due);\n  const dueToday = context.displayStatus === \"due-today\";\n  const relative =\n    context.status !== \"pending\" || context.daysLeft < 0\n      ? null\n      : context.daysLeft === 1\n        ? \"amanhã\"\n        : context.daysLeft > 1\n          ? `em ${context.daysLeft} dias`\n          : null;\n  return (\n    <dl\n      data-slot=\"boleto-payment-details\"\n      className={cn(\n        \"m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3.5 gap-y-1.5 text-[12px] leading-4\",\n        className,\n      )}\n      {...props}\n    >\n      <BoletoPaymentDetail term=\"Vencimento\">\n        <b className={cn(\"font-medium text-foreground\", dueToday && \"text-warning-ink\")}>\n          {dueToday ? `Hoje, ${date}` : date}\n        </b>\n        {relative ? ` · ${relative}` : null}\n      </BoletoPaymentDetail>\n      {beneficiary ? (\n        <BoletoPaymentDetail term=\"Beneficiário\">{beneficiary}</BoletoPaymentDetail>\n      ) : null}\n      {children}\n    </dl>\n  );\n}\n\nexport type BoletoPaymentDetailProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  term: ReactNode;\n  children: ReactNode;\n};\n\nexport function BoletoPaymentDetail({\n  term,\n  children,\n  className,\n  ...props\n}: BoletoPaymentDetailProps) {\n  return (\n    <div data-slot=\"boleto-payment-detail\" className={cn(\"contents\", className)} {...props}>\n      <dt className=\"text-subtle-foreground\">{term}</dt>\n      <dd className=\"m-0 min-w-0 text-right text-muted-foreground tabular-nums\">{children}</dd>\n    </div>\n  );\n}\n\nexport function BoletoPaymentFooter({ className, ...props }: ComponentProps<\"footer\">) {\n  return (\n    <footer\n      data-slot=\"boleto-payment-footer\"\n      className={cn(\n        \"flex min-w-0 flex-wrap items-center justify-between gap-x-3 gap-y-2\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type BoletoPaymentDownloadProps = ComponentProps<\"a\">;\n\n/** A secondary pill that links to the consumer's PDF. */\nexport function BoletoPaymentDownload({\n  children = \"Baixar PDF\",\n  className,\n  ...props\n}: BoletoPaymentDownloadProps) {\n  return (\n    <a\n      data-slot=\"boleto-payment-download\"\n      className={cn(\n        \"inline-flex h-7 items-center gap-1.5 rounded-full bg-secondary px-3 text-[12px] leading-4 font-medium text-foreground no-underline transition-[background-color,scale] duration-[120ms,140ms] ease-out hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring focus-visible:outline-solid active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100\",\n        className,\n      )}\n      {...props}\n    >\n      <Download className=\"size-3.5\" strokeWidth={1.75} aria-hidden=\"true\" />\n      {children}\n    </a>\n  );\n}\n\nexport type BoletoPaymentHintProps = ComponentProps<\"p\"> & {\n  /** Danger ink for consumer lines such as an overdue fee notice. */\n  tone?: \"subtle\" | \"danger\";\n};\n\nexport function BoletoPaymentHint({\n  tone = \"subtle\",\n  children = \"Compensa em até 3 dias úteis\",\n  className,\n  ...props\n}: BoletoPaymentHintProps) {\n  return (\n    <p\n      data-slot=\"boleto-payment-hint\"\n      data-tone={tone}\n      className={cn(\n        \"m-0 text-[11.5px] leading-4\",\n        tone === \"danger\" ? \"text-[12px] text-destructive-ink\" : \"text-subtle-foreground\",\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </p>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/uai/boleto-payment.tsx"
    }
  ],
  "categories": [
    "brazil",
    "commerce",
    "checkout"
  ],
  "type": "registry:ui"
}