"use client";
import * as React5 from 'react';
import { cva } from 'class-variance-authority';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import { Slot } from '@radix-ui/react-slot';
import * as LabelPrimitive from '@radix-ui/react-label';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var alertVariants = cva(
  [
    "relative w-full rounded-lg border px-[var(--space-4,1rem)] py-[var(--space-3,0.75rem)] text-sm",
    "transition-all duration-[var(--duration-normal,200ms)] ease-out",
    "[&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:h-4 [&>svg]:w-4 [&>svg]:text-foreground",
    "[&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px]"
  ].join(" "),
  {
    variants: {
      variant: {
        default: "border-foreground/[0.08] bg-background text-foreground",
        destructive: "border-destructive/50 text-destructive [&>svg]:text-destructive bg-destructive/5"
      }
    },
    defaultVariants: { variant: "default" }
  }
);
var Alert = React5.forwardRef(({ className, variant, ...props }, ref) => /* @__PURE__ */ jsx(
  "div",
  {
    ref,
    role: "alert",
    className: cn(alertVariants({ variant }), className),
    ...props
  }
));
Alert.displayName = "Alert";
var AlertTitle = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
  "h5",
  {
    ref,
    className: cn("mb-[var(--space-1,0.25rem)] font-medium leading-none tracking-tight", className),
    ...props
  }
));
AlertTitle.displayName = "AlertTitle";
var AlertDescription = React5.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: cn("text-sm [&_p]:leading-relaxed", className), ...props })
);
AlertDescription.displayName = "AlertDescription";
var buttonVariants = cva(
  [
    "inline-flex items-center justify-center gap-[var(--gap-sm,0.5rem)] whitespace-nowrap rounded-md text-sm font-medium",
    "transition-all duration-[var(--duration-normal,200ms)] ease-out",
    "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
    "disabled:pointer-events-none disabled:opacity-50",
    "active:scale-[0.98]",
    "[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"
  ].join(" "),
  {
    variants: {
      variant: {
        default: [
          "bg-primary text-primary-foreground",
          "shadow-sm shadow-primary/20",
          "hover:bg-primary/90 hover:shadow-md hover:shadow-primary/25"
        ].join(" "),
        destructive: [
          "bg-destructive text-destructive-foreground",
          "shadow-sm shadow-destructive/20",
          "hover:bg-destructive/90 hover:shadow-md hover:shadow-destructive/25"
        ].join(" "),
        outline: [
          "border border-input bg-background",
          "shadow-sm inset-ring-1 inset-ring-foreground/[0.06]",
          "hover:bg-accent hover:text-accent-foreground hover:shadow-md hover:inset-ring-foreground/12"
        ].join(" "),
        secondary: [
          "bg-secondary text-secondary-foreground",
          "shadow-sm inset-ring-1 inset-ring-foreground/[0.08]",
          "hover:bg-secondary/80 hover:shadow-md hover:inset-ring-foreground/15"
        ].join(" "),
        ghost: "hover:bg-accent hover:text-accent-foreground",
        link: "text-primary underline-offset-4 hover:underline"
      },
      size: {
        default: "h-[var(--control-height-md,2.5rem)] px-[var(--space-4,1rem)] py-[var(--space-2,0.5rem)]",
        sm: "h-[var(--control-height-sm,2.25rem)] rounded-md px-[var(--space-3,0.75rem)]",
        lg: "h-[var(--control-height-lg,2.75rem)] rounded-md px-[var(--space-8,2rem)] text-base",
        icon: "h-[var(--control-height-md,2.5rem)] w-[var(--control-height-md,2.5rem)]"
      }
    },
    defaultVariants: {
      variant: "default",
      size: "default"
    }
  }
);
var Button = React5.forwardRef(
  ({ className, variant, size, asChild = false, loading = false, children, disabled, ...props }, ref) => {
    const Comp = asChild ? Slot : "button";
    return /* @__PURE__ */ jsx(
      Comp,
      {
        className: cn(buttonVariants({ variant, size, className })),
        ref,
        disabled: disabled || loading,
        "aria-busy": loading || void 0,
        ...props,
        children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsxs(
            "svg",
            {
              className: "animate-spin h-4 w-4",
              xmlns: "http://www.w3.org/2000/svg",
              fill: "none",
              viewBox: "0 0 24 24",
              "aria-hidden": "true",
              children: [
                /* @__PURE__ */ jsx(
                  "circle",
                  {
                    className: "opacity-25",
                    cx: "12",
                    cy: "12",
                    r: "10",
                    stroke: "currentColor",
                    strokeWidth: "4"
                  }
                ),
                /* @__PURE__ */ jsx(
                  "path",
                  {
                    className: "opacity-75",
                    fill: "currentColor",
                    d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
                  }
                )
              ]
            }
          ),
          children
        ] }) : children
      }
    );
  }
);
Button.displayName = "Button";
var Input = React5.forwardRef(
  ({ className, type, ...props }, ref) => {
    return /* @__PURE__ */ jsx(
      "input",
      {
        type,
        className: cn(
          "flex h-[var(--control-height-md,2.5rem)] w-full rounded-md border border-input bg-background px-[var(--space-3,0.75rem)] py-[var(--space-2,0.5rem)] text-sm",
          "transition-all duration-[var(--duration-normal,200ms)] ease-out",
          // inset-ring gives a self-borne edge so the input field is visible on flat
          // surfaces (token border alone is too low-contrast on bg-background=white).
          "shadow-sm inset-ring-1 inset-ring-foreground/[0.06]",
          "file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground",
          "placeholder:text-muted-foreground",
          "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
          "focus-visible:shadow-md focus-visible:border-ring/50",
          "hover:border-ring/30 hover:shadow-md",
          "disabled:cursor-not-allowed disabled:opacity-50",
          className
        ),
        ref,
        ...props
      }
    );
  }
);
Input.displayName = "Input";
var labelVariants = cva(
  "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
);
var Label = React5.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx(LabelPrimitive.Root, { ref, className: cn(labelVariants(), className), ...props })
);
Label.displayName = "Label";
function AuthResetPassword({
  adapter,
  token,
  signInHref = "/sign-in",
  passwordMinLength = 8,
  className,
  onSuccess
}) {
  const [password, setPassword] = React5.useState("");
  const [confirmPassword, setConfirmPassword] = React5.useState("");
  const [submitting, setSubmitting] = React5.useState(false);
  const [error, setError] = React5.useState(null);
  function validate() {
    if (password.length < passwordMinLength) {
      return {
        code: "password_too_short",
        message: `Password must be at least ${passwordMinLength} characters.`
      };
    }
    if (password !== confirmPassword) {
      return { code: "password_mismatch", message: "Passwords don't match." };
    }
    if (token.length === 0) {
      return {
        code: "missing_token",
        message: "This reset link is invalid or expired. Request a new one."
      };
    }
    return null;
  }
  async function handleSubmit(e) {
    e.preventDefault();
    const validation = validate();
    if (validation) {
      setError(validation);
      return;
    }
    if (!adapter.resetPassword) {
      console.warn(
        "[AuthResetPassword] adapter.resetPassword is not implemented \u2014 wire it up before exposing the form."
      );
      setError({
        code: "unimplemented",
        message: "Password reset is currently unavailable. Please try again later."
      });
      return;
    }
    setError(null);
    setSubmitting(true);
    try {
      const result = await adapter.resetPassword({ token, password });
      if (!result.ok) {
        setError(result.error ?? { code: "unknown", message: "Couldn't update password." });
        return;
      }
      onSuccess?.(result.redirect);
    } finally {
      setSubmitting(false);
    }
  }
  return /* @__PURE__ */ jsx("div", { className: cn("flex min-h-svh items-center justify-center p-6 sm:p-10", className), children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-sm space-y-6", children: [
    /* @__PURE__ */ jsxs("header", { className: "space-y-2 text-center", children: [
      /* @__PURE__ */ jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: "Set a new password" }),
      /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Choose a strong password. You\u2019ll be signed in automatically once it\u2019s saved." })
    ] }),
    error ? /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
      /* @__PURE__ */ jsx(AlertTitle, { children: "Couldn\u2019t update password" }),
      /* @__PURE__ */ jsx(AlertDescription, { children: error.message })
    ] }) : null,
    /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", noValidate: true, children: [
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "auth-reset-password", children: "New password" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "auth-reset-password",
            type: "password",
            autoComplete: "new-password",
            required: true,
            minLength: passwordMinLength,
            value: password,
            onChange: (e) => setPassword(e.target.value),
            disabled: submitting,
            "aria-describedby": "auth-reset-password-hint"
          }
        ),
        /* @__PURE__ */ jsxs(
          "p",
          {
            id: "auth-reset-password-hint",
            className: "text-xs text-muted-foreground",
            children: [
              "At least ",
              passwordMinLength,
              " characters."
            ]
          }
        )
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "auth-reset-confirm", children: "Confirm new password" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "auth-reset-confirm",
            type: "password",
            autoComplete: "new-password",
            required: true,
            value: confirmPassword,
            onChange: (e) => setConfirmPassword(e.target.value),
            disabled: submitting
          }
        )
      ] }),
      /* @__PURE__ */ jsx(
        Button,
        {
          type: "submit",
          className: "w-full",
          disabled: submitting,
          loading: submitting,
          children: submitting ? "Saving" : "Save new password"
        }
      )
    ] }),
    /* @__PURE__ */ jsx("p", { className: "text-center text-sm text-muted-foreground", children: /* @__PURE__ */ jsx(
      "a",
      {
        href: signInHref,
        className: "font-medium text-foreground underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 rounded",
        children: "Back to sign in"
      }
    ) })
  ] }) });
}

export { AuthResetPassword };
//# sourceMappingURL=auth-reset-password.js.map
//# sourceMappingURL=auth-reset-password.js.map