import { a5 as u, P as k, N as y, k as s, ay as R, l as e, o as i, bg as L, aJ as S, aK as M, aL as O, aM as F, aN as x, aO as I, bh as l, J as m, K as p, Q as h, I as v, an as B, aB as P, bi as j, bj as E, Z as D, a2 as U } from "./App-1cb933e1.mjs";
import w from "react";
import "react-dom";
import "@feedloop/formula-editor";
import "@feedloop/expression-parser";
function _({
  provider: $,
  callback: b
}) {
  const a = u(), r = u(), c = w.useRef(null), o = k({
    defaultValues: {
      remember: !0,
      username: "",
      password: ""
    }
  }), f = y.useClient(), [g, n] = w.useState({
    status: "idle"
  }), C = () => {
    r.onToggle(), c.current && c.current.focus({
      preventScroll: !0
    });
  };
  return /* @__PURE__ */ s(R, {
    children: [/* @__PURE__ */ e(i, {
      onClick: a.onOpen,
      leftIcon: /* @__PURE__ */ e(L, {}),
      width: "full",
      children: "Username & Password"
    }), /* @__PURE__ */ s(S, {
      isOpen: a.isOpen,
      onClose: a.onClose,
      children: [/* @__PURE__ */ e(M, {}), /* @__PURE__ */ s(O, {
        children: [/* @__PURE__ */ e(F, {
          children: "Login"
        }), /* @__PURE__ */ e(x, {}), /* @__PURE__ */ e(I, {
          as: "form",
          pb: 6,
          onSubmit: o.handleSubmit(async (t) => {
            n({
              status: "loading"
            });
            try {
              const d = await f.authenticate(t.username, t.password);
              n({
                status: "idle"
              }), a.onClose(), window.location.href = `${b}#token=${d}&remember=${t.remember}`;
            } catch {
              n({
                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(B, {
                    children: /* @__PURE__ */ e(P, {
                      variant: "link",
                      "aria-label": r.isOpen ? "Mask password" : "Reveal password",
                      icon: r.isOpen ? /* @__PURE__ */ e(j, {}) : /* @__PURE__ */ e(E, {}),
                      onClick: C
                    })
                  }), /* @__PURE__ */ e(h, {
                    id: "password",
                    type: r.isOpen ? "text" : "password",
                    autoComplete: "current-password",
                    required: !0,
                    placeholder: "********",
                    ...o.register("password")
                  })]
                })]
              })]
            }), /* @__PURE__ */ s(D, {
              justify: "space-between",
              children: [/* @__PURE__ */ e(U, {
                ...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 {
  _ as default
};
