"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./App-57333a77.js"),s=require("react"),a=require("./chakra-ui-skeleton.esm-c6699b28.js");require("@emotion/react");require("react-dom");require("@emotion/styled");require("@feedloop/formula-editor");require("@feedloop/expression-parser");require("crypto-js");require("react-mentions");function l(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const i=l(s);function c(t){return i.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),i.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 d=()=>{const t=e.useForm({defaultValues:{externalID:"",password:""}}),n=e.useSDKContext();return e.jsxs(e.VStack,{as:"form",onSubmit:t.handleSubmit(async r=>{const o=await n.authorize({identifier:r.externalID,password:r.password});e.api.set("USER-TOKEN",o.data.token,{expires:7}),window.location.href=window.location.origin}),alignItems:"normal",spacing:2,children:[e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{children:"External ID"}),e.jsx(e.Input,{...t.register("externalID")})]}),e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{children:"Password"}),e.jsx(e.Input,{type:"password",...t.register("password")})]}),e.jsx(e.FormControl,{children:e.jsx(e.Button,{type:"submit",width:"100%",marginTop:"10px",colorScheme:"blue",children:"Login"})})]})},u=()=>{const t=e.useForm({defaultValues:{adminSecret:""}}),n=s.useCallback(async r=>{await new e.DefaultApi(new e.Configuration({apiKey:r.adminSecret})).getSchema(),e.api.set("ADMIN-SECRET",r.adminSecret,{expires:7}),window.location.href=window.location.origin},[]);return e.jsxs(e.VStack,{as:"form",onSubmit:t.handleSubmit(n),alignItems:"normal",spacing:2,children:[e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{children:"Admin Secret"}),e.jsx(e.Input,{type:"password",...t.register("adminSecret")})]}),e.jsx(e.FormControl,{children:e.jsx(e.Button,{type:"submit",width:"100%",marginTop:"10px",colorScheme:"blue",children:"Login"})})]})},m=()=>{const[t,n]=s.useState({mode:"user"});return e.jsxs(e.VStack,{alignItems:"normal",spacing:5,children:[e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{children:"Login as"}),e.jsxs(e.Select,{value:t.mode,onChange:r=>{n(o=>({...o,mode:r.currentTarget.value}))},children:[e.jsx("option",{value:"user",children:"User"}),e.jsx("option",{value:"admin",children:"Admin"})]})]}),t.mode==="user"?e.jsx(d,{}):e.jsx(u,{})]})},x=()=>{var r,o;const t=e.qoreContext.useCurrentUser(),n=s.useCallback(()=>{e.api.remove("ADMIN-SECRET"),e.api.remove("USER-TOKEN"),window.location.reload()},[]);return e.jsxs(e.VStack,{alignItems:"normal",spacing:4,children:[e.jsxs(e.Text,{textAlign:"center",fontSize:"15px",children:["Hello"," ",e.jsx("span",{style:{fontWeight:"bold"},children:((r=t.user)==null?void 0:r.external_id)||"..."}),e.jsx("br",{}),"you are logged in as"," ",e.jsx("span",{style:{fontWeight:"bold"},children:((o=t.user)==null?void 0:o.external_id)||"..."})]}),e.jsx(e.Button,{width:"100%",colorScheme:"red",onClick:n,children:"Logout"})]})};function h(){const t=e.useSDKContext(),n=e.useSWR([t,"/me"],async()=>(await t.v1UserGet()).data);return e.useHistory(),e.jsxs(e.Center,{position:"relative",inset:"0",height:"full",width:"100vw",children:[e.jsx(e.Link,{to:"/",children:e.jsx(e.Button,{colorScheme:"blackAlpha",leftIcon:e.jsx(c,{fontSize:"20px"}),position:"absolute",marginTop:"5px",marginLeft:"5px",top:0,left:0,children:"Back to table"})}),e.jsxs(e.Box,{borderRadius:"6px",borderColor:"gray.200",borderWidth:"1px",borderStyle:"solid",padding:"20px",width:"280px",children:[n.data&&e.jsx(x,{}),n.error&&e.jsx(m,{}),n.isValidating&&e.jsx(a.Skeleton,{})]})]})}exports.default=h;
