import { a6 as u, Q as k, O as R, l as s, aw as y, m as e, p as i, bg as L, aH as S, aI as M, aJ as O, aK as F, aL as I, aM as x, bh as l, K as m, N as p, R as h, I as v, al as j, az as B, bi as E, bj as P, $, a3 as D } from "./App-4f8b3c63.mjs";
import w from "react";
import "@emotion/react";
import "react-dom";
import "@emotion/styled";
import "@feedloop/formula-editor";
import "@feedloop/expression-parser";
function J({
  provider: H,
  callback: b
}) {
  const r = u(), a = u(), c = w.useRef(null), o = k({
    defaultValues: {
      remember: !0,
      username: "",
      password: ""
    }
  }), f = R.useClient(), [g, t] = w.useState({
    status: "idle"
  }), C = () => {
    a.onToggle(), c.current && c.current.focus({
      preventScroll: !0
    });
  };
  return /* @__PURE__ */ s(y, {
    children: [/* @__PURE__ */ e(i, {
      onClick: r.onOpen,
      leftIcon: /* @__PURE__ */ e(L, {}),
      width: "full",
      children: "Username & Password"
    }), /* @__PURE__ */ s(S, {
      isOpen: r.isOpen,
      onClose: r.onClose,
      children: [/* @__PURE__ */ e(M, {}), /* @__PURE__ */ s(O, {
        children: [/* @__PURE__ */ e(F, {
          children: "Login"
        }), /* @__PURE__ */ e(I, {}), /* @__PURE__ */ e(x, {
          as: "form",
          pb: 6,
          onSubmit: o.handleSubmit(async (n) => {
            t({
              status: "loading"
            });
            try {
              const d = await f.authenticate(n.username, n.password);
              t({
                status: "idle"
              }), r.onClose(), window.location.href = `${b}#token=${d}&remember=${n.remember}`;
            } catch {
              t({
                status: "error"
              });
            }
          }),
          children: /* @__PURE__ */ s(l, {
            spacing: "6",
            children: [/* @__PURE__ */ s(l, {
              spacing: "5",
              children: [/* @__PURE__ */ s(m, {
                children: [/* @__PURE__ */ e(p, {
                  htmlFor: "username",
                  children: "Username"
                }), /* @__PURE__ */ e(h, {
                  id: "username",
                  type: "username",
                  placeholder: "Enter username",
                  ...o.register("username")
                })]
              }), /* @__PURE__ */ s(m, {
                children: [/* @__PURE__ */ e(p, {
                  htmlFor: "password",
                  children: "Password"
                }), /* @__PURE__ */ s(v, {
                  children: [/* @__PURE__ */ e(j, {
                    children: /* @__PURE__ */ e(B, {
                      variant: "link",
                      "aria-label": a.isOpen ? "Mask password" : "Reveal password",
                      icon: a.isOpen ? /* @__PURE__ */ e(E, {}) : /* @__PURE__ */ e(P, {}),
                      onClick: C
                    })
                  }), /* @__PURE__ */ e(h, {
                    id: "password",
                    type: a.isOpen ? "text" : "password",
                    autoComplete: "current-password",
                    required: !0,
                    placeholder: "********",
                    ...o.register("password")
                  })]
                })]
              })]
            }), /* @__PURE__ */ s($, {
              justify: "space-between",
              children: [/* @__PURE__ */ e(D, {
                ...o.register("remember"),
                defaultChecked: !0,
                children: "Remember me"
              }), /* @__PURE__ */ e(i, {
                variant: "link",
                colorScheme: "blue",
                size: "sm",
                children: "Forgot password?"
              })]
            }), /* @__PURE__ */ e(l, {
              spacing: "6",
              children: /* @__PURE__ */ e(i, {
                isLoading: g.status === "loading",
                colorScheme: "blue",
                type: "submit",
                children: "Login"
              })
            })]
          })
        })]
      })]
    })]
  });
}
export {
  J as default
};
