import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{a as t,i as n,l as r,s as i,t as a}from"./graphql-w47gyQE9.js";import{n as o,t as s}from"./LoadingSpinner-0XRXvdGq.js";import{n as c,t as l}from"./jsx-runtime-BHz_hoGM.js";import{n as u}from"./not-found-i5RsCZif.js";import{t as d}from"./link-RG1Klsig.js";import{d as f,t as p}from"./useTranslation-CWZfA4RN.js";import{n as m}from"./useNavigate-_c9R0sfE.js";import{t as h}from"./Button-CfjN5AeH.js";import{t as g}from"./Avatar-V1mexNc2.js";import{n as _}from"./Heading-fQbpz6tX.js";import{t as v}from"./Trans-CXTCuDnR.js";import{A as y,B as b,C as x,G as S,H as ee,J as C,K as te,L as w,M as T,N as E,R as D,U as ne,V as re,W as ie,X as ae,Z as O,_ as oe,b as k,g as A,j as se,v as ce,x as j,y as M,z as le}from"./main-CqHK_FoX.js";import{t as N}from"./Separator-K1RKzFV8.js";import"./Separator-CUqwPKvA.js";import{t as ue}from"./ButtonLink-BaIKz4k4.js";import{n as de}from"./EndBrowserSessionButton-B-g1OryL.js";var P=e(c(),1),F=l();function I(e,t){return(0,F.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 24 24`,ref:t,...e,children:(0,F.jsx)(`path`,{d:`M9 12.031q0-.424.288-.712A.97.97 0 0 1 10 11.03h7.15l-1.875-1.875a.96.96 0 0 1-.3-.7q0-.4.325-.725a.93.93 0 0 1 .712-.287.98.98 0 0 1 .688.287l3.6 3.6q.15.15.212.325.063.175.063.375 0 .201-.062.375a.9.9 0 0 1-.213.325l-3.6 3.6q-.3.3-.712.288a.98.98 0 0 1-.688-.288 1.02 1.02 0 0 1-.312-.712.93.93 0 0 1 .287-.713l1.875-1.875H10a.97.97 0 0 1-.712-.287A.97.97 0 0 1 9 12.03m-6-7q0-.824.588-1.412A1.93 1.93 0 0 1 5 3.03h6q.424 0 .713.288.287.287.287.712t-.287.713A.97.97 0 0 1 11 5.03H5v14h6q.424 0 .713.288.287.287.287.712t-.287.713a.97.97 0 0 1-.713.287H5q-.824 0-1.412-.587A1.93 1.93 0 0 1 3 19.03z`})})}I.displayName=`SignOutIcon`;var L=(0,P.forwardRef)(I),R=n(`
  fragment AccountDeleteButton_user on User {
    username
    hasPassword
    matrix {
      mxid
      displayName
    }
  }
`),z=n(`
  fragment AccountDeleteButton_siteConfig on SiteConfig {
    passwordLoginEnabled
  }
`),B=n(`
  mutation DeactivateUser($hsErase: Boolean!, $password: String) {
    deactivateUser(input: { hsErase: $hsErase, password: $password }) {
      status
    }
  }
`),V=({mxid:e,displayName:t,username:n})=>(0,F.jsxs)(`section`,{className:`flex items-center p-4 gap-4 border border-[var(--cpd-color-gray-400)] rounded-xl`,children:[(0,F.jsx)(g,{id:e,name:t||n,size:`56px`}),(0,F.jsxs)(`div`,{className:`flex-1 flex flex-col`,children:[(0,F.jsx)(O,{type:`body`,weight:`semibold`,size:`lg`,className:`text-primary`,children:t||n}),(0,F.jsx)(O,{type:`body`,weight:`regular`,size:`md`,className:`text-secondary`,children:e})]})]}),H=e=>{let n=t(R,e.user),r=t(z,e.siteConfig),{t:i}=p(),c=o({mutationFn:({password:e,hsErase:t})=>a({query:B,variables:{password:e,hsErase:t}}),onSuccess:e=>{e.deactivateUser.status===`DEACTIVATED`&&window.location.reload()}}),[l,u]=(0,P.useState)(!1),[d,f]=(0,P.useState)(!1);(0,P.useEffect)(()=>{if(l){let e=setTimeout(()=>{f(!0)},500);return()=>clearTimeout(e)}f(!1)},[l]);let m=(0,P.useCallback)(e=>{u(e.currentTarget.value!==``)},[]),g=(0,P.useCallback)(e=>{u(e.currentTarget.value===n.matrix.mxid)},[n.matrix.mxid]),_=(0,P.useCallback)(e=>{if(e.preventDefault(),!d)return;let t=new FormData(e.currentTarget),n=t.get(`password`);if(n!==null&&typeof n!=`string`)throw Error();let r=t.get(`hs-erase`)===`on`;c.mutate({password:n,hsErase:r})},[c.mutate,d]),b=c.data?.deactivateUser.status===`INCORRECT_PASSWORD`,x=c.isPending||c.data?.deactivateUser.status===`DEACTIVATED`,S=n.hasPassword&&r.passwordLoginEnabled;return(0,F.jsxs)(M,{trigger:(0,F.jsx)(h,{kind:`tertiary`,destructive:!0,size:`md`,className:`self-center`,Icon:j,children:i(`frontend.account.delete_account.button`)}),children:[(0,F.jsx)(k,{children:i(`frontend.account.delete_account.dialog_title`)}),(0,F.jsx)(D,{className:`flex flex-col gap-4`,children:(0,F.jsx)(v,{t:i,i18nKey:`frontend.account.delete_account.dialog_description`,components:{text:(0,F.jsx)(O,{type:`body`,weight:`regular`,size:`md`}),list:(0,F.jsx)(`ul`,{className:`list-disc list-outside pl-6`}),item:(0,F.jsx)(O,{as:`li`,type:`body`,weight:`regular`,size:`md`}),profile:(0,F.jsx)(V,{mxid:n.matrix.mxid,username:n.username,displayName:n.matrix.displayName})}})}),(0,F.jsxs)(y.Root,{onSubmit:_,children:[(0,F.jsx)(y.InlineField,{control:(0,F.jsx)(y.CheckboxControl,{}),name:`hs-erase`,children:(0,F.jsx)(y.Label,{children:i(`frontend.account.delete_account.erase_checkbox_label`)})}),(0,F.jsx)(N,{className:`my-1`}),S?(0,F.jsxs)(y.Field,{name:`password`,serverInvalid:b,children:[(0,F.jsx)(y.Label,{children:i(`frontend.account.delete_account.password_label`)}),(0,F.jsx)(y.PasswordControl,{autoComplete:`current-password`,required:!0,onInput:m}),(0,F.jsx)(y.ErrorMessage,{match:`valueMissing`,children:i(`frontend.errors.field_required`)}),b&&(0,F.jsx)(y.ErrorMessage,{children:i(`frontend.account.delete_account.incorrect_password`)})]}):(0,F.jsxs)(y.Field,{name:`mxid`,children:[(0,F.jsx)(y.Label,{children:i(`frontend.account.delete_account.mxid_label`,{mxid:n.matrix.mxid})}),(0,F.jsx)(y.TextControl,{required:!0,placeholder:n.matrix.mxid,onInput:g}),(0,F.jsx)(y.ErrorMessage,{match:`valueMissing`,children:i(`frontend.errors.field_required`)}),(0,F.jsx)(y.ErrorMessage,{match:e=>e!==n.matrix.mxid,children:i(`frontend.account.delete_account.mxid_mismatch`)})]}),l&&(0,F.jsx)(C,{type:`critical`,title:i(`frontend.account.delete_account.alert_title`),children:i(`frontend.account.delete_account.alert_description`)}),(0,F.jsxs)(h,{type:`submit`,kind:`primary`,destructive:!0,disabled:!d||x,Icon:x?void 0:j,children:[x&&(0,F.jsx)(s,{inline:!0}),i(`frontend.account.delete_account.button`)]})]}),(0,F.jsx)(w,{asChild:!0,children:(0,F.jsx)(h,{kind:`tertiary`,children:i(`action.cancel`)})})]})},fe={link:`_link_1g96u_8`},pe=n(`
  fragment PasswordChange_siteConfig on SiteConfig {
    passwordChangeAllowed
  }
`);function me({siteConfig:e}){let{t:n}=p(),{passwordChangeAllowed:r}=t(pe,e);return(0,F.jsx)(y.Root,{children:(0,F.jsxs)(y.Field,{name:`password_preview`,children:[(0,F.jsx)(y.Label,{children:n(`frontend.account.password.label`)}),(0,F.jsx)(y.TextControl,{type:`password`,readOnly:!0,value:`this looks like a password`}),(0,F.jsxs)(y.HelpMessage,{children:[r&&(0,F.jsx)(d,{to:`/password/change`,className:fe.link,children:n(`frontend.account.password.change`)}),!r&&n(`frontend.account.password.change_disabled`)]})]})})}var U=`Collapsible`,[he,ge]=ie(U),[_e,W]=he(U),G=P.forwardRef((e,t)=>{let{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:a,onOpenChange:o,...s}=e,[c,l]=re({prop:r,defaultProp:i??!1,onChange:o,caller:U});return(0,F.jsx)(_e,{scope:n,disabled:a,contentId:ee(),open:c,onOpenToggle:P.useCallback(()=>l(e=>!e),[l]),children:(0,F.jsx)(b.div,{"data-state":X(c),"data-disabled":a?``:void 0,...s,ref:t})})});G.displayName=U;var K=`CollapsibleTrigger`,q=P.forwardRef((e,t)=>{let{__scopeCollapsible:n,...r}=e,i=W(K,n);return(0,F.jsx)(b.button,{type:`button`,"aria-controls":i.open?i.contentId:void 0,"aria-expanded":i.open||!1,"data-state":X(i.open),"data-disabled":i.disabled?``:void 0,disabled:i.disabled,...r,ref:t,onClick:te(e.onClick,i.onOpenToggle)})});q.displayName=K;var J=`CollapsibleContent`,Y=P.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=W(J,e.__scopeCollapsible);return(0,F.jsx)(le,{present:n||i.open,children:({present:e})=>(0,F.jsx)(ve,{...r,ref:t,present:e})})});Y.displayName=J;var ve=P.forwardRef((e,t)=>{let{__scopeCollapsible:n,present:r,children:i,...a}=e,o=W(J,n),[s,c]=P.useState(r),l=P.useRef(null),u=S(t,l),d=P.useRef(0),f=d.current,p=P.useRef(0),m=p.current,h=o.open||s,g=P.useRef(h),_=P.useRef(void 0);return P.useEffect(()=>{let e=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(e)},[]),ne(()=>{let e=l.current;if(e){_.current=_.current||{transitionDuration:e.style.transitionDuration,animationName:e.style.animationName},e.style.transitionDuration=`0s`,e.style.animationName=`none`;let t=e.getBoundingClientRect();d.current=t.height,p.current=t.width,g.current||(e.style.transitionDuration=_.current.transitionDuration,e.style.animationName=_.current.animationName),c(r)}},[o.open,r]),(0,F.jsx)(b.div,{"data-state":X(o.open),"data-disabled":o.disabled?``:void 0,id:o.contentId,hidden:!h,...a,ref:u,style:{"--radix-collapsible-content-height":f?`${f}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:h&&i})});function X(e){return e?`open`:`closed`}var ye=G,be=q,xe=Y;function Z(e,t){return(0,F.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`1em`,height:`1em`,fill:`currentColor`,viewBox:`0 0 24 24`,ref:t,...e,children:(0,F.jsx)(`path`,{d:`m12 10.775-3.9 3.9a.95.95 0 0 1-.7.275.95.95 0 0 1-.7-.275.95.95 0 0 1-.275-.7q0-.425.275-.7l4.6-4.6q.15-.15.325-.212Q11.8 8.4 12 8.4t.375.063a.9.9 0 0 1 .325.212l4.6 4.6a.95.95 0 0 1 .275.7.95.95 0 0 1-.275.7.95.95 0 0 1-.7.275.95.95 0 0 1-.7-.275z`})})}Z.displayName=`ChevronUpIcon`;var Se=(0,P.forwardRef)(Z),Ce=e(f(),1),Q={root:`_root_1hqni_8`,heading:`_heading_1hqni_14`,trigger:`_trigger_1hqni_20`,triggerTitle:`_trigger-title_1hqni_29`,triggerIcon:`_trigger-icon_1hqni_34`,description:`_description_1hqni_42`,content:`_content_1hqni_48`},$=({title:e,description:t,defaultOpen:n,className:r,children:i,...a})=>{let{t:o}=p(),[s,c]=(0,P.useState)(n||!1),l=(0,P.useId)(),u=(0,P.useId)(),d=(0,P.useCallback)(e=>{e.preventDefault(),c(e=>!e)},[]);return(0,F.jsx)(ye,{...a,open:s,onOpenChange:c,asChild:!0,"aria-labelledby":l,"aria-describedby":t?u:void 0,className:(0,Ce.default)(Q.root,r),children:(0,F.jsxs)(`section`,{children:[(0,F.jsxs)(`header`,{className:Q.heading,children:[(0,F.jsxs)(`div`,{className:Q.trigger,children:[(0,F.jsx)(_,{onClick:d,id:l,className:Q.triggerTitle,children:e}),(0,F.jsx)(be,{className:Q.triggerIcon,asChild:!0,children:(0,F.jsx)(ae,{tooltip:o(s?`action.collapse`:`action.expand`),children:(0,F.jsx)(Se,{})})})]}),t&&(0,F.jsx)(`p`,{className:Q.description,id:u,children:t})]}),(0,F.jsx)(xe,{asChild:!0,children:(0,F.jsx)(`article`,{className:Q.content,children:i})})]})})},we=n(`
  fragment AddEmailForm_user on User {
    hasPassword
  }
`),Te=n(`
  fragment AddEmailForm_siteConfig on SiteConfig {
    passwordLoginEnabled
  }
`),Ee=n(`
  mutation AddEmail($email: String!, $password: String, $language: String!) {
    startEmailAuthentication(
      input: { email: $email, password: $password, language: $language }
    ) {
      status
      violations
      authentication {
        id
      }
    }
  }
`),De=({user:e,siteConfig:n,onAdd:i})=>{let{hasPassword:s}=t(we,e),{passwordLoginEnabled:c}=t(Te,n),l=s&&c,{t:u,i18n:d}=p(),f=r(),[m,h]=ce(),g=o({mutationFn:({email:e,password:t,language:n})=>a({query:Ee,variables:{email:e,password:t,language:n}}),onSuccess:async e=>{if(f.invalidateQueries({queryKey:[`userEmails`]}),e.startEmailAuthentication.status===`STARTED`){if(!e.startEmailAuthentication.authentication?.id)throw Error(`Unexpected response from server`);await i(e.startEmailAuthentication.authentication?.id)}}}),_=(0,P.useCallback)(async e=>{e.preventDefault();let t=new FormData(e.currentTarget).get(`input`),n;if(l&&(n=await m()),(await g.mutateAsync({email:t,password:n,language:d.languages[0]})).startEmailAuthentication.status!==`STARTED`)throw Error()},[g.mutateAsync,l,m,d.languages]),v=g.data?.startEmailAuthentication.status??null,y=g.data?.startEmailAuthentication.violations??[];return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(oe,{title:u(`frontend.add_email_form.password_confirmation`),ref:h}),(0,F.jsxs)(se,{onSave:_,required:!0,type:`email`,serverInvalid:!!v&&v!==`STARTED`,label:u(`frontend.add_email_form.email_field_label`),helpLabel:u(`frontend.add_email_form.email_field_help`),saveButtonLabel:u(`action.save`),savingLabel:u(`common.saving`),savedLabel:u(`common.saved`),cancelButtonLabel:u(`action.cancel`),children:[(0,F.jsx)(T,{match:`typeMismatch`,forceMatch:v===`INVALID_EMAIL_ADDRESS`,children:u(`frontend.add_email_form.email_invalid_error`)}),v===`IN_USE`&&(0,F.jsx)(T,{children:u(`frontend.add_email_form.email_in_use_error`)}),v===`RATE_LIMITED`&&(0,F.jsx)(T,{children:u(`frontend.errors.rate_limit_exceeded`)}),v===`DENIED`&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(T,{children:u(`frontend.add_email_form.email_denied_error`)}),y.map(e=>(0,F.jsx)(E,{children:e},e))]}),v===`INCORRECT_PASSWORD`&&(0,F.jsx)(T,{children:u(`frontend.add_email_form.incorrect_password_error`)})]})]})},Oe=({id:e})=>{let{t}=p(),n=de(e,!0);return(0,F.jsxs)(M,{trigger:(0,F.jsx)(h,{kind:`primary`,destructive:!0,size:`lg`,Icon:L,children:t(`frontend.account.sign_out.button`)}),children:[(0,F.jsx)(k,{children:t(`frontend.account.sign_out.dialog`)}),(0,F.jsx)(D,{asChild:!0,children:(0,F.jsxs)(h,{type:`button`,kind:`primary`,destructive:!0,onClick:()=>n.mutate(),disabled:n.isPending,Icon:n.isPending?void 0:L,children:[n.isPending&&(0,F.jsx)(s,{inline:!0}),t(`action.sign_out`)]})}),(0,F.jsx)(w,{asChild:!0,children:(0,F.jsx)(h,{kind:`tertiary`,children:t(`action.cancel`)})})]})};function ke(){let e=m(),{t}=p(),{data:{viewerSession:n,siteConfig:r}}=i(x);if(n?.__typename!==`BrowserSession`)throw u();return(0,F.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(r.emailChangeAllowed||n.user.emails.totalCount>0)&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)($,{defaultOpen:!0,title:t(`frontend.account.contact_info`),children:[(0,F.jsx)(A,{user:n.user,siteConfig:r}),r.emailChangeAllowed&&(0,F.jsx)(De,{user:n.user,siteConfig:r,onAdd:async t=>{await e({to:`/emails/$id/verify`,params:{id:t}})}})]}),(0,F.jsx)(N,{kind:`section`})]}),r.passwordLoginEnabled&&n.user.hasPassword&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)($,{defaultOpen:!0,title:t(`frontend.account.account_password`),children:(0,F.jsx)(me,{siteConfig:r})}),(0,F.jsx)(N,{kind:`section`})]}),(0,F.jsxs)($,{title:t(`common.e2ee`),children:[(0,F.jsx)(O,{className:`text-secondary`,size:`md`,children:t(`frontend.reset_cross_signing.description`)}),(0,F.jsx)(ue,{to:`/reset-cross-signing`,kind:`secondary`,destructive:!0,children:t(`frontend.reset_cross_signing.start_reset`)})]}),(0,F.jsx)(N,{kind:`section`}),(0,F.jsx)(Oe,{id:n.id}),r.accountDeactivationAllowed&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(N,{}),(0,F.jsx)(H,{user:n.user,siteConfig:r})]}),(0,F.jsx)(N,{})]})}export{ke as component};
//# sourceMappingURL=_account.index-CCd9q3rX.js.map