import{n as e}from"./chunk-Bh1tDfsg.js";import{t}from"./Avatar-DgliEa85.js";import{n}from"./Heading-B3YO_p87.js";import{t as r}from"./Trans-CnAc3Ogn.js";import{$ as i,A as a,At as o,C as s,Ct as c,D as l,Dt as u,Et as d,G as f,K as p,M as m,Mt as h,P as g,Q as _,W as v,Z as y,_ as b,_t as x,at as S,b as C,ct as ee,et as w,ft as te,g as ne,ht as T,jt as re,k as E,kt as ie,mt as D,nt as ae,ot as oe,q as se,rt as O,st as ce,tt as le,v as k,x as A,y as j,yt as ue}from"./main-ChC-SNZa.js";import{t as M}from"./Separator-BgSf8Vu2.js";import"./Separator-BRiwsd7J.js";import{t as de}from"./ButtonLink-CvJOjYPg.js";import{n as fe}from"./EndBrowserSessionButton-l-4WagCS.js";var N=e(h(),1),P=re();function F(e,t){return(0,P.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,P.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`})})}F.displayName=`SignOutIcon`;var I=(0,N.forwardRef)(F),L=a(`
  fragment AccountDeleteButton_user on User {
    username
    hasPassword
    matrix {
      mxid
      displayName
    }
  }
`),R=a(`
  fragment AccountDeleteButton_siteConfig on SiteConfig {
    passwordLoginEnabled
  }
`),z=a(`
  mutation DeactivateUser($hsErase: Boolean!, $password: String) {
    deactivateUser(input: { hsErase: $hsErase, password: $password }) {
      status
    }
  }
`),B=({mxid:e,displayName:n,username:r})=>(0,P.jsxs)(`section`,{className:`flex items-center p-4 gap-4 border border-[var(--cpd-color-gray-400)] rounded-xl`,children:[(0,P.jsx)(t,{id:e,name:n||r,size:`56px`}),(0,P.jsxs)(`div`,{className:`flex-1 flex flex-col`,children:[(0,P.jsx)(T,{type:`body`,weight:`semibold`,size:`lg`,className:`text-primary`,children:n||r}),(0,P.jsx)(T,{type:`body`,weight:`regular`,size:`md`,className:`text-secondary`,children:e})]})]}),V=e=>{let t=m(L,e.user),n=m(R,e.siteConfig),{t:i}=g(),a=u({mutationFn:({password:e,hsErase:t})=>E({query:z,variables:{password:e,hsErase:t}}),onSuccess:e=>{e.deactivateUser.status===`DEACTIVATED`&&window.location.reload()}}),[o,s]=(0,N.useState)(!1),[c,d]=(0,N.useState)(!1);(0,N.useEffect)(()=>{if(o){let e=setTimeout(()=>{d(!0)},500);return()=>clearTimeout(e)}d(!1)},[o]);let f=(0,N.useCallback)(e=>{s(e.currentTarget.value!==``)},[]),p=(0,N.useCallback)(e=>{s(e.currentTarget.value===t.matrix.mxid)},[t.matrix.mxid]),h=(0,N.useCallback)(e=>{if(e.preventDefault(),!c)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`;a.mutate({password:n,hsErase:r})},[a.mutate,c]),b=a.data?.deactivateUser.status===`INCORRECT_PASSWORD`,x=a.isPending||a.data?.deactivateUser.status===`DEACTIVATED`,S=t.hasPassword&&n.passwordLoginEnabled;return(0,P.jsxs)(j,{trigger:(0,P.jsx)(D,{kind:`tertiary`,destructive:!0,size:`md`,className:`self-center`,Icon:A,children:i(`frontend.account.delete_account.button`)}),children:[(0,P.jsx)(C,{children:i(`frontend.account.delete_account.dialog_title`)}),(0,P.jsx)(_,{className:`flex flex-col gap-4`,children:(0,P.jsx)(r,{t:i,i18nKey:`frontend.account.delete_account.dialog_description`,components:{text:(0,P.jsx)(T,{type:`body`,weight:`regular`,size:`md`}),list:(0,P.jsx)(`ul`,{className:`list-disc list-outside pl-6`}),item:(0,P.jsx)(T,{as:`li`,type:`body`,weight:`regular`,size:`md`}),profile:(0,P.jsx)(B,{mxid:t.matrix.mxid,username:t.username,displayName:t.matrix.displayName})}})}),(0,P.jsxs)(v.Root,{onSubmit:h,children:[(0,P.jsx)(v.InlineField,{control:(0,P.jsx)(v.CheckboxControl,{}),name:`hs-erase`,children:(0,P.jsx)(v.Label,{children:i(`frontend.account.delete_account.erase_checkbox_label`)})}),(0,P.jsx)(M,{className:`my-1`}),S?(0,P.jsxs)(v.Field,{name:`password`,serverInvalid:b,children:[(0,P.jsx)(v.Label,{children:i(`frontend.account.delete_account.password_label`)}),(0,P.jsx)(v.PasswordControl,{autoComplete:`current-password`,required:!0,onInput:f}),(0,P.jsx)(v.ErrorMessage,{match:`valueMissing`,children:i(`frontend.errors.field_required`)}),b&&(0,P.jsx)(v.ErrorMessage,{children:i(`frontend.account.delete_account.incorrect_password`)})]}):(0,P.jsxs)(v.Field,{name:`mxid`,children:[(0,P.jsx)(v.Label,{children:i(`frontend.account.delete_account.mxid_label`,{mxid:t.matrix.mxid})}),(0,P.jsx)(v.TextControl,{required:!0,placeholder:t.matrix.mxid,onInput:p}),(0,P.jsx)(v.ErrorMessage,{match:`valueMissing`,children:i(`frontend.errors.field_required`)}),(0,P.jsx)(v.ErrorMessage,{match:e=>e!==t.matrix.mxid,children:i(`frontend.account.delete_account.mxid_mismatch`)})]}),o&&(0,P.jsx)(ee,{type:`critical`,title:i(`frontend.account.delete_account.alert_title`),children:i(`frontend.account.delete_account.alert_description`)}),(0,P.jsxs)(D,{type:`submit`,kind:`primary`,destructive:!0,disabled:!c||x,Icon:x?void 0:A,children:[x&&(0,P.jsx)(l,{inline:!0}),i(`frontend.account.delete_account.button`)]})]}),(0,P.jsx)(y,{asChild:!0,children:(0,P.jsx)(D,{kind:`tertiary`,children:i(`action.cancel`)})})]})},pe={link:`_link_1g96u_8`},me=a(`
  fragment PasswordChange_siteConfig on SiteConfig {
    passwordChangeAllowed
  }
`);function he({siteConfig:e}){let{t}=g(),{passwordChangeAllowed:n}=m(me,e);return(0,P.jsx)(v.Root,{children:(0,P.jsxs)(v.Field,{name:`password_preview`,children:[(0,P.jsx)(v.Label,{children:t(`frontend.account.password.label`)}),(0,P.jsx)(v.TextControl,{type:`password`,readOnly:!0,value:`this looks like a password`}),(0,P.jsxs)(v.HelpMessage,{children:[n&&(0,P.jsx)(ue,{to:`/password/change`,className:pe.link,children:t(`frontend.account.password.change`)}),!n&&t(`frontend.account.password.change_disabled`)]})]})})}var H=`Collapsible`,[U,ge]=oe(H),[_e,W]=U(H),G=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,open:r,defaultOpen:a,disabled:o,onOpenChange:s,...c}=e,[l,u]=i({prop:r,defaultProp:a??!1,onChange:s,caller:H});return(0,P.jsx)(_e,{scope:n,disabled:o,contentId:le(),open:l,onOpenToggle:N.useCallback(()=>u(e=>!e),[u]),children:(0,P.jsx)(O.div,{"data-state":X(l),"data-disabled":o?``:void 0,...c,ref:t})})});G.displayName=H;var K=`CollapsibleTrigger`,q=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,...r}=e,i=W(K,n);return(0,P.jsx)(O.button,{type:`button`,"aria-controls":i.contentId,"aria-expanded":i.open||!1,"data-state":X(i.open),"data-disabled":i.disabled?``:void 0,disabled:i.disabled,...r,ref:t,onClick:ce(e.onClick,i.onOpenToggle)})});q.displayName=K;var J=`CollapsibleContent`,Y=N.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=W(J,e.__scopeCollapsible);return(0,P.jsx)(w,{present:n||i.open,children:({present:e})=>(0,P.jsx)(ve,{...r,ref:t,present:e})})});Y.displayName=J;var ve=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,present:r,children:i,...a}=e,o=W(J,n),[s,c]=N.useState(r),l=N.useRef(null),u=S(t,l),d=N.useRef(0),f=d.current,p=N.useRef(0),m=p.current,h=o.open||s,g=N.useRef(h),_=N.useRef(void 0);return N.useEffect(()=>{let e=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(e)},[]),ae(()=>{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,P.jsx)(O.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,P.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,P.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,N.forwardRef)(Z),Ce=e(x(),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:r,className:i,children:a,...o})=>{let{t:s}=g(),[c,l]=(0,N.useState)(r||!1),u=(0,N.useId)(),d=(0,N.useId)(),f=(0,N.useCallback)(e=>{e.preventDefault(),l(e=>!e)},[]);return(0,P.jsx)(ye,{...o,open:c,onOpenChange:l,asChild:!0,"aria-labelledby":u,"aria-describedby":t?d:void 0,className:(0,Ce.default)(Q.root,i),children:(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{className:Q.heading,children:[(0,P.jsxs)(`div`,{className:Q.trigger,children:[(0,P.jsx)(n,{onClick:f,id:u,className:Q.triggerTitle,children:e}),(0,P.jsx)(be,{className:Q.triggerIcon,asChild:!0,children:(0,P.jsx)(te,{tooltip:s(c?`action.collapse`:`action.expand`),children:(0,P.jsx)(Se,{})})})]}),t&&(0,P.jsx)(`p`,{className:Q.description,id:d,children:t})]}),(0,P.jsx)(xe,{asChild:!0,children:(0,P.jsx)(`article`,{className:Q.content,children:a})})]})})},we=a(`
  fragment AddEmailForm_user on User {
    hasPassword
  }
`),Te=a(`
  fragment AddEmailForm_siteConfig on SiteConfig {
    passwordLoginEnabled
  }
`),Ee=a(`
  mutation AddEmail($email: String!, $password: String, $language: String!) {
    startEmailAuthentication(
      input: { email: $email, password: $password, language: $language }
    ) {
      status
      violations
      authentication {
        id
      }
    }
  }
`),De=({user:e,siteConfig:t,onAdd:n})=>{let{hasPassword:r}=m(we,e),{passwordLoginEnabled:i}=m(Te,t),a=r&&i,{t:s,i18n:c}=g(),l=o(),[d,h]=k(),_=u({mutationFn:({email:e,password:t,language:n})=>E({query:Ee,variables:{email:e,password:t,language:n}}),onSuccess:async e=>{if(l.invalidateQueries({queryKey:[`userEmails`]}),e.startEmailAuthentication.status===`STARTED`){if(!e.startEmailAuthentication.authentication?.id)throw Error(`Unexpected response from server`);await n(e.startEmailAuthentication.authentication?.id)}}}),v=(0,N.useCallback)(async e=>{e.preventDefault();let t=new FormData(e.currentTarget).get(`input`),n;if(a&&(n=await d()),(await _.mutateAsync({email:t,password:n,language:c.languages[0]})).startEmailAuthentication.status!==`STARTED`)throw Error()},[_.mutateAsync,a,d,c.languages]),y=_.data?.startEmailAuthentication.status??null,x=_.data?.startEmailAuthentication.violations??[];return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(b,{title:s(`frontend.add_email_form.password_confirmation`),ref:h}),(0,P.jsxs)(f,{onSave:v,required:!0,type:`email`,serverInvalid:!!y&&y!==`STARTED`,label:s(`frontend.add_email_form.email_field_label`),helpLabel:s(`frontend.add_email_form.email_field_help`),saveButtonLabel:s(`action.save`),savingLabel:s(`common.saving`),savedLabel:s(`common.saved`),cancelButtonLabel:s(`action.cancel`),children:[(0,P.jsx)(p,{match:`typeMismatch`,forceMatch:y===`INVALID_EMAIL_ADDRESS`,children:s(`frontend.add_email_form.email_invalid_error`)}),y===`IN_USE`&&(0,P.jsx)(p,{children:s(`frontend.add_email_form.email_in_use_error`)}),y===`RATE_LIMITED`&&(0,P.jsx)(p,{children:s(`frontend.errors.rate_limit_exceeded`)}),y===`DENIED`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(p,{children:s(`frontend.add_email_form.email_denied_error`)}),x.map(e=>(0,P.jsx)(se,{children:e},e))]}),y===`INCORRECT_PASSWORD`&&(0,P.jsx)(p,{children:s(`frontend.add_email_form.incorrect_password_error`)})]})]})},Oe=({id:e})=>{let{t}=g(),n=fe(e,!0);return(0,P.jsxs)(j,{trigger:(0,P.jsx)(D,{kind:`primary`,destructive:!0,size:`lg`,Icon:I,children:t(`frontend.account.sign_out.button`)}),children:[(0,P.jsx)(C,{children:t(`frontend.account.sign_out.dialog`)}),(0,P.jsx)(_,{asChild:!0,children:(0,P.jsxs)(D,{type:`button`,kind:`primary`,destructive:!0,onClick:()=>n.mutate(),disabled:n.isPending,Icon:n.isPending?void 0:I,children:[n.isPending&&(0,P.jsx)(l,{inline:!0}),t(`action.sign_out`)]})}),(0,P.jsx)(y,{asChild:!0,children:(0,P.jsx)(D,{kind:`tertiary`,children:t(`action.cancel`)})})]})};function ke(){let e=c(),{t}=g(),{data:{viewerSession:n,siteConfig:r}}=ie(s);if(n?.__typename!==`BrowserSession`)throw d();return(0,P.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(r.emailChangeAllowed||n.user.emails.totalCount>0)&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)($,{defaultOpen:!0,title:t(`frontend.account.contact_info`),children:[(0,P.jsx)(ne,{user:n.user,siteConfig:r}),r.emailChangeAllowed&&(0,P.jsx)(De,{user:n.user,siteConfig:r,onAdd:async t=>{await e({to:`/emails/$id/verify`,params:{id:t}})}})]}),(0,P.jsx)(M,{kind:`section`})]}),r.passwordLoginEnabled&&n.user.hasPassword&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)($,{defaultOpen:!0,title:t(`frontend.account.account_password`),children:(0,P.jsx)(he,{siteConfig:r})}),(0,P.jsx)(M,{kind:`section`})]}),(0,P.jsxs)($,{title:t(`common.e2ee`),children:[(0,P.jsx)(T,{className:`text-secondary`,size:`md`,children:t(`frontend.reset_cross_signing.description`)}),(0,P.jsx)(de,{to:`/reset-cross-signing`,kind:`secondary`,destructive:!0,children:t(`frontend.reset_cross_signing.start_reset`)})]}),(0,P.jsx)(M,{kind:`section`}),(0,P.jsx)(Oe,{id:n.id}),r.accountDeactivationAllowed&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(M,{}),(0,P.jsx)(V,{user:n.user,siteConfig:r})]}),(0,P.jsx)(M,{})]})}export{ke as component};
//# sourceMappingURL=_account.index-Cv38lvEW.js.map