{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "installment-picker",
  "title": "Installment Picker",
  "description": "Card installment choices with amounts, interest terms, and totals in list, tiles, and compact variants.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "radio-group",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/components/installment-picker.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { type ComponentProps, createContext, useContext, useId, useState } from \"react\";\n\nimport { RadioGroup, RadioGroupItem } from \"@/components/ui/radio-group\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const INSTALLMENT_PICKER_VARIANTS = [\"list\", \"tiles\", \"compact\"] as const;\n\nexport type InstallmentPickerVariant = (typeof INSTALLMENT_PICKER_VARIANTS)[number];\n\nexport function formatBrl(value: number) {\n  return new Intl.NumberFormat(\"pt-BR\", { style: \"currency\", currency: \"BRL\" }).format(value);\n}\n\nexport type InstallmentPickerProps = Omit<\n  ComponentProps<\"fieldset\">,\n  \"defaultValue\" | \"onChange\"\n> & {\n  variant?: InstallmentPickerVariant;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Form field name submitted with the selected value. */\n  name?: string;\n};\n\ntype InstallmentPickerContextValue = {\n  variant: InstallmentPickerVariant;\n  name: string;\n  legendId: string;\n  value: string | undefined;\n  disabled: boolean;\n  select: (value: string) => void;\n};\n\nconst InstallmentPickerContext = createContext<InstallmentPickerContextValue | null>(null);\n\nfunction useInstallmentPicker(part: string) {\n  const context = useContext(InstallmentPickerContext);\n  if (!context) throw new Error(`${part} must be used within InstallmentPicker`);\n  return context;\n}\n\nexport function InstallmentPicker({\n  variant = \"list\",\n  value,\n  defaultValue,\n  onValueChange,\n  name,\n  disabled = false,\n  children,\n  className,\n  ...props\n}: InstallmentPickerProps) {\n  const generatedName = useId();\n  const legendId = useId();\n  const [internalValue, setInternalValue] = useState(defaultValue);\n  const current = value ?? internalValue;\n\n  const select = (next: string) => {\n    if (value === undefined) setInternalValue(next);\n    onValueChange?.(next);\n  };\n\n  return (\n    <InstallmentPickerContext.Provider\n      value={{ variant, name: name ?? generatedName, legendId, value: current, disabled, select }}\n    >\n      <fieldset\n        data-slot=\"installment-picker\"\n        data-variant={variant}\n        className={cn(\n          \"group/installments m-0 grid w-full min-w-0 border-0 p-0 text-foreground\",\n          disabled && \"opacity-55\",\n          className,\n        )}\n        {...props}\n        disabled={disabled}\n      >\n        {children}\n      </fieldset>\n    </InstallmentPickerContext.Provider>\n  );\n}\n\nexport type InstallmentPickerLegendProps = ComponentProps<\"legend\">;\n\nexport function InstallmentPickerLegend({\n  children = \"Parcelamento\",\n  className,\n  ...props\n}: InstallmentPickerLegendProps) {\n  const context = useInstallmentPicker(\"InstallmentPickerLegend\");\n  return (\n    <legend\n      data-slot=\"installment-picker-legend\"\n      className={cn(\n        \"float-left w-full p-0 font-medium text-muted-foreground\",\n        context.variant === \"compact\"\n          ? \"mb-1 text-[11.5px] leading-4\"\n          : \"mb-1.5 text-[12px] leading-4\",\n        className,\n      )}\n      {...props}\n      id={context.legendId}\n    >\n      {children}\n    </legend>\n  );\n}\n\nconst optionsVariants = cva(\"clear-both grid min-w-0\", {\n  variants: {\n    variant: {\n      list: \"gap-0 overflow-hidden rounded-[14px] border border-border bg-card *:not-first:border-t *:not-first:border-border\",\n      tiles: \"@container/tiles grid-cols-[repeat(auto-fill,minmax(148px,1fr))] gap-2\",\n      compact: \"gap-0.5 rounded-xl border border-border bg-card p-0.5\",\n    },\n  },\n});\n\nexport type InstallmentPickerOptionsProps = Omit<\n  ComponentProps<typeof RadioGroup>,\n  \"value\" | \"defaultValue\" | \"onValueChange\" | \"name\"\n>;\n\n/** The radio group. Arrow keys move between options and select them. */\nexport function InstallmentPickerOptions({ className, ...props }: InstallmentPickerOptionsProps) {\n  const context = useInstallmentPicker(\"InstallmentPickerOptions\");\n  return (\n    <RadioGroup\n      data-slot=\"installment-picker-options\"\n      aria-labelledby={context.legendId}\n      className={cn(optionsVariants({ variant: context.variant }), className)}\n      {...props}\n      name={context.name}\n      value={context.value ?? \"\"}\n      onValueChange={context.select}\n      disabled={context.disabled}\n    />\n  );\n}\n\nconst optionVariants = cva(\n  \"group/option relative flex min-w-0 cursor-pointer items-center transition-[background-color,box-shadow] duration-[120ms] ease-out has-data-[state=checked]:bg-accent has-data-checked:bg-accent has-disabled:cursor-not-allowed has-disabled:opacity-55 has-focus-visible:outline-2 has-focus-visible:-outline-offset-2 has-focus-visible:outline-ring motion-reduce:transition-none\",\n  {\n    variants: {\n      variant: {\n        list: \"gap-3 px-3.5 py-3 hover:bg-accent/60\",\n        tiles:\n          \"flex-col items-start gap-1 rounded-xl bg-card p-3 shadow-[inset_0_0_0_1px_var(--border)] hover:shadow-[inset_0_0_0_1px_var(--border-strong)] has-data-[state=checked]:shadow-[inset_0_0_0_1px_var(--foreground)] has-data-checked:shadow-[inset_0_0_0_1px_var(--foreground)]\",\n        compact: \"gap-2.5 rounded-[10px] px-2.5 py-1.5 hover:bg-accent/60\",\n      },\n    },\n  },\n);\n\nexport type InstallmentPickerOptionProps = Omit<ComponentProps<\"label\">, \"htmlFor\"> & {\n  value: string;\n  disabled?: boolean;\n};\n\n/** One choice. The whole row is the click target for its radio. */\nexport function InstallmentPickerOption({\n  value,\n  disabled = false,\n  children,\n  className,\n  ...props\n}: InstallmentPickerOptionProps) {\n  const context = useInstallmentPicker(\"InstallmentPickerOption\");\n  const contentId = useId();\n  const checked = context.value === value;\n  return (\n    <label\n      data-slot=\"installment-picker-option\"\n      data-state={checked ? \"checked\" : \"unchecked\"}\n      className={cn(optionVariants({ variant: context.variant }), className)}\n      {...props}\n    >\n      <RadioGroupItem\n        value={value}\n        disabled={context.disabled || disabled}\n        aria-labelledby={contentId}\n        className={cn(\n          \"size-4 border-0 bg-transparent shadow-[inset_0_0_0_1.5px_var(--subtle-foreground)] transition-[background-color,box-shadow] duration-[140ms] ease-out-quint focus-visible:ring-0 data-[state=checked]:bg-primary data-checked:bg-primary data-[state=checked]:shadow-none data-checked:shadow-none disabled:opacity-100 motion-reduce:transition-none dark:bg-transparent dark:data-[state=checked]:bg-primary dark:data-checked:bg-primary [&_svg]:size-1.5 [&_svg]:fill-primary-foreground [&_svg]:stroke-0 [&_svg]:animate-in [&_svg]:zoom-in-0 [&_svg]:duration-150 [&_svg]:ease-out-quint motion-reduce:[&_svg]:animate-none\",\n          context.variant === \"tiles\" && \"absolute top-3 right-3\",\n          context.variant === \"compact\" && \"size-3.5\",\n        )}\n      />\n      <span\n        id={contentId}\n        className={cn(\n          \"grid min-w-0 flex-1 items-baseline gap-x-2 gap-y-0.5\",\n          context.variant === \"tiles\"\n            ? \"w-full grid-cols-1 pr-6\"\n            : \"grid-cols-[auto_minmax(0,1fr)_auto]\",\n        )}\n      >\n        {children}\n      </span>\n    </label>\n  );\n}\n\nexport type InstallmentPickerCountProps = ComponentProps<\"span\">;\n\n/** The number of installments, such as \"12x\". */\nexport function InstallmentPickerCount({ className, ...props }: InstallmentPickerCountProps) {\n  return (\n    <span\n      data-slot=\"installment-picker-count\"\n      className={cn(\n        \"font-medium text-foreground tabular-nums group-data-[variant=compact]/installments:text-[12.5px] group-data-[variant=list]/installments:min-w-7 group-data-[variant=list]/installments:text-[13px] group-data-[variant=tiles]/installments:text-[12px] group-data-[variant=tiles]/installments:text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type InstallmentPickerAmountProps = ComponentProps<\"span\">;\n\n/** The amount of each installment. */\nexport function InstallmentPickerAmount({ className, ...props }: InstallmentPickerAmountProps) {\n  return (\n    <span\n      data-slot=\"installment-picker-amount\"\n      className={cn(\n        \"min-w-0 truncate text-foreground tabular-nums group-data-[variant=compact]/installments:text-[12.5px] group-data-[variant=list]/installments:text-[13px] group-data-[variant=tiles]/installments:text-[17px] group-data-[variant=tiles]/installments:leading-6 group-data-[variant=tiles]/installments:font-semibold\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type InstallmentPickerTermsProps = ComponentProps<\"span\"> & {\n  /** Marks interest-free terms with the success tint. */\n  interestFree?: boolean;\n};\n\n/** The interest terms or the final total, such as \"sem juros\" or \"total R$ 574,80\". */\nexport function InstallmentPickerTerms({\n  interestFree = false,\n  className,\n  ...props\n}: InstallmentPickerTermsProps) {\n  return (\n    <span\n      data-slot=\"installment-picker-terms\"\n      data-interest-free={interestFree || undefined}\n      className={cn(\n        \"justify-self-end text-[11.5px] leading-4 tabular-nums group-data-[variant=tiles]/installments:justify-self-start\",\n        interestFree\n          ? \"inline-flex h-5 items-center rounded-full bg-success/14 px-2 font-medium text-success-ink\"\n          : \"text-subtle-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/uai/installment-picker.tsx"
    }
  ],
  "categories": [
    "brazil",
    "commerce",
    "forms"
  ],
  "type": "registry:ui"
}