import { w as p, D as w, u as S, j as r, C as f, a as e, L as x, B as d, o as b, V as c, O as a, P as s, q as k, Q as C, R as l, T as L, U as g, W as m, X as A, Y as y } from "./App-f49e4ede.mjs";
import * as h from "react";
import u from "react";
import { a as I } from "./chakra-ui-skeleton.esm-18eff055.mjs";
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(t) {
  return h.createElement(
    "svg",
    Object.assign({ xmlns: "http://www.w3.org/2000/svg", strokeWidth: 0, viewBox: "0 0 24 24", fill: "currentColor", stroke: "currentColor", width: "1em", height: "1em" }, t),
    h.createElement("path", { d: "M4 8a1 1 0 012 0v8a1 1 0 01-2 0V8zm7.414 5L14 15.586A.999.999 0 1112.586 17L9 13.414a2 2 0 010-2.828L12.586 7A.999.999 0 1114 8.414L11.414 11H20a1 1 0 010 2h-8.586z" })
  );
}
const E = () => {
  const t = g({
    defaultValues: {
      externalID: "",
      password: ""
    }
  }), o = p();
  return /* @__PURE__ */ r(c, {
    as: "form",
    onSubmit: t.handleSubmit(async (n) => {
      const i = await o.authorize({
        identifier: n.externalID,
        password: n.password
      });
      l.set("USER-TOKEN", i.data.token, {
        expires: 7
      }), window.location.href = window.location.origin;
    }),
    alignItems: "normal",
    spacing: 2,
    children: [/* @__PURE__ */ r(a, {
      children: [/* @__PURE__ */ e(s, {
        children: "External ID"
      }), /* @__PURE__ */ e(m, {
        ...t.register("externalID")
      })]
    }), /* @__PURE__ */ r(a, {
      children: [/* @__PURE__ */ e(s, {
        children: "Password"
      }), /* @__PURE__ */ e(m, {
        type: "password",
        ...t.register("password")
      })]
    }), /* @__PURE__ */ e(a, {
      children: /* @__PURE__ */ e(d, {
        type: "submit",
        width: "100%",
        marginTop: "10px",
        colorScheme: "blue",
        children: "Login"
      })
    })]
  });
}, T = () => {
  const t = g({
    defaultValues: {
      adminSecret: ""
    }
  }), o = u.useCallback(async (n) => {
    await new A(new y({
      apiKey: n.adminSecret
    })).getSchema(), l.set("ADMIN-SECRET", n.adminSecret, {
      expires: 7
    }), window.location.href = window.location.origin;
  }, []);
  return /* @__PURE__ */ r(c, {
    as: "form",
    onSubmit: t.handleSubmit(o),
    alignItems: "normal",
    spacing: 2,
    children: [/* @__PURE__ */ r(a, {
      children: [/* @__PURE__ */ e(s, {
        children: "Admin Secret"
      }), /* @__PURE__ */ e(m, {
        type: "password",
        ...t.register("adminSecret")
      })]
    }), /* @__PURE__ */ e(a, {
      children: /* @__PURE__ */ e(d, {
        type: "submit",
        width: "100%",
        marginTop: "10px",
        colorScheme: "blue",
        children: "Login"
      })
    })]
  });
}, D = () => {
  const [t, o] = u.useState({
    mode: "user"
  });
  return /* @__PURE__ */ r(c, {
    alignItems: "normal",
    spacing: 5,
    children: [/* @__PURE__ */ r(a, {
      children: [/* @__PURE__ */ e(s, {
        children: "Login as"
      }), /* @__PURE__ */ r(k, {
        value: t.mode,
        onChange: (n) => {
          o((i) => ({
            ...i,
            mode: n.currentTarget.value
          }));
        },
        children: [/* @__PURE__ */ e("option", {
          value: "user",
          children: "User"
        }), /* @__PURE__ */ e("option", {
          value: "admin",
          children: "Admin"
        })]
      })]
    }), t.mode === "user" ? /* @__PURE__ */ e(E, {}) : /* @__PURE__ */ e(T, {})]
  });
}, R = () => {
  var n, i;
  const t = C.useCurrentUser(), o = u.useCallback(() => {
    l.remove("ADMIN-SECRET"), l.remove("USER-TOKEN"), window.location.reload();
  }, []);
  return /* @__PURE__ */ r(c, {
    alignItems: "normal",
    spacing: 4,
    children: [/* @__PURE__ */ r(L, {
      textAlign: "center",
      fontSize: "15px",
      children: ["Hello", " ", /* @__PURE__ */ e("span", {
        style: {
          fontWeight: "bold"
        },
        children: ((n = t.user) == null ? void 0 : n.external_id) || "..."
      }), /* @__PURE__ */ e("br", {}), "you are logged in as", " ", /* @__PURE__ */ e("span", {
        style: {
          fontWeight: "bold"
        },
        children: ((i = t.user) == null ? void 0 : i.external_id) || "..."
      })]
    }), /* @__PURE__ */ e(d, {
      width: "100%",
      colorScheme: "red",
      onClick: o,
      children: "Logout"
    })]
  });
};
function F() {
  const t = p(), o = w([t, "/me"], async () => (await t.v1UserGet()).data);
  return S(), /* @__PURE__ */ r(f, {
    position: "relative",
    inset: "0",
    height: "full",
    width: "100vw",
    children: [/* @__PURE__ */ e(x, {
      to: "/",
      children: /* @__PURE__ */ e(d, {
        colorScheme: "blackAlpha",
        leftIcon: /* @__PURE__ */ e(v, {
          fontSize: "20px"
        }),
        position: "absolute",
        marginTop: "5px",
        marginLeft: "5px",
        top: 0,
        left: 0,
        children: "Back to table"
      })
    }), /* @__PURE__ */ r(b, {
      borderRadius: "6px",
      borderColor: "gray.200",
      borderWidth: "1px",
      borderStyle: "solid",
      padding: "20px",
      width: "280px",
      children: [o.data && /* @__PURE__ */ e(R, {}), o.error && /* @__PURE__ */ e(D, {}), o.isValidating && /* @__PURE__ */ e(I, {})]
    })]
  });
}
export {
  F as default
};
