"use client";
import * as React6 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 = React6.forwardRef(({ className, variant, ...props }, ref) => /* @__PURE__ */ jsx(
  "div",
  {
    ref,
    role: "alert",
    className: cn(alertVariants({ variant }), className),
    ...props
  }
));
Alert.displayName = "Alert";
var AlertTitle = React6.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 = React6.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: cn("text-sm [&_p]:leading-relaxed", className), ...props })
);
AlertDescription.displayName = "AlertDescription";
var emptyVariants = cva(
  [
    "flex flex-col items-center justify-center text-center",
    "rounded-md border border-dashed border-border bg-muted/30"
  ].join(" "),
  {
    variants: {
      size: {
        sm: "gap-[var(--space-2,0.5rem)] px-[var(--space-4,1rem)] py-[var(--space-6,1.5rem)] text-sm",
        default: "gap-[var(--space-3,0.75rem)] px-[var(--space-6,1.5rem)] py-[var(--space-8,2rem)]",
        lg: "gap-[var(--space-4,1rem)] px-[var(--space-8,2rem)] py-[var(--space-12,3rem)]"
      }
    },
    defaultVariants: { size: "default" }
  }
);
var emptyIconWrapperVariants = cva(
  "flex shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground [&_svg]:size-5",
  {
    variants: {
      size: {
        sm: "h-9 w-9",
        default: "h-12 w-12 [&_svg]:size-6",
        lg: "h-16 w-16 [&_svg]:size-7"
      }
    },
    defaultVariants: { size: "default" }
  }
);
var emptyTitleVariants = cva("font-semibold text-foreground", {
  variants: {
    size: {
      sm: "text-sm",
      default: "text-base",
      lg: "text-lg"
    }
  },
  defaultVariants: { size: "default" }
});
var emptyDescriptionVariants = cva("max-w-md text-muted-foreground", {
  variants: {
    size: {
      sm: "text-xs",
      default: "text-sm",
      lg: "text-base"
    }
  },
  defaultVariants: { size: "default" }
});
function Empty({
  className,
  size,
  icon,
  title,
  description,
  action,
  titleAs = "h3",
  ref,
  ...props
}) {
  const titleId = React6.useId();
  const TitleComp = titleAs;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref,
      role: "region",
      "aria-labelledby": titleId,
      className: cn(emptyVariants({ size }), className),
      ...props,
      children: [
        icon ? /* @__PURE__ */ jsx("div", { className: emptyIconWrapperVariants({ size }), "aria-hidden": "true", children: icon }) : null,
        /* @__PURE__ */ jsx(TitleComp, { id: titleId, className: emptyTitleVariants({ size }), children: title }),
        description ? /* @__PURE__ */ jsx("div", { className: emptyDescriptionVariants({ size }), children: description }) : null,
        action ? /* @__PURE__ */ jsx("div", { className: "mt-[var(--space-2,0.5rem)]", children: action }) : null
      ]
    }
  );
}
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 = React6.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 = React6.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 = React6.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx(LabelPrimitive.Root, { ref, className: cn(labelVariants(), className), ...props })
);
Label.displayName = "Label";
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
var MailIcon = () => /* @__PURE__ */ jsxs(
  "svg",
  {
    xmlns: "http://www.w3.org/2000/svg",
    viewBox: "0 0 24 24",
    fill: "none",
    stroke: "currentColor",
    strokeWidth: 2,
    strokeLinecap: "round",
    strokeLinejoin: "round",
    "aria-hidden": "true",
    children: [
      /* @__PURE__ */ jsx("rect", { width: 20, height: 16, x: 2, y: 4, rx: 2 }),
      /* @__PURE__ */ jsx("path", { d: "m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" })
    ]
  }
);
function AuthForgotPassword({
  adapter,
  signInHref = "/sign-in",
  className,
  onSuccess
}) {
  const [email, setEmail] = React6.useState("");
  const [submitting, setSubmitting] = React6.useState(false);
  const [error, setError] = React6.useState(null);
  const [submittedEmail, setSubmittedEmail] = React6.useState(null);
  async function handleSubmit(e) {
    e.preventDefault();
    if (!EMAIL_REGEX.test(email)) {
      setError({ code: "invalid_email", message: "Enter a valid email address." });
      return;
    }
    if (!adapter.requestPasswordReset) {
      console.warn(
        "[AuthForgotPassword] adapter.requestPasswordReset 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.requestPasswordReset({ email });
      if (!result.ok) {
        setError(result.error ?? { code: "unknown", message: "Couldn't send reset link." });
        return;
      }
      setSubmittedEmail(email);
      onSuccess?.();
    } finally {
      setSubmitting(false);
    }
  }
  if (submittedEmail) {
    return /* @__PURE__ */ jsx(
      "div",
      {
        className: cn(
          "flex min-h-svh items-center justify-center p-6 sm:p-10",
          className
        ),
        children: /* @__PURE__ */ jsx("div", { className: "w-full max-w-sm", children: /* @__PURE__ */ jsx(
          Empty,
          {
            icon: /* @__PURE__ */ jsx(MailIcon, {}),
            title: "Check your inbox",
            description: /* @__PURE__ */ jsxs(Fragment, { children: [
              "We sent a password-reset link to",
              " ",
              /* @__PURE__ */ jsx("strong", { className: "text-foreground", children: submittedEmail }),
              ". The link expires in 60 minutes."
            ] }),
            action: /* @__PURE__ */ jsx(Button, { variant: "outline", asChild: true, children: /* @__PURE__ */ jsx("a", { href: signInHref, children: "Back to sign in" }) })
          }
        ) })
      }
    );
  }
  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: "Reset your password" }),
      /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Enter your email and we\u2019ll send you a link to set a new password." })
    ] }),
    error ? /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
      /* @__PURE__ */ jsx(AlertTitle, { children: "Couldn\u2019t send reset link" }),
      /* @__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-forgot-email", children: "Email" }),
        /* @__PURE__ */ jsx(
          Input,
          {
            id: "auth-forgot-email",
            type: "email",
            autoComplete: "email",
            required: true,
            value: email,
            onChange: (e) => setEmail(e.target.value),
            disabled: submitting
          }
        )
      ] }),
      /* @__PURE__ */ jsx(
        Button,
        {
          type: "submit",
          className: "w-full",
          disabled: submitting,
          loading: submitting,
          children: submitting ? "Sending link" : "Send reset link"
        }
      )
    ] }),
    /* @__PURE__ */ jsxs("p", { className: "text-center text-sm text-muted-foreground", children: [
      "Remembered your password?",
      " ",
      /* @__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: "Sign in"
        }
      )
    ] })
  ] }) });
}

export { AuthForgotPassword };
//# sourceMappingURL=auth-forgot-password.js.map
//# sourceMappingURL=auth-forgot-password.js.map