import { a8 as u, U as k, Q as y, j as s, an as R, a as e, B as i, bj as L, aK as O, aL as S, aM as M, aN as F, aO as x, aP as I, bk as l, O as m, P as p, W as h, I as P, al as j, aD as v, bl as B, bm as D, a1 as E, a5 as U } from "./App-664af23e.mjs";
import w from "react";
import "@emotion/react";
import "react-dom";
import "@emotion/styled";
import "@feedloop/formula-editor";
import "@feedloop/expression-parser";
import "base-64";
import "react-mentions";
function T({
  provider: $,
  callback: b
}) {
  const r = u(), a = u(), c = w.useRef(null), o = k({
    defaultValues: {
      remember: !0,
      username: "",
      password: ""
    }
  }), f = y.useClient(), [g, t] = w.useState({
    status: "idle"
  }), C = () => {
    a.onToggle(), c.current && c.current.focus({
      preventScroll: !0
    });
  };
  return /* @__PURE__ */ s(R, {
    children: [/* @__PURE__ */ e(i, {
      onClick: r.onOpen,
      leftIcon: /* @__PURE__ */ e(L, {}),
      width: "full",
      children: "Username & Password"
    }), /* @__PURE__ */ s(O, {
      isOpen: r.isOpen,
      onClose: r.onClose,
      children: [/* @__PURE__ */ e(S, {}), /* @__PURE__ */ s(M, {
        children: [/* @__PURE__ */ e(F, {
          children: "Login"
        }), /* @__PURE__ */ e(x, {}), /* @__PURE__ */ e(I, {
          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(P, {
                  children: [/* @__PURE__ */ e(j, {
                    children: /* @__PURE__ */ e(v, {
                      variant: "link",
                      "aria-label": a.isOpen ? "Mask password" : "Reveal password",
                      icon: a.isOpen ? /* @__PURE__ */ e(B, {}) : /* @__PURE__ */ e(D, {}),
                      onClick: C
                    })
                  }), /* @__PURE__ */ e(h, {
                    id: "password",
                    type: a.isOpen ? "text" : "password",
                    autoComplete: "current-password",
                    required: !0,
                    placeholder: "********",
                    ...o.register("password")
                  })]
                })]
              })]
            }), /* @__PURE__ */ s(E, {
              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 {
  T as default
};
