import{n as e}from"./chunk-DrgAwqJ9.js";import{a as t,i as n,l as r,s as i,t as a}from"./graphql-BME5mLgf.js";import{n as o,t as s}from"./LoadingSpinner-BR8GsFxa.js";import{n as c,t as l}from"./jsx-runtime-C3uB2UIS.js";import"./useStore-BnK_t0Uy.js";import{n as u}from"./not-found-D2Q6nITs.js";import{t as d}from"./link-DiTuM_g9.js";import{t as f}from"./useTranslation-DVVidJl_.js";import{r as p,t as m}from"./Tooltip-Lf-InH2_.js";import{t as h}from"./IconButton-DsXdt-tQ.js";import{t as g}from"./Avatar-C4sVgCxb.js";import{i as _,n as v,r as y,t as b}from"./Dialog-B7h_fmap.js";import{i as x}from"./Heading-CuKRj857.js";import{a as S,n as C,o as w,s as T}from"./Message-C3OrPzh0.js";import{t as E}from"./Button-BZSwK8Kg.js";import{t as D}from"./Submit-CmO9RMCD.js";import{t as O}from"./Action-hqmLDXqy.js";import{t as k}from"./Text-S2uXnuWC.js";import{E as A,S as j,k as M,x as N}from"./main-BpPO1zAy.js";import{t as P}from"./edit-xsOZ1TPr.js";var F={navBar:`_nav-bar_16kbp_8`,navBarItems:`_nav-bar-items_16kbp_12`},I=l(),L=({children:e})=>(0,I.jsx)(`nav`,{className:F.navBar,children:(0,I.jsx)(`ul`,{className:F.navBarItems,children:e})}),R={navTab:`_nav-tab_9fhit_8`,navItem:`_nav-item_9fhit_26`,externalLink:`_external-link_9fhit_39`},z=e=>(0,I.jsx)(`li`,{className:R.navTab,children:(0,I.jsx)(d,{className:R.navItem,activeProps:{"aria-current":`page`},...e})}),B=e(c(),1),V={user:`_user_lnqhg_8`,meta:`_meta_lnqhg_19`,editButton:`_edit-button_lnqhg_32`,mxid:`_mxid_lnqhg_36`,dialogForm:`_dialog-form_lnqhg_40`},H=n(`
  fragment UserGreeting_user on User {
    id
    matrix {
      mxid
      displayName
    }
  }
`),U=n(`
  fragment UserGreeting_siteConfig on SiteConfig {
    displayNameChangeAllowed
  }
`),W=n(`
  mutation SetDisplayName($userId: ID!, $displayName: String) {
    setDisplayName(input: { userId: $userId, displayName: $displayName }) {
      status
    }
  }
`),G=(0,B.forwardRef)(({label:e,...t},n)=>(0,I.jsx)(m,{label:e,children:(0,I.jsx)(h,{ref:n,type:`button`,size:`var(--cpd-space-6x)`,className:V.editButton,...t,children:(0,I.jsx)(P,{})})})),K=({user:e,siteConfig:n})=>{let i=(0,B.useRef)(null),c=t(H,e),{displayNameChangeAllowed:l}=t(U,n),u=r(),d=o({mutationFn:({userId:e,displayName:t})=>a({query:W,variables:{userId:e,displayName:t}}),onSuccess:e=>{u.invalidateQueries({queryKey:[`currentUserGreeting`]}),e.setDisplayName.status===`SET`&&h(!1)}}),[m,h]=(0,B.useState)(!1),{t:x}=f();return(0,I.jsxs)(`div`,{className:V.user,children:[(0,I.jsx)(g,{size:`var(--cpd-space-14x)`,id:c.matrix.mxid,name:c.matrix.displayName||c.matrix.mxid,className:V.avatar}),(0,I.jsx)(`div`,{className:V.meta,children:c.matrix.displayName?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(A,{size:`lg`,weight:`semibold`,children:c.matrix.displayName}),(0,I.jsx)(A,{size:`md`,className:V.mxid,children:c.matrix.mxid})]}):(0,I.jsx)(A,{size:`lg`,weight:`semibold`,children:c.matrix.mxid})}),l&&(0,I.jsxs)(b,{trigger:(0,I.jsx)(G,{label:x(`action.edit`)}),open:m,onOpenChange:e=>{i.current?.form?.reset(),h(e)},children:[(0,I.jsx)(v,{children:x(`frontend.account.edit_profile.title`)}),(0,I.jsx)(g,{size:`88px`,className:`self-center`,id:c.matrix.mxid,name:c.matrix.displayName||c.matrix.mxid}),(0,I.jsx)(_,{asChild:!0,children:(0,I.jsxs)(S,{onSubmit:e=>{e.preventDefault();let t=e.currentTarget,n=new FormData(t).get(`displayname`)||null;d.mutate({displayName:n,userId:c.id})},children:[(0,I.jsxs)(`div`,{className:V.dialogForm,children:[(0,I.jsxs)(T,{name:`displayname`,serverInvalid:d.data?.setDisplayName.status===`INVALID`,children:[(0,I.jsx)(w,{children:x(`frontend.account.edit_profile.display_name_label`)}),(0,I.jsx)(O,{type:`text`,Icon:p,autoComplete:`name`,defaultValue:c.matrix.displayName||void 0,actionLabel:x(`action.clear`),ref:i,onActionClick:()=>{i.current&&(i.current.value=``,i.current.focus())}}),(0,I.jsx)(C,{children:x(`frontend.account.edit_profile.display_name_help`)})]}),(0,I.jsxs)(T,{name:`mxid`,children:[(0,I.jsx)(w,{children:x(`frontend.account.edit_profile.username_label`)}),(0,I.jsx)(k,{value:c.matrix.mxid,readOnly:!0})]})]}),(0,I.jsxs)(D,{disabled:d.isPending,children:[d.isPending&&(0,I.jsx)(s,{inline:!0}),x(`action.save`)]})]})}),(0,I.jsx)(y,{asChild:!0,children:(0,I.jsx)(E,{kind:`tertiary`,children:x(`action.cancel`)})})]})]})};function q(){let{t:e}=f(),t=i(N),n=t.data.viewer;if(n?.__typename!==`User`)throw u();let{siteConfig:r}=t.data,{planManagementIframeUri:a}=r;return(0,I.jsxs)(j,{wide:!0,children:[(0,I.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,I.jsx)(x,{size:`md`,weight:`semibold`,children:e(`frontend.account.title`)}),(0,I.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,I.jsx)(K,{user:n,siteConfig:r}),(0,I.jsxs)(L,{children:[(0,I.jsx)(z,{to:`/`,children:e(`frontend.nav.settings`)}),(0,I.jsx)(z,{to:`/sessions`,children:e(`frontend.nav.devices`)}),a&&(0,I.jsx)(z,{to:`/plan`,children:e(`frontend.nav.plan`)})]})]})]}),(0,I.jsx)(M,{})]})}export{q as component};
//# sourceMappingURL=_account-B7cZ8qcA.js.map