import{n as e}from"./chunk-Bh1tDfsg.js";import{t}from"./Avatar-DgliEa85.js";import{i as n}from"./Heading-B3YO_p87.js";import{A as r,At as i,D as a,Dt as o,E as s,Et as c,M as l,Mt as u,O as d,P as f,Q as p,W as m,Z as h,b as g,dt as _,ft as v,ht as y,jt as b,k as x,kt as S,lt as C,mt as w,pt as T,vt as E,y as D,yt as O}from"./main-ChC-SNZa.js";import{t as k}from"./edit-COFX0spr.js";var A={navBar:`_nav-bar_16kbp_8`,navBarItems:`_nav-bar-items_16kbp_12`},j=b(),M=({children:e})=>(0,j.jsx)(`nav`,{className:A.navBar,children:(0,j.jsx)(`ul`,{className:A.navBarItems,children:e})}),N={navTab:`_nav-tab_12e0b_8`,navItem:`_nav-item_12e0b_26`,externalLink:`_external-link_12e0b_43`,navBarErrorIcon:`_nav-bar-error-icon_12e0b_67`},P=e=>(0,j.jsx)(`li`,{className:N.navTab,children:(0,j.jsx)(O,{className:N.navItem,activeProps:{"aria-current":`page`},...e})}),F=e=>(0,j.jsx)(_,{className:N.navBarErrorIcon}),I=e(u(),1),L={user:`_user_lnqhg_8`,meta:`_meta_lnqhg_19`,editButton:`_edit-button_lnqhg_32`,mxid:`_mxid_lnqhg_36`,dialogForm:`_dialog-form_lnqhg_40`},R=r(`
  fragment UserGreeting_user on User {
    id
    matrix {
      mxid
      displayName
    }
  }
`),z=r(`
  fragment UserGreeting_siteConfig on SiteConfig {
    displayNameChangeAllowed
  }
`),B=r(`
  mutation SetDisplayName($userId: ID!, $displayName: String) {
    setDisplayName(input: { userId: $userId, displayName: $displayName }) {
      status
    }
  }
`),V=(0,I.forwardRef)(({label:e,...t},n)=>(0,j.jsx)(T,{label:e,children:(0,j.jsx)(v,{ref:n,type:`button`,size:`var(--cpd-space-6x)`,className:L.editButton,...t,children:(0,j.jsx)(k,{})})})),H=({user:e,siteConfig:n})=>{let r=(0,I.useRef)(null),s=l(R,e),{displayNameChangeAllowed:c}=l(z,n),u=i(),d=o({mutationFn:({userId:e,displayName:t})=>x({query:B,variables:{userId:e,displayName:t}}),onSuccess:e=>{u.invalidateQueries({queryKey:[`currentUserGreeting`]}),e.setDisplayName.status===`SET`&&v(!1)}}),[_,v]=(0,I.useState)(!1),{t:b}=f();return(0,j.jsxs)(`div`,{className:L.user,children:[(0,j.jsx)(t,{size:`var(--cpd-space-14x)`,id:s.matrix.mxid,name:s.matrix.displayName||s.matrix.mxid,className:L.avatar}),(0,j.jsx)(`div`,{className:L.meta,children:s.matrix.displayName?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(y,{size:`lg`,weight:`semibold`,children:s.matrix.displayName}),(0,j.jsx)(y,{size:`md`,className:L.mxid,children:s.matrix.mxid})]}):(0,j.jsx)(y,{size:`lg`,weight:`semibold`,children:s.matrix.mxid})}),c&&(0,j.jsxs)(D,{trigger:(0,j.jsx)(V,{label:b(`action.edit`)}),open:_,onOpenChange:e=>{r.current?.form?.reset(),v(e)},children:[(0,j.jsx)(g,{children:b(`frontend.account.edit_profile.title`)}),(0,j.jsx)(t,{size:`88px`,className:`self-center`,id:s.matrix.mxid,name:s.matrix.displayName||s.matrix.mxid}),(0,j.jsx)(p,{asChild:!0,children:(0,j.jsxs)(m.Root,{onSubmit:e=>{e.preventDefault();let t=e.currentTarget,n=new FormData(t).get(`displayname`)||null;d.mutate({displayName:n,userId:s.id})},children:[(0,j.jsxs)(`div`,{className:L.dialogForm,children:[(0,j.jsxs)(m.Field,{name:`displayname`,serverInvalid:d.data?.setDisplayName.status===`INVALID`,children:[(0,j.jsx)(m.Label,{children:b(`frontend.account.edit_profile.display_name_label`)}),(0,j.jsx)(m.ActionControl,{type:`text`,Icon:C,autoComplete:`name`,defaultValue:s.matrix.displayName||void 0,actionLabel:b(`action.clear`),ref:r,onActionClick:()=>{r.current&&(r.current.value=``,r.current.focus())}}),(0,j.jsx)(m.HelpMessage,{children:b(`frontend.account.edit_profile.display_name_help`)})]}),(0,j.jsxs)(m.Field,{name:`mxid`,children:[(0,j.jsx)(m.Label,{children:b(`frontend.account.edit_profile.username_label`)}),(0,j.jsx)(m.TextControl,{value:s.matrix.mxid,readOnly:!0})]})]}),(0,j.jsxs)(m.Submit,{disabled:d.isPending,children:[d.isPending&&(0,j.jsx)(a,{inline:!0}),b(`action.save`)]})]})}),(0,j.jsx)(h,{asChild:!0,children:(0,j.jsx)(w,{kind:`tertiary`,children:b(`action.cancel`)})})]})]})};function U(){let{t:e}=f(),t=S(s),r=t.data.viewer;if(r?.__typename!==`User`)throw c();let{siteConfig:i}=t.data,{planManagementIframeUri:a,sessionLimit:o}=i,l=null;return o&&r.unfilteredAppSessions.totalCount>=o.softLimit&&(l=(0,j.jsx)(T,{label:e(`frontend.nav.device_limit_error`),children:(0,j.jsx)(F,{})})),(0,j.jsxs)(d,{wide:!0,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,j.jsx)(n,{size:`md`,weight:`semibold`,children:e(`frontend.account.title`)}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,j.jsx)(H,{user:r,siteConfig:i}),(0,j.jsxs)(M,{children:[(0,j.jsx)(P,{to:`/`,children:e(`frontend.nav.settings`)}),(0,j.jsxs)(P,{to:`/sessions`,children:[e(`frontend.nav.devices`),l]}),a&&(0,j.jsx)(P,{to:`/plan`,children:e(`frontend.nav.plan`)})]})]})]}),(0,j.jsx)(E,{})]})}export{U as component};
//# sourceMappingURL=_account-ACKD_6C9.js.map