{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-two-factor-auth",
  "title": "TwoFactorAuth",
  "description": "Desafio de autenticação em duas etapas (2FA) com suporte a código OTP de 6 dígitos e expiração.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/input-otp",
    "@lema-ds/button",
    "@lema-ds/checkbox",
    "@lema-ds/label",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-two-factor-auth.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport {\n  ShieldCheckIcon,\n  Loader2Icon,\n  RefreshCwIcon,\n  SmartphoneIcon,\n} from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  InputOTP,\n  InputOTPGroup,\n  InputOTPSlot,\n} from \"@/components/ui/input-otp\"\nimport { Button } from \"@/components/ui/button\"\nimport { Checkbox } from \"@/components/ui/checkbox\"\nimport { Label } from \"@/components/ui/label\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\n\n// ── Types ──\n\nexport interface TwoFactorAuthProps\n  extends\n    Omit<React.HTMLAttributes<HTMLDivElement>, \"onSubmit\">,\n    VariantProps<typeof twoFactorAuthVariants> {\n  onVerify?: (\n    code: string,\n    trustDevice: boolean\n  ) => Promise<boolean | void> | void\n  onResend?: () => Promise<void> | void\n  resendCooldown?: number\n  destination?: string\n  method?: \"authenticator\" | \"email\" | \"sms\"\n  allowAlternative?: boolean\n  onAlternativeMethod?: () => void\n  locale?: UILocale\n}\n\n// ── Variants ──\n\nexport const twoFactorAuthVariants = cva(\n  \"flex w-full max-w-md flex-col items-center gap-6 rounded-2xl border border-border/80 bg-card p-6 text-card-foreground shadow-lg sm:p-8\",\n  {\n    variants: {\n      variant: {\n        default: \"\",\n        clean: \"border-0 bg-transparent p-0 shadow-none sm:p-0\",\n      },\n    },\n    defaultVariants: {\n      variant: \"default\",\n    },\n  }\n)\n\n// ── Component ──\n\nexport const TwoFactorAuth = React.forwardRef<\n  HTMLDivElement,\n  TwoFactorAuthProps\n>(\n  (\n    {\n      className,\n      variant = \"default\",\n      onVerify,\n      onResend,\n      resendCooldown = 60,\n      destination = \"u***@ufpb.br\",\n      method = \"email\",\n      allowAlternative = true,\n      onAlternativeMethod,\n      locale: localeProp,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [code, setCode] = React.useState(\"\")\n    const [trustDevice, setTrustDevice] = React.useState(false)\n    const [countdown, setCountdown] = React.useState(resendCooldown)\n    const [loading, setLoading] = React.useState(false)\n    const [resending, setResending] = React.useState(false)\n\n    const t = UI_I18N[locale]?.auth ?? UI_I18N[\"en-US\"].auth\n\n    React.useEffect(() => {\n      if (countdown <= 0) return\n      const timer = setInterval(() => {\n        setCountdown((prev) => prev - 1)\n      }, 1000)\n      return () => clearInterval(timer)\n    }, [countdown])\n\n    const handleVerify = async (e: React.FormEvent) => {\n      e.preventDefault()\n      if (code.length < 6 || loading || !onVerify) return\n\n      try {\n        setLoading(true)\n        await onVerify(code, trustDevice)\n      } finally {\n        setLoading(false)\n      }\n    }\n\n    const handleResend = async () => {\n      if (countdown > 0 || resending || !onResend) return\n\n      try {\n        setResending(true)\n        await onResend()\n        setCountdown(resendCooldown)\n      } finally {\n        setResending(false)\n      }\n    }\n\n    return (\n      <div\n        ref={ref}\n        className={cn(twoFactorAuthVariants({ variant }), className)}\n        {...props}\n      >\n        {/* Header with Icon */}\n        <div className=\"flex flex-col items-center gap-2 text-center\">\n          <div className=\"mb-1 flex size-12 items-center justify-center rounded-full bg-primary/10 text-primary\">\n            {method === \"authenticator\" ? (\n              <SmartphoneIcon className=\"size-6\" aria-hidden=\"true\" />\n            ) : (\n              <ShieldCheckIcon className=\"size-6\" aria-hidden=\"true\" />\n            )}\n          </div>\n          <h2 className=\"text-xl font-bold tracking-tight text-foreground\">\n            {t.twoFactorTitle}\n          </h2>\n          <p className=\"max-w-xs text-xs text-muted-foreground\">\n            {t.twoFactorDescription}\n            {destination && (\n              <span className=\"mt-1 block font-semibold text-foreground\">\n                {destination}\n              </span>\n            )}\n          </p>\n        </div>\n\n        {/* Verification Form */}\n        <form\n          onSubmit={handleVerify}\n          className=\"flex w-full flex-col items-center gap-5\"\n        >\n          <div className=\"flex flex-col items-center gap-2\">\n            <Label htmlFor=\"two-factor-otp-input\" className=\"sr-only\">\n              {t.twoFactorTitle}\n            </Label>\n            <InputOTP\n              id=\"two-factor-otp-input\"\n              aria-label={t.twoFactorTitle}\n              maxLength={6}\n              value={code}\n              onChange={(value) => setCode(value)}\n              autoFocus\n            >\n              <InputOTPGroup>\n                <InputOTPSlot index={0} />\n                <InputOTPSlot index={1} />\n                <InputOTPSlot index={2} />\n                <InputOTPSlot index={3} />\n                <InputOTPSlot index={4} />\n                <InputOTPSlot index={5} />\n              </InputOTPGroup>\n            </InputOTP>\n          </div>\n\n          <div className=\"flex items-center gap-2 text-xs\">\n            <Checkbox\n              id=\"trust-device\"\n              checked={trustDevice}\n              onCheckedChange={(checked) => setTrustDevice(!!checked)}\n            />\n            <Label\n              htmlFor=\"trust-device\"\n              className=\"cursor-pointer text-xs font-normal text-muted-foreground\"\n            >\n              {t.rememberMe} (30 days)\n            </Label>\n          </div>\n\n          <Button\n            type=\"submit\"\n            disabled={code.length < 6 || loading}\n            className=\"w-full gap-2\"\n          >\n            {loading ? (\n              <Loader2Icon className=\"size-4 animate-spin\" aria-hidden=\"true\" />\n            ) : (\n              t.verify\n            )}\n          </Button>\n        </form>\n\n        {/* Resend & Alternative options */}\n        <div className=\"flex w-full flex-col items-center gap-2 border-t border-border/50 pt-1 text-center text-xs text-muted-foreground\">\n          <div className=\"mt-2 flex items-center gap-1.5\">\n            <span>{t.dontHaveAccount}</span>\n            {countdown > 0 ? (\n              <span className=\"font-semibold text-foreground\">\n                {t.resendIn} {countdown}s\n              </span>\n            ) : (\n              <Button\n                type=\"button\"\n                variant=\"link\"\n                size=\"sm\"\n                onClick={handleResend}\n                disabled={resending}\n                className=\"h-auto p-0 text-xs font-semibold text-primary\"\n              >\n                {resending && (\n                  <RefreshCwIcon\n                    className=\"mr-1 size-3 animate-spin\"\n                    aria-hidden=\"true\"\n                  />\n                )}\n                {t.resendCode}\n              </Button>\n            )}\n          </div>\n\n          {allowAlternative && onAlternativeMethod && (\n            <Button\n              type=\"button\"\n              variant=\"ghost\"\n              size=\"sm\"\n              onClick={onAlternativeMethod}\n              className=\"h-7 text-xs text-muted-foreground hover:text-foreground\"\n            >\n              {t.useAlternativeMethod}\n            </Button>\n          )}\n        </div>\n      </div>\n    )\n  }\n)\nTwoFactorAuth.displayName = \"TwoFactorAuth\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
