"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
"use client";













var _chunkXSD2S42Ijs = require('./chunk-XSD2S42I.js');


var _chunkYINJ5YZ5js = require('./chunk-YINJ5YZ5.js');

// src/components/DeviceHandoffGate.tsx
var _react = require('react');
var _qrcodereact = require('qrcode.react');










var _lucidereact = require('lucide-react');
var _jsxruntime = require('react/jsx-runtime');
function ThemeToggle() {
  const [, rerender] = _react.useReducer.call(void 0, (x) => x + 1, 0);
  const dark = typeof document !== "undefined" && document.documentElement.classList.contains("dark");
  const toggle = () => {
    const next = !document.documentElement.classList.contains("dark");
    document.documentElement.classList.toggle("dark", next);
    try {
      localStorage.setItem("theme", next ? "dark" : "light");
    } catch (e) {
    }
    rerender();
  };
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
    "button",
    {
      type: "button",
      onClick: toggle,
      className: "flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",
      "aria-label": dark ? "Switch to light mode" : "Switch to dark mode",
      children: dark ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Sun, { className: "h-4 w-4" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Moon, { className: "h-4 w-4" })
    }
  );
}
function HeaderBrand() {
  const { logo, companyName } = _chunkXSD2S42Ijs.useBranding.call(void 0, );
  const [failed, setFailed] = _react.useState.call(void 0, false);
  const showLogo = Boolean(logo) && !failed;
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex min-w-0 items-center gap-2", children: [
    showLogo && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-full bg-white shadow-sm ring-1 ring-black/5", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: logo, alt: companyName ? `${companyName} logo` : "Company logo", className: "h-full w-full object-cover", onError: () => setFailed(true) }) }),
    showLogo && companyName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "truncate text-sm font-semibold text-foreground", children: companyName })
  ] });
}
function DeviceHandoffGate({
  snapshot,
  onContinueHere,
  onClose,
  showThemeToggle,
  disableClose
}) {
  var _a;
  const config = _chunkXSD2S42Ijs.useKYCConfig.call(void 0, );
  const handoff = _chunkXSD2S42Ijs.useDeviceHandoff.call(void 0, config.api, snapshot, true);
  const [copied, setCopied] = _react.useState.call(void 0, false);
  const [noCamera, setNoCamera] = _react.useState.call(void 0, false);
  const submittedRef = _react.useRef.call(void 0, false);
  const themeVars = _chunkXSD2S42Ijs.buildThemeVars.call(void 0, config.appearance);
  _react.useEffect.call(void 0, () => {
    var _a2;
    const theme = (_a2 = config.appearance) == null ? void 0 : _a2.theme;
    if (theme) document.documentElement.classList.toggle("dark", theme === "dark");
  }, [(_a = config.appearance) == null ? void 0 : _a.theme]);
  _react.useEffect.call(void 0, () => {
    let active = true;
    _chunkXSD2S42Ijs.hasNoWebcam.call(void 0, ).then((v) => {
      if (active) setNoCamera(v);
    });
    return () => {
      active = false;
    };
  }, []);
  _react.useEffect.call(void 0, () => {
    if (handoff.phase === "error") onContinueHere();
  }, [handoff.phase, onContinueHere]);
  _react.useEffect.call(void 0, () => {
    var _a2, _b;
    if (handoff.phase === "submitted" && handoff.verificationId && !submittedRef.current) {
      submittedRef.current = true;
      (_b = config.onSubmit) == null ? void 0 : _b.call(config, {
        verificationId: handoff.verificationId,
        status: "pending",
        metadata: _chunkYINJ5YZ5js.__spreadValues.call(void 0, {}, (_a2 = config.metadata) != null ? _a2 : {}),
        submittedAt: (/* @__PURE__ */ new Date()).toISOString()
      });
    }
  }, [handoff.phase, handoff.verificationId, config]);
  const copyLink = () => {
    var _a2;
    if (!handoff.url) return;
    (_a2 = navigator.clipboard) == null ? void 0 : _a2.writeText(handoff.url).then(
      () => {
        setCopied(true);
        setTimeout(() => setCopied(false), 2e3);
      },
      () => {
      }
    );
  };
  const isTerminal = handoff.phase === "submitted";
  const dismissBlocked = disableClose === true && !isTerminal;
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.Dialog, { open: true, onOpenChange: (o) => {
    if (!o && !dismissBlocked) onClose();
  }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
    _chunkXSD2S42Ijs.DialogContent,
    {
      className: "kyc-root",
      style: themeVars,
      onPointerDownOutside: (e) => {
        if (dismissBlocked) e.preventDefault();
      },
      onEscapeKeyDown: (e) => {
        if (dismissBlocked) e.preventDefault();
      },
      children: [
        /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXSD2S42Ijs.VisuallyHidden, { children: [
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.DialogTitle, { children: "Continue your verification" }),
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.DialogDescription, { children: "Continue on your phone or this device" })
        ] }),
        /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex h-full flex-col overflow-hidden rounded-[inherit]", children: [
          /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative flex min-h-12 items-center justify-between gap-2 px-3 pt-[calc(env(safe-area-inset-top)+1.25rem)]", children: [
            /* @__PURE__ */ _jsxruntime.jsx.call(void 0, HeaderBrand, {}),
            /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex shrink-0 items-center gap-1", children: [
              showThemeToggle !== false && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThemeToggle, {}),
              !dismissBlocked && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                "button",
                {
                  type: "button",
                  onClick: onClose,
                  className: "flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground transition-colors",
                  "aria-label": "Close",
                  children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.X, { className: "h-4 w-4" })
                }
              )
            ] })
          ] }),
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-1 overflow-y-auto p-6 animate-slide-up", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
            GateBody,
            {
              phase: handoff.phase,
              url: handoff.url,
              code: handoff.code,
              noCamera,
              copied,
              onCopyLink: copyLink,
              onContinueHere,
              onRegenerate: handoff.regenerate,
              onDone: onClose
            }
          ) })
        ] })
      ]
    }
  ) });
}
function GateBody({
  phase,
  url,
  code,
  noCamera,
  copied,
  onCopyLink,
  onContinueHere,
  onRegenerate,
  onDone
}) {
  if (phase === "submitted") {
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center gap-6 py-8 animate-fade-in", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-20 w-20 items-center justify-center rounded-full bg-[var(--kyc-success)]/10", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "h-10 w-10 text-[var(--kyc-success)]", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "3", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M4 12l5 5L20 6", strokeDasharray: "100", strokeDashoffset: "100", className: "animate-checkmark" }) }) }),
      /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "text-center space-y-1", children: [
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-xl font-semibold font-heading", children: "Completed on your phone" }),
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm text-muted-foreground", children: "Your verification has been submitted for review. You can close this window." })
      ] }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.Button, { className: "w-full", onClick: onDone, children: "Done" })
    ] });
  }
  if (phase === "expired") {
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center gap-6 py-8 animate-fade-in", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-muted", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.RefreshCcw, { className: "h-7 w-7 text-muted-foreground" }) }),
      /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "text-center space-y-1", children: [
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-lg font-semibold font-heading", children: "Link expired" }),
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm text-muted-foreground", children: "This verification link timed out. Generate a new one, or continue on this device." })
      ] }),
      /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col gap-2", children: [
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.Button, { className: "w-full", onClick: onRegenerate, children: "Generate a new link" }),
        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkXSD2S42Ijs.Button, { variant: "ghost", className: "w-full", onClick: onContinueHere, children: "Continue on this device" })
      ] })
    ] });
  }
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center gap-6 py-2 animate-fade-in", children: [
    /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center gap-2 text-center", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-12 w-12 items-center justify-center rounded-full bg-primary/10", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Smartphone, { className: "h-6 w-6 text-primary" }) }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-xl font-semibold font-heading", children: "Continue on your phone" }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "max-w-sm text-sm text-muted-foreground", children: noCamera ? "This device has no camera. Scan the QR code with your phone to finish your verification there." : "Scan the QR code with your phone to continue your verification there \u2014 handy for capturing your ID and selfie." })
    ] }),
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-[232px] w-[232px] items-center justify-center rounded-2xl border border-border bg-white p-4", children: url ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _qrcodereact.QRCodeSVG, { value: url, size: 200, level: "M", marginSize: 0 }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Loader2, { className: "h-8 w-8 animate-spin text-muted-foreground" }) }),
    code && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-col items-center gap-2", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Or enter this code" }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "font-heading text-lg font-semibold tracking-[0.2em] text-foreground", children: code }),
      /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkXSD2S42Ijs.Button, { variant: "outline", className: "mt-1 gap-2", onClick: onCopyLink, children: [
        copied ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Copy, { className: "h-4 w-4" }),
        copied ? "Link copied" : "Copy link"
      ] })
    ] }),
    phase === "opened" && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { className: "flex items-center gap-2 text-sm text-primary", children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Loader2, { className: "h-4 w-4 animate-spin" }),
      "Continuing on your phone\u2026"
    ] }),
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-full border-t border-border pt-4", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
      _chunkXSD2S42Ijs.Button,
      {
        variant: "ghost",
        className: _chunkXSD2S42Ijs.cn.call(void 0, "w-full gap-2", phase === "opened" && "pointer-events-none opacity-50"),
        onClick: onContinueHere,
        disabled: phase === "opened",
        children: [
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Monitor, { className: "h-4 w-4" }),
          "Continue on this device"
        ]
      }
    ) })
  ] });
}


exports.default = DeviceHandoffGate;
//# sourceMappingURL=DeviceHandoffGate-X3YRXYR5.js.map