{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-17",
  "title": "Checkout dialog",
  "description": "A billing period, card fields and a coupon field on demand.",
  "dependencies": [
    "motion",
    "react-payment-inputs"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/radio-group.json",
    "https://ui.ndekocode.dev/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/dialog/dialog-17.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useRef, useState } from 'react';\nimport { usePaymentInputs } from 'react-payment-inputs';\nimport images, { type CardImages } from 'react-payment-inputs/images';\n\nimport {\n  CreditCardIcon,\n  PlusIcon,\n  StoreIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport { RadioGroup, RadioGroupItem } from '@/registry/ndeko/ui/radio-group';\n\ntype BillingPlan = {\n  value: string;\n  label: string;\n  price: string;\n  badge?: string;\n};\n\nconst BILLING_PLANS: BillingPlan[] = [\n  { value: 'monthly', label: 'Monthly', price: '$32 per month' },\n  {\n    value: 'yearly',\n    label: 'Yearly',\n    price: '$320 per year',\n    badge: '2 months free',\n  },\n];\n\nconst CARD_IMAGES = images as unknown as CardImages;\n\nconst ICON_TILE =\n  'keycap-3d text-muted-foreground flex size-10 shrink-0 items-center justify-center rounded-lg';\n\nconst PLAN_TILE = [\n  'relative flex cursor-pointer flex-col gap-1 rounded-lg bg-card px-3.5 py-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)] hairline-ring ring-border transition-[box-shadow] duration-150',\n  'has-data-checked:shadow-[0_1px_2px_rgb(0_0_0/0.04),0_6px_16px_-8px_color-mix(in_oklab,var(--primary)_35%,transparent)] has-data-checked:ring-primary/45',\n  'has-focus-visible:ring-[3px] has-focus-visible:ring-ring/25',\n].join(' ');\n\nconst FIELD_REVEAL_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst FIELD_REVEAL_VARIANTS: Variants = {\n  hidden: { opacity: 0 },\n  shown: { opacity: 1 },\n};\n\nexport default function Dialog17() {\n  const id = useId();\n  const nameId = `${id}-name`;\n  const cardLabelId = `${id}-card`;\n  const couponId = `${id}-coupon`;\n  const [isCouponShown, setIsCouponShown] = useState(false);\n  const [couponCode, setCouponCode] = useState('');\n  const couponInputRef = useRef<HTMLInputElement>(null);\n  const {\n    meta,\n    getCardNumberProps,\n    getExpiryDateProps,\n    getCVCProps,\n    getCardImageProps,\n  } = usePaymentInputs();\n  const hasCardType = Boolean(meta.cardType);\n\n  useEffect(() => {\n    if (isCouponShown) {\n      couponInputRef.current?.focus();\n    }\n  }, [isCouponShown]);\n\n  function showCoupon() {\n    setIsCouponShown(true);\n  }\n\n  function updateCouponCode(event: React.ChangeEvent<HTMLInputElement>) {\n    setCouponCode(event.currentTarget.value);\n  }\n\n  return (\n    <Dialog>\n      <DialogTrigger render={<Button variant='outline' />}>\n        Check out\n      </DialogTrigger>\n      <DialogContent className='max-w-md'>\n        <div className='flex flex-col gap-4'>\n          <span aria-hidden='true' className={ICON_TILE}>\n            <StoreIcon className='size-5' />\n          </span>\n          <DialogHeader>\n            <DialogTitle>Confirm and pay</DialogTitle>\n            <DialogDescription>\n              Pay securely and cancel at any time.\n            </DialogDescription>\n          </DialogHeader>\n        </div>\n        <form className='flex flex-col gap-5'>\n          <div className='flex flex-col gap-4'>\n            <RadioGroup\n              defaultValue='yearly'\n              aria-label='Billing period'\n              className='grid-cols-2 gap-2'\n            >\n              {BILLING_PLANS.map((plan) => (\n                <label key={plan.value} className={PLAN_TILE}>\n                  <RadioGroupItem value={plan.value} className='sr-only' />\n                  <span className='flex items-start justify-between gap-2'>\n                    <span className='text-foreground text-[13px] font-medium'>\n                      {plan.label}\n                    </span>\n                    {plan.badge && (\n                      <Badge variant='success'>{plan.badge}</Badge>\n                    )}\n                  </span>\n                  <span className='text-muted-foreground text-[13px] tabular-nums'>\n                    {plan.price}\n                  </span>\n                </label>\n              ))}\n            </RadioGroup>\n            <div className='grid gap-2'>\n              <Label htmlFor={nameId}>Name on card</Label>\n              <Input\n                id={nameId}\n                autoComplete='cc-name'\n                placeholder='Amara Okafor'\n                required\n              />\n            </div>\n            <div\n              role='group'\n              aria-labelledby={cardLabelId}\n              className='grid gap-2'\n            >\n              <span\n                id={cardLabelId}\n                className='text-foreground text-[13px] leading-none font-medium'\n              >\n                Card details\n              </span>\n              <div>\n                <div className='relative focus-within:z-10'>\n                  <Input\n                    {...getCardNumberProps()}\n                    className='peer rounded-b-none pe-9 shadow-none [direction:inherit]'\n                  />\n                  <span className='text-muted-foreground/80 pointer-events-none absolute inset-y-0 end-0 flex items-center pe-2.5 peer-disabled:opacity-50'>\n                    {hasCardType && (\n                      <svg\n                        className='overflow-hidden rounded-sm'\n                        {...getCardImageProps({ images: CARD_IMAGES })}\n                        width={20}\n                      />\n                    )}\n                    {!hasCardType && <CreditCardIcon className='size-4' />}\n                  </span>\n                </div>\n                <div className='-mt-px flex'>\n                  <div className='min-w-0 flex-1 focus-within:z-10'>\n                    <Input\n                      {...getExpiryDateProps()}\n                      className='rounded-e-none rounded-t-none shadow-none [direction:inherit]'\n                    />\n                  </div>\n                  <div className='-ms-px min-w-0 flex-1 focus-within:z-10'>\n                    <Input\n                      {...getCVCProps()}\n                      className='rounded-s-none rounded-t-none shadow-none [direction:inherit]'\n                    />\n                  </div>\n                </div>\n              </div>\n            </div>\n            {!isCouponShown && (\n              <Button\n                type='button'\n                variant='ghost'\n                size='sm'\n                className='-ms-2.5 w-fit'\n                onClick={showCoupon}\n              >\n                <PlusIcon className='opacity-60' />\n                Add coupon\n              </Button>\n            )}\n            <AnimatePresence initial={false}>\n              {isCouponShown && (\n                <motion.div\n                  key='coupon'\n                  variants={FIELD_REVEAL_VARIANTS}\n                  initial='hidden'\n                  animate='shown'\n                  transition={FIELD_REVEAL_TRANSITION}\n                >\n                  <div className='grid gap-2'>\n                    <Label htmlFor={couponId}>Coupon code</Label>\n                    <Input\n                      ref={couponInputRef}\n                      id={couponId}\n                      placeholder='SPRING-25'\n                      value={couponCode}\n                      onChange={updateCouponCode}\n                    />\n                  </div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n          <Button type='button' size='lg' className='w-full'>\n            Subscribe\n          </Button>\n        </form>\n        <p className='text-muted-foreground text-center text-xs'>\n          Payments are non-refundable. You can cancel at any time.\n        </p>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}