import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{a as t,r as n,s as r,t as i}from"./graphql-DoHZA98X.js";import{n as a,t as o}from"./LoadingSpinner-B4qmRXm8.js";import{n as s,t as c}from"./jsx-runtime-BHz_hoGM.js";import{n as l}from"./not-found-i5RsCZif.js";import{t as u}from"./link-C5HcoTdL.js";import{f as d,t as f}from"./useTranslation-CvpQbuHy.js";import{n as p}from"./useNavigate-_c9R0sfE.js";import{t as m}from"./Text-5cGdO1lY.js";import{t as h}from"./Button-BsQwiPxy.js";import{t as g}from"./IconButton-8-SP7uXc.js";import{t as _}from"./Alert-Cv1Qk_aP.js";import{t as v}from"./Avatar-Ddktawb0.js";import{i as y,n as b,r as x,t as S}from"./Form-BGfdeQUz.js";import{a as C,c as ee,d as te,f as ne,i as w,l as re,n as T,o as E,r as D,s as ie,t as O,u as k}from"./Dialog-BMazobwD.js";import{n as ae}from"./Heading-BC6aWv8D.js";import"./LoadingSpinner-FeQKcGKO.js";import{t as oe}from"./Trans-C_dpnjwR.js";import{a as se,i as ce,r as le,t as ue}from"./UserEmailList-CI3amvTe.js";import{t as A}from"./fragment-masking-DSZC2_uz.js";import{t as j}from"./delete-DPbZcv-9.js";import{t as M}from"./Separator-HVVfTnrU.js";import"./Separator-CFvXpK0N.js";import{t as de}from"./ButtonLink-D518vkFm.js";import{n as fe}from"./EndBrowserSessionButton-CtKRrA4A.js";var N=e(s(),1),P=c();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=n(`
  fragment AccountDeleteButton_user on User {
    username
    hasPassword
    matrix {
      mxid
      displayName
    }
  }
`),R=n(`
  fragment AccountDeleteButton_siteConfig on SiteConfig {
    passwordLoginEnabled
  }
`),z=n(`
  mutation DeactivateUser($hsErase: Boolean!, $password: String) {
    deactivateUser(input: { hsErase: $hsErase, password: $password }) {
      status
    }
  }
`),B=({mxid:e,displayName:t,username:n})=>(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)(v,{id:e,name:t||n,size:`56px`}),(0,P.jsxs)(`div`,{className:`flex-1 flex flex-col`,children:[(0,P.jsx)(m,{type:`body`,weight:`semibold`,size:`lg`,className:`text-primary`,children:t||n}),(0,P.jsx)(m,{type:`body`,weight:`regular`,size:`md`,className:`text-secondary`,children:e})]})]}),V=e=>{let t=A(L,e.user),n=A(R,e.siteConfig),{t:r}=f(),s=a({mutationFn:({password:e,hsErase:t})=>i({query:z,variables:{password:e,hsErase:t}}),onSuccess:e=>{e.deactivateUser.status===`DEACTIVATED`&&window.location.reload()}}),[c,l]=(0,N.useState)(!1),[u,d]=(0,N.useState)(!1);(0,N.useEffect)(()=>{if(c){let e=setTimeout(()=>{d(!0)},500);return()=>clearTimeout(e)}d(!1)},[c]);let p=(0,N.useCallback)(e=>{l(e.currentTarget.value!==``)},[]),g=(0,N.useCallback)(e=>{l(e.currentTarget.value===t.matrix.mxid)},[t.matrix.mxid]),v=(0,N.useCallback)(e=>{if(e.preventDefault(),!u)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`;s.mutate({password:n,hsErase:r})},[s.mutate,u]),y=s.data?.deactivateUser.status===`INCORRECT_PASSWORD`,b=s.isPending||s.data?.deactivateUser.status===`DEACTIVATED`,x=t.hasPassword&&n.passwordLoginEnabled;return(0,P.jsxs)(O,{trigger:(0,P.jsx)(h,{kind:`tertiary`,destructive:!0,size:`md`,className:`self-center`,Icon:j,children:r(`frontend.account.delete_account.button`)}),children:[(0,P.jsx)(T,{children:r(`frontend.account.delete_account.dialog_title`)}),(0,P.jsx)(w,{className:`flex flex-col gap-4`,children:(0,P.jsx)(oe,{t:r,i18nKey:`frontend.account.delete_account.dialog_description`,components:{text:(0,P.jsx)(m,{type:`body`,weight:`regular`,size:`md`}),list:(0,P.jsx)(`ul`,{className:`list-disc list-outside pl-6`}),item:(0,P.jsx)(m,{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)(S.Root,{onSubmit:v,children:[(0,P.jsx)(S.InlineField,{control:(0,P.jsx)(S.CheckboxControl,{}),name:`hs-erase`,children:(0,P.jsx)(S.Label,{children:r(`frontend.account.delete_account.erase_checkbox_label`)})}),(0,P.jsx)(M,{className:`my-1`}),x?(0,P.jsxs)(S.Field,{name:`password`,serverInvalid:y,children:[(0,P.jsx)(S.Label,{children:r(`frontend.account.delete_account.password_label`)}),(0,P.jsx)(S.PasswordControl,{autoComplete:`current-password`,required:!0,onInput:p}),(0,P.jsx)(S.ErrorMessage,{match:`valueMissing`,children:r(`frontend.errors.field_required`)}),y&&(0,P.jsx)(S.ErrorMessage,{children:r(`frontend.account.delete_account.incorrect_password`)})]}):(0,P.jsxs)(S.Field,{name:`mxid`,children:[(0,P.jsx)(S.Label,{children:r(`frontend.account.delete_account.mxid_label`,{mxid:t.matrix.mxid})}),(0,P.jsx)(S.TextControl,{required:!0,placeholder:t.matrix.mxid,onInput:g}),(0,P.jsx)(S.ErrorMessage,{match:`valueMissing`,children:r(`frontend.errors.field_required`)}),(0,P.jsx)(S.ErrorMessage,{match:e=>e!==t.matrix.mxid,children:r(`frontend.account.delete_account.mxid_mismatch`)})]}),c&&(0,P.jsx)(_,{type:`critical`,title:r(`frontend.account.delete_account.alert_title`),children:r(`frontend.account.delete_account.alert_description`)}),(0,P.jsxs)(h,{type:`submit`,kind:`primary`,destructive:!0,disabled:!u||b,Icon:b?void 0:j,children:[b&&(0,P.jsx)(o,{inline:!0}),r(`frontend.account.delete_account.button`)]})]}),(0,P.jsx)(D,{asChild:!0,children:(0,P.jsx)(h,{kind:`tertiary`,children:r(`action.cancel`)})})]})},pe={link:`_link_1g96u_8`},me=n(`
  fragment PasswordChange_siteConfig on SiteConfig {
    passwordChangeAllowed
  }
`);function he({siteConfig:e}){let{t}=f(),{passwordChangeAllowed:n}=A(me,e);return(0,P.jsx)(S.Root,{children:(0,P.jsxs)(S.Field,{name:`password_preview`,children:[(0,P.jsx)(S.Label,{children:t(`frontend.account.password.label`)}),(0,P.jsx)(S.TextControl,{type:`password`,readOnly:!0,value:`this looks like a password`}),(0,P.jsxs)(S.HelpMessage,{children:[n&&(0,P.jsx)(u,{to:`/password/change`,className:pe.link,children:t(`frontend.account.password.change`)}),!n&&t(`frontend.account.password.change_disabled`)]})]})})}var H=`Collapsible`,[ge,_e]=k(H),[ve,U]=ge(H),W=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,open:r,defaultOpen:i,disabled:a,onOpenChange:o,...s}=e,[c,l]=ie({prop:r,defaultProp:i??!1,onChange:o,caller:H});return(0,P.jsx)(ve,{scope:n,disabled:a,contentId:ee(),open:c,onOpenToggle:N.useCallback(()=>l(e=>!e),[l]),children:(0,P.jsx)(E.div,{"data-state":Y(c),"data-disabled":a?``:void 0,...s,ref:t})})});W.displayName=H;var G=`CollapsibleTrigger`,K=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,...r}=e,i=U(G,n);return(0,P.jsx)(E.button,{type:`button`,"aria-controls":i.open?i.contentId:void 0,"aria-expanded":i.open||!1,"data-state":Y(i.open),"data-disabled":i.disabled?``:void 0,disabled:i.disabled,...r,ref:t,onClick:ne(e.onClick,i.onOpenToggle)})});K.displayName=G;var q=`CollapsibleContent`,J=N.forwardRef((e,t)=>{let{forceMount:n,...r}=e,i=U(q,e.__scopeCollapsible);return(0,P.jsx)(C,{present:n||i.open,children:({present:e})=>(0,P.jsx)(ye,{...r,ref:t,present:e})})});J.displayName=q;var ye=N.forwardRef((e,t)=>{let{__scopeCollapsible:n,present:r,children:i,...a}=e,o=U(q,n),[s,c]=N.useState(r),l=N.useRef(null),u=te(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)},[]),re(()=>{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)(E.div,{"data-state":Y(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 Y(e){return e?`open`:`closed`}var be=W,xe=K,Se=J;function X(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`})})}X.displayName=`ChevronUpIcon`;var Z=(0,N.forwardRef)(X),Ce=e(d(),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}=f(),[s,c]=(0,N.useState)(n||!1),l=(0,N.useId)(),u=(0,N.useId)(),d=(0,N.useCallback)(e=>{e.preventDefault(),c(e=>!e)},[]);return(0,P.jsx)(be,{...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,P.jsxs)(`section`,{children:[(0,P.jsxs)(`header`,{className:Q.heading,children:[(0,P.jsxs)(`div`,{className:Q.trigger,children:[(0,P.jsx)(ae,{onClick:d,id:l,className:Q.triggerTitle,children:e}),(0,P.jsx)(xe,{className:Q.triggerIcon,asChild:!0,children:(0,P.jsx)(g,{tooltip:o(s?`action.collapse`:`action.expand`),children:(0,P.jsx)(Z,{})})})]}),t&&(0,P.jsx)(`p`,{className:Q.description,id:u,children:t})]}),(0,P.jsx)(Se,{asChild:!0,children:(0,P.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:t,onAdd:n})=>{let{hasPassword:o}=A(we,e),{passwordLoginEnabled:s}=A(Te,t),c=o&&s,{t:l,i18n:u}=f(),d=r(),[p,m]=ce(),h=a({mutationFn:({email:e,password:t,language:n})=>i({query:Ee,variables:{email:e,password:t,language:n}}),onSuccess:async e=>{if(d.invalidateQueries({queryKey:[`userEmails`]}),e.startEmailAuthentication.status===`STARTED`){if(!e.startEmailAuthentication.authentication?.id)throw Error(`Unexpected response from server`);await n(e.startEmailAuthentication.authentication?.id)}}}),g=(0,N.useCallback)(async e=>{e.preventDefault();let t=new FormData(e.currentTarget).get(`input`),n;if(c&&(n=await p()),(await h.mutateAsync({email:t,password:n,language:u.languages[0]})).startEmailAuthentication.status!==`STARTED`)throw Error()},[h.mutateAsync,c,p,u.languages]),_=h.data?.startEmailAuthentication.status??null,v=h.data?.startEmailAuthentication.violations??[];return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(le,{title:l(`frontend.add_email_form.password_confirmation`),ref:m}),(0,P.jsxs)(b,{onSave:g,required:!0,type:`email`,serverInvalid:!!_&&_!==`STARTED`,label:l(`frontend.add_email_form.email_field_label`),helpLabel:l(`frontend.add_email_form.email_field_help`),saveButtonLabel:l(`action.save`),savingLabel:l(`common.saving`),savedLabel:l(`common.saved`),cancelButtonLabel:l(`action.cancel`),children:[(0,P.jsx)(x,{match:`typeMismatch`,forceMatch:_===`INVALID_EMAIL_ADDRESS`,children:l(`frontend.add_email_form.email_invalid_error`)}),_===`IN_USE`&&(0,P.jsx)(x,{children:l(`frontend.add_email_form.email_in_use_error`)}),_===`RATE_LIMITED`&&(0,P.jsx)(x,{children:l(`frontend.errors.rate_limit_exceeded`)}),_===`DENIED`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(x,{children:l(`frontend.add_email_form.email_denied_error`)}),v.map(e=>(0,P.jsx)(y,{children:e},e))]}),_===`INCORRECT_PASSWORD`&&(0,P.jsx)(x,{children:l(`frontend.add_email_form.incorrect_password_error`)})]})]})},Oe=({id:e})=>{let{t}=f(),n=fe(e,!0);return(0,P.jsxs)(O,{trigger:(0,P.jsx)(h,{kind:`primary`,destructive:!0,size:`lg`,Icon:I,children:t(`frontend.account.sign_out.button`)}),children:[(0,P.jsx)(T,{children:t(`frontend.account.sign_out.dialog`)}),(0,P.jsx)(w,{asChild:!0,children:(0,P.jsxs)(h,{type:`button`,kind:`primary`,destructive:!0,onClick:()=>n.mutate(),disabled:n.isPending,Icon:n.isPending?void 0:I,children:[n.isPending&&(0,P.jsx)(o,{inline:!0}),t(`action.sign_out`)]})}),(0,P.jsx)(D,{asChild:!0,children:(0,P.jsx)(h,{kind:`tertiary`,children:t(`action.cancel`)})})]})};function ke(){let e=p(),{t:n}=f(),{data:{viewerSession:r,siteConfig:i}}=t(se);if(r?.__typename!==`BrowserSession`)throw l();return(0,P.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(i.emailChangeAllowed||r.user.emails.totalCount>0)&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)($,{defaultOpen:!0,title:n(`frontend.account.contact_info`),children:[(0,P.jsx)(ue,{user:r.user,siteConfig:i}),i.emailChangeAllowed&&(0,P.jsx)(De,{user:r.user,siteConfig:i,onAdd:async t=>{await e({to:`/emails/$id/verify`,params:{id:t}})}})]}),(0,P.jsx)(M,{kind:`section`})]}),i.passwordLoginEnabled&&r.user.hasPassword&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)($,{defaultOpen:!0,title:n(`frontend.account.account_password`),children:(0,P.jsx)(he,{siteConfig:i})}),(0,P.jsx)(M,{kind:`section`})]}),(0,P.jsxs)($,{title:n(`common.e2ee`),children:[(0,P.jsx)(m,{className:`text-secondary`,size:`md`,children:n(`frontend.reset_cross_signing.description`)}),(0,P.jsx)(de,{to:`/reset-cross-signing`,kind:`secondary`,destructive:!0,children:n(`frontend.reset_cross_signing.start_reset`)})]}),(0,P.jsx)(M,{kind:`section`}),(0,P.jsx)(Oe,{id:r.id}),i.accountDeactivationAllowed&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(M,{}),(0,P.jsx)(V,{user:r.user,siteConfig:i})]}),(0,P.jsx)(M,{})]})}export{ke as component};
//# sourceMappingURL=_account.index-CnV5nYOk.js.map