"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./App-48fd652c.js"),l=require("react");require("@emotion/react");require("react-dom");require("@emotion/styled");require("@feedloop/formula-editor");require("@feedloop/expression-parser");function p({provider:h,callback:c}){const s=e.useDisclosure(),r=e.useDisclosure(),i=l.useRef(null),t=e.useForm({defaultValues:{remember:!0,username:"",password:""}}),u=e.qoreContext.useClient(),[d,n]=l.useState({status:"idle"}),m=()=>{r.onToggle(),i.current&&i.current.focus({preventScroll:!0})};return e.jsxs(e.Fragment,{children:[e.jsx(e.Button,{onClick:s.onOpen,leftIcon:e.jsx(e.RiLockPasswordLine,{}),width:"full",children:"Username & Password"}),e.jsxs(e.Modal,{isOpen:s.isOpen,onClose:s.onClose,children:[e.jsx(e.ModalOverlay,{}),e.jsxs(e.ModalContent,{children:[e.jsx(e.ModalHeader,{children:"Login"}),e.jsx(e.ModalCloseButton,{}),e.jsx(e.ModalBody,{as:"form",pb:6,onSubmit:t.handleSubmit(async o=>{n({status:"loading"});try{const a=await u.authenticate(o.username,o.password);n({status:"idle"}),s.onClose(),window.location.href=`${c}#token=${a}&remember=${o.remember}`}catch{n({status:"error"})}}),children:e.jsxs(e.Stack,{spacing:"6",children:[e.jsxs(e.Stack,{spacing:"5",children:[e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{htmlFor:"username",children:"Username"}),e.jsx(e.Input,{id:"username",type:"username",placeholder:"Enter username",...t.register("username")})]}),e.jsxs(e.FormControl,{children:[e.jsx(e.FormLabel,{htmlFor:"password",children:"Password"}),e.jsxs(e.InputGroup,{children:[e.jsx(e.InputRightElement,{children:e.jsx(e.IconButton,{variant:"link","aria-label":r.isOpen?"Mask password":"Reveal password",icon:r.isOpen?e.jsx(e.RiEye2Line,{}):e.jsx(e.RiEyeCloseLine,{}),onClick:m})}),e.jsx(e.Input,{id:"password",type:r.isOpen?"text":"password",autoComplete:"current-password",required:!0,placeholder:"********",...t.register("password")})]})]})]}),e.jsxs(e.HStack,{justify:"space-between",children:[e.jsx(e.Checkbox,{...t.register("remember"),defaultChecked:!0,children:"Remember me"}),e.jsx(e.Button,{variant:"link",colorScheme:"blue",size:"sm",children:"Forgot password?"})]}),e.jsx(e.Stack,{spacing:"6",children:e.jsx(e.Button,{isLoading:d.status==="loading",colorScheme:"blue",type:"submit",children:"Login"})})]})})]})]})]})}exports.default=p;
