import{j as e,a as D,r as x,b as h,c as A,d as B,u as y,T as m,D as q,e as F,f as S,R as w,F as g,g as j,A as E,C as R,H as L,h as U,i as z,k as G,B as M,l as p,m as O,n as k,o as $,p as H,q as P,s as Q,L as V,O as K}from"./main-Bn3jZxQW.js";import{H as Y}from"./Heading-BPu-MP59.js";import{I as J}from"./edit-CDDdEeO1.js";import{A as v}from"./Avatar-QWt5VU0l.js";import{S as W}from"./Submit-s3yrm_WK.js";import"./_commonjsHelpers-DaWZu8wl.js";/* empty css               */const X="_nav-bar_16kbp_8",Z="_nav-bar-items_16kbp_12",_={navBar:X,navBarItems:Z},ee=({children:a})=>e.jsx("nav",{className:_.navBar,children:e.jsx("ul",{className:_.navBarItems,children:a})}),se="_nav-tab_9fhit_8",ae="_nav-item_9fhit_26",N={navTab:se,navItem:ae},u=a=>e.jsx("li",{className:N.navTab,children:e.jsx(D,{className:N.navItem,activeProps:{"aria-current":"page"},...a})}),te="_user_lnqhg_8",ne="_meta_lnqhg_19",ie="_edit-button_lnqhg_32",re="_mxid_lnqhg_36",le="_dialog-form_lnqhg_40",l={user:te,meta:ne,editButton:ie,mxid:re,dialogForm:le},oe=p(`
  fragment UserGreeting_user on User {
    id
    matrix {
      mxid
      displayName
    }
  }
`),ce=p(`
  fragment UserGreeting_siteConfig on SiteConfig {
    displayNameChangeAllowed
  }
`),de=p(`
  mutation SetDisplayName($userId: ID!, $displayName: String) {
    setDisplayName(input: { userId: $userId, displayName: $displayName }) {
      status
    }
  }
`),me=x.forwardRef(({label:a,...r},t)=>e.jsx(k,{label:a,children:e.jsx($,{ref:t,type:"button",size:"var(--cpd-space-6x)",className:l.editButton,...r,children:e.jsx(J,{})})})),ue=({user:a,siteConfig:r})=>{const t=x.useRef(null),s=h(oe,a),{displayNameChangeAllowed:c}=h(ce,r),I=A(),o=B({mutationFn:({userId:i,displayName:d})=>O({query:de,variables:{userId:i,displayName:d}}),onSuccess:i=>{I.invalidateQueries({queryKey:["currentUserGreeting"]}),i.setDisplayName.status==="SET"&&f(!1)}}),[b,f]=x.useState(!1),{t:n}=y(),C=i=>{i.preventDefault();const d=i.currentTarget,T=new FormData(d).get("displayname")||null;o.mutate({displayName:T,userId:s.id})};return e.jsxs("div",{className:l.user,children:[e.jsx(v,{size:"var(--cpd-space-14x)",id:s.matrix.mxid,name:s.matrix.displayName||s.matrix.mxid,className:l.avatar}),e.jsx("div",{className:l.meta,children:s.matrix.displayName?e.jsxs(e.Fragment,{children:[e.jsx(m,{size:"lg",weight:"semibold",children:s.matrix.displayName}),e.jsx(m,{size:"md",className:l.mxid,children:s.matrix.mxid})]}):e.jsx(m,{size:"lg",weight:"semibold",children:s.matrix.mxid})}),c&&e.jsxs(q,{trigger:e.jsx(me,{label:n("action.edit")}),open:b,onOpenChange:i=>{t.current?.form?.reset(),f(i)},children:[e.jsx(F,{children:n("frontend.account.edit_profile.title")}),e.jsx(v,{size:"88px",className:"self-center",id:s.matrix.mxid,name:s.matrix.displayName||s.matrix.mxid}),e.jsx(S,{asChild:!0,children:e.jsxs(w,{onSubmit:C,children:[e.jsxs("div",{className:l.dialogForm,children:[e.jsxs(g,{name:"displayname",serverInvalid:o.data?.setDisplayName.status==="INVALID",children:[e.jsx(j,{children:n("frontend.account.edit_profile.display_name_label")}),e.jsx(E,{type:"text",Icon:R,autoComplete:"name",defaultValue:s.matrix.displayName||void 0,actionLabel:n("action.clear"),ref:t,onActionClick:()=>{t.current&&(t.current.value="",t.current.focus())}}),e.jsx(L,{children:n("frontend.account.edit_profile.display_name_help")})]}),e.jsxs(g,{name:"mxid",children:[e.jsx(j,{children:n("frontend.account.edit_profile.username_label")}),e.jsx(U,{value:s.matrix.mxid,readOnly:!0})]})]}),e.jsxs(W,{disabled:o.isPending,children:[o.isPending&&e.jsx(z,{inline:!0}),n("action.save")]})]})}),e.jsx(G,{asChild:!0,children:e.jsx(M,{kind:"tertiary",children:n("action.cancel")})})]})]})};function Ne(){const{t:a}=y(),r=H(P),t=r.data.viewer;if(t?.__typename!=="User")throw Q();const{siteConfig:s}=r.data,{planManagementIframeUri:c}=s;return e.jsxs(V,{wide:!0,children:[e.jsxs("div",{className:"flex flex-col gap-10",children:[e.jsx(Y,{size:"md",weight:"semibold",children:a("frontend.account.title")}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ue,{user:t,siteConfig:s}),e.jsxs(ee,{children:[e.jsx(u,{to:"/",children:a("frontend.nav.settings")}),e.jsx(u,{to:"/sessions",children:a("frontend.nav.devices")}),c&&e.jsx(u,{to:"/plan",children:a("frontend.nav.plan")})]})]})]}),e.jsx(K,{})]})}export{Ne as component};
//# sourceMappingURL=_account-BrGmE1wb.js.map
