{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-12",
  "type": "registry:component",
  "title": "Dialog 12",
  "description": "Dialog 12. A dialog component for displaying important information or prompts.",
  "dependencies": [
    "input-otp",
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "dialog"
  ],
  "files": [
    {
      "path": "components/watermelon/dialog-12.tsx",
      "type": "registry:component",
      "content": "import React, { useEffect, useRef, useState } from 'react';\n\nimport { CheckIcon, MailIcon } from 'lucide-react';\n\nimport { OTPInput, type SlotProps } from 'input-otp';\n\nimport { Button } from '@/components/base-ui/button';\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/components/base-ui/dialog';\n\nimport { cn } from '@/lib/utils';\n\nconst CORRECT_CODE = '11208';\n\nconst Dialog12: React.FC = () => {\n  const [value, setValue] = useState<string>('');\n  const [hasGuessed, setHasGuessed] = useState<boolean | undefined>(undefined);\n  const inputRef = useRef<HTMLInputElement>(null);\n  const closeButtonRef = useRef<HTMLButtonElement>(null);\n\n  useEffect(() => {\n    if (hasGuessed) {\n      closeButtonRef.current?.focus();\n    }\n  }, [hasGuessed]);\n\n  async function onSubmit(e?: React.FormEvent<HTMLFormElement>) {\n    e?.preventDefault?.();\n    inputRef.current?.select();\n    await new Promise((r) => setTimeout(r, 100));\n    setHasGuessed(value === CORRECT_CODE);\n    setValue('');\n    setTimeout(() => {\n      inputRef.current?.blur();\n    }, 20);\n  }\n\n  return (\n    <Dialog>\n      <DialogTrigger>\n        <Button\n          variant=\"outline\"\n          className=\"rounded-2xl border border-zinc-200 bg-zinc-50 px-6 py-2 font-medium text-zinc-700 shadow-xl transition-all hover:bg-zinc-100 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-200 dark:hover:bg-zinc-800\"\n          style={{\n            boxShadow:\n              '0 6px 32px 0 rgba(24,24,27,0.16), 0 1.5px 6px 0 rgba(24,24,27,0.10)',\n          }}\n        >\n          Get OTP Code\n        </Button>\n      </DialogTrigger>\n      <DialogContent className=\"rounded-2xl border bg-white p-6 shadow-2xl sm:max-w-md dark:bg-zinc-900\">\n        <div className=\"flex flex-col items-center gap-3\">\n          <div\n            className={cn(\n              'flex size-10 shrink-0 items-center justify-center rounded-2xl border border-zinc-200 bg-zinc-100 shadow-lg dark:border-zinc-700 dark:bg-zinc-800',\n              {\n                'border-zinc-300 bg-zinc-200 dark:border-zinc-600 dark:bg-zinc-700':\n                  hasGuessed,\n              },\n            )}\n            aria-hidden=\"true\"\n          >\n            {hasGuessed ? (\n              <CheckIcon\n                className=\"text-zinc-700 dark:text-zinc-200\"\n                strokeWidth={1}\n              />\n            ) : (\n              <MailIcon\n                className=\"text-zinc-400 dark:text-zinc-500\"\n                strokeWidth={1}\n              />\n            )}\n          </div>\n          <DialogHeader className=\"text-center\">\n            <DialogTitle className=\"text-base font-semibold text-zinc-900 dark:text-zinc-100\">\n              {hasGuessed ? 'OTP Verified' : 'Enter OTP Code'}\n            </DialogTitle>\n            <DialogDescription className=\"text-sm text-zinc-600 dark:text-zinc-300\">\n              {hasGuessed ? (\n                <span>\n                  Your code was accepted.\n                  <br />\n                  Welcome! Verification complete.\n                </span>\n              ) : (\n                <span>\n                  Enter the 5-digit code sent to{' '}\n                  <strong>exa**le@gmail.com</strong>.<br />\n                  This helps keep your account secure.\n                </span>\n              )}\n            </DialogDescription>\n          </DialogHeader>\n        </div>\n\n        {hasGuessed ? (\n          <div className=\"mt-4 text-center\">\n            <DialogClose>\n              <Button\n                type=\"button\"\n                ref={closeButtonRef}\n                className=\"rounded-2xl border-0 bg-zinc-800 px-6 py-2 font-semibold text-white shadow-xl transition-all duration-200 hover:bg-zinc-700\"\n              >\n                Continue\n              </Button>\n            </DialogClose>\n          </div>\n        ) : (\n          <div className=\"mt-2 space-y-4\">\n            <div className=\"flex justify-center\">\n              <OTPInput\n                id=\"confirmation-code\"\n                ref={inputRef}\n                value={value}\n                onChange={setValue}\n                containerClassName=\"flex items-center gap-3 has-disabled:opacity-50\"\n                maxLength={5}\n                onFocus={() => setHasGuessed(undefined)}\n                render={({ slots }) => (\n                  <div className=\"flex gap-2\">\n                    {slots.map((slot, idx) => (\n                      <Slot key={idx} {...slot} />\n                    ))}\n                  </div>\n                )}\n                onComplete={onSubmit}\n              />\n            </div>\n            {hasGuessed === false && (\n              <p\n                className=\"text-center text-xs text-red-500 dark:text-red-400\"\n                role=\"alert\"\n                aria-live=\"polite\"\n              >\n                Invalid code. Please try again.\n              </p>\n            )}\n            <p className=\"text-center text-xs text-zinc-500 dark:text-zinc-400\">\n              Didn&apos;t get a code?{' '}\n              <a\n                className=\"text-zinc-700 hover:underline dark:text-zinc-200\"\n                href=\"#\"\n              >\n                Resend\n              </a>\n            </p>\n          </div>\n        )}\n      </DialogContent>\n    </Dialog>\n  );\n};\n\nfunction Slot(props: SlotProps) {\n  return (\n    <div\n      className={cn(\n        'border-input flex size-9 items-center justify-center rounded-2xl border bg-zinc-50 font-medium text-zinc-900 shadow-md transition-[color,box-shadow] dark:bg-zinc-800 dark:text-zinc-100',\n        {\n          'z-10 border-zinc-500 ring-[3px] ring-zinc-200/50': props.isActive,\n          'border-zinc-300 dark:border-zinc-700': !props.isActive,\n        },\n      )}\n      style={{\n        boxShadow: props.isActive\n          ? '0 4px 16px 0 rgba(24,24,27,0.10)'\n          : undefined,\n      }}\n    >\n      {props.char !== null && <div>{props.char}</div>}\n    </div>\n  );\n}\n\nexport default Dialog12;\n"
    }
  ]
}
