import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{a as t,i as n,l as r,s as i,t as a}from"./graphql-w47gyQE9.js";import{n as o,t as s}from"./LoadingSpinner-0XRXvdGq.js";import{n as c,t as l}from"./jsx-runtime-BHz_hoGM.js";import{n as u}from"./not-found-i5RsCZif.js";import{t as d}from"./link-RG1Klsig.js";import{t as f}from"./useTranslation-CWZfA4RN.js";import{t as p}from"./Button-CfjN5AeH.js";import{n as m,t as h}from"./close-C3FZSJFY.js";import{t as g}from"./error-solid-Bab1gp9Y.js";import{t as _}from"./Avatar-V1mexNc2.js";import{i as v}from"./Heading-fQbpz6tX.js";import{$ as y,A as b,D as x,E as S,L as C,R as w,X as T,Z as E,b as D,y as O}from"./main-CqHK_FoX.js";import{t as k}from"./edit-peBclVB2.js";var A={navBar:`_nav-bar_16kbp_8`,navBarItems:`_nav-bar-items_16kbp_12`},j=l(),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)(d,{className:N.navItem,activeProps:{"aria-current":`page`},...e})}),F=e=>(0,j.jsx)(g,{className:N.navBarErrorIcon}),I=e(c(),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=n(`
  fragment UserGreeting_user on User {
    id
    matrix {
      mxid
      displayName
    }
  }
`),z=n(`
  fragment UserGreeting_siteConfig on SiteConfig {
    displayNameChangeAllowed
  }
`),B=n(`
  mutation SetDisplayName($userId: ID!, $displayName: String) {
    setDisplayName(input: { userId: $userId, displayName: $displayName }) {
      status
    }
  }
`),V=(0,I.forwardRef)(({label:e,...t},n)=>(0,j.jsx)(m,{label:e,children:(0,j.jsx)(T,{ref:n,type:`button`,size:`var(--cpd-space-6x)`,className:L.editButton,...t,children:(0,j.jsx)(k,{})})})),H=({user:e,siteConfig:n})=>{let i=(0,I.useRef)(null),c=t(R,e),{displayNameChangeAllowed:l}=t(z,n),u=r(),d=o({mutationFn:({userId:e,displayName:t})=>a({query:B,variables:{userId:e,displayName:t}}),onSuccess:e=>{u.invalidateQueries({queryKey:[`currentUserGreeting`]}),e.setDisplayName.status===`SET`&&g(!1)}}),[m,g]=(0,I.useState)(!1),{t:v}=f();return(0,j.jsxs)(`div`,{className:L.user,children:[(0,j.jsx)(_,{size:`var(--cpd-space-14x)`,id:c.matrix.mxid,name:c.matrix.displayName||c.matrix.mxid,className:L.avatar}),(0,j.jsx)(`div`,{className:L.meta,children:c.matrix.displayName?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(E,{size:`lg`,weight:`semibold`,children:c.matrix.displayName}),(0,j.jsx)(E,{size:`md`,className:L.mxid,children:c.matrix.mxid})]}):(0,j.jsx)(E,{size:`lg`,weight:`semibold`,children:c.matrix.mxid})}),l&&(0,j.jsxs)(O,{trigger:(0,j.jsx)(V,{label:v(`action.edit`)}),open:m,onOpenChange:e=>{i.current?.form?.reset(),g(e)},children:[(0,j.jsx)(D,{children:v(`frontend.account.edit_profile.title`)}),(0,j.jsx)(_,{size:`88px`,className:`self-center`,id:c.matrix.mxid,name:c.matrix.displayName||c.matrix.mxid}),(0,j.jsx)(w,{asChild:!0,children:(0,j.jsxs)(b.Root,{onSubmit:e=>{e.preventDefault();let t=e.currentTarget,n=new FormData(t).get(`displayname`)||null;d.mutate({displayName:n,userId:c.id})},children:[(0,j.jsxs)(`div`,{className:L.dialogForm,children:[(0,j.jsxs)(b.Field,{name:`displayname`,serverInvalid:d.data?.setDisplayName.status===`INVALID`,children:[(0,j.jsx)(b.Label,{children:v(`frontend.account.edit_profile.display_name_label`)}),(0,j.jsx)(b.ActionControl,{type:`text`,Icon:h,autoComplete:`name`,defaultValue:c.matrix.displayName||void 0,actionLabel:v(`action.clear`),ref:i,onActionClick:()=>{i.current&&(i.current.value=``,i.current.focus())}}),(0,j.jsx)(b.HelpMessage,{children:v(`frontend.account.edit_profile.display_name_help`)})]}),(0,j.jsxs)(b.Field,{name:`mxid`,children:[(0,j.jsx)(b.Label,{children:v(`frontend.account.edit_profile.username_label`)}),(0,j.jsx)(b.TextControl,{value:c.matrix.mxid,readOnly:!0})]})]}),(0,j.jsxs)(b.Submit,{disabled:d.isPending,children:[d.isPending&&(0,j.jsx)(s,{inline:!0}),v(`action.save`)]})]})}),(0,j.jsx)(C,{asChild:!0,children:(0,j.jsx)(p,{kind:`tertiary`,children:v(`action.cancel`)})})]})]})};function U(){let{t:e}=f(),t=i(S),n=t.data.viewer;if(n?.__typename!==`User`)throw u();let{siteConfig:r}=t.data,{planManagementIframeUri:a,sessionLimit:o}=r,s=null;return o&&n.unfilteredAppSessions.totalCount>=o.softLimit&&(s=(0,j.jsx)(m,{label:e(`frontend.nav.device_limit_error`),children:(0,j.jsx)(F,{})})),(0,j.jsxs)(x,{wide:!0,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,j.jsx)(v,{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:n,siteConfig:r}),(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`),s]}),a&&(0,j.jsx)(P,{to:`/plan`,children:e(`frontend.nav.plan`)})]})]})]}),(0,j.jsx)(y,{})]})}export{U as component};
//# sourceMappingURL=_account-C7JfQi8T.js.map