import { a8 as u, U as k, Q as y, j as s, ax as R, a as e, B as i, bh as L, aI as S, aJ as M, aK as O, aL as x, aM as F, aN as I, bi as l, O as m, P as p, W as h, I as j, am as v, aA as B, bj as P, bk as E, a1 as U, a5 as D } from "./App-7cdde89e.mjs";
import w from "react";
import "@emotion/react";
import "react-dom";
import "@emotion/styled";
import "@feedloop/formula-editor";
import "@feedloop/expression-parser";
function K({
  provider: $,
  callback: b
}) {
  const a = u(), r = u(), c = w.useRef(null), o = k({
    defaultValues: {
      remember: !0,
      username: "",
      password: ""
    }
  }), f = y.useClient(), [g, t] = 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(x, {
          children: "Login"
        }), /* @__PURE__ */ e(F, {}), /* @__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"
              }), a.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(j, {
                  children: [/* @__PURE__ */ e(v, {
                    children: /* @__PURE__ */ e(B, {
                      variant: "link",
                      "aria-label": r.isOpen ? "Mask password" : "Reveal password",
                      icon: r.isOpen ? /* @__PURE__ */ e(P, {}) : /* @__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(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 {
  K as default
};
