import { a9 as u, U as k, Q as y, j as s, ao as R, a as e, B as i, bm as L, aL as O, aM as S, aN as M, aO as F, aP as x, aQ as I, bn as l, O as m, P as p, W as h, I as P, am as v, aE as B, bo as E, bp as j, a1 as U, a6 as D } from "./App-f49e4ede.mjs";
import w from "react";
import "@emotion/react";
import "react-dom";
import "@emotion/styled";
import "@feedloop/formula-editor";
import "@feedloop/expression-parser";
import "crypto-js";
import "react-mentions";
function V({
  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(v, {
                    children: /* @__PURE__ */ e(B, {
                      variant: "link",
                      "aria-label": a.isOpen ? "Mask password" : "Reveal password",
                      icon: a.isOpen ? /* @__PURE__ */ e(E, {}) : /* @__PURE__ */ e(j, {}),
                      onClick: C
                    })
                  }), /* @__PURE__ */ e(h, {
                    id: "password",
                    type: a.isOpen ? "text" : "password",
                    autoComplete: "current-password",
                    required: !0,
                    placeholder: "********",
                    ...o.register("password")
                  })]
                })]
              })]
            }), /* @__PURE__ */ s(U, {
              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 {
  V as default
};
