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{n as u}from"./Match-Bi0Dx331.js";import{t as d}from"./link-C5HcoTdL.js";import{t as f}from"./useTranslation-CvpQbuHy.js";import{t as p}from"./Text-5cGdO1lY.js";import{t as m}from"./Button-BsQwiPxy.js";import{t as h}from"./IconButton-8-SP7uXc.js";import{n as g,t as _}from"./close-RlxFqidR.js";import{t as v}from"./error-solid-Bab1gp9Y.js";import{t as y}from"./Avatar-Ddktawb0.js";import{t as b}from"./Form-BGfdeQUz.js";import{i as x,n as S,r as C,t as w}from"./Dialog-BMazobwD.js";import{i as T}from"./Heading-BC6aWv8D.js";import"./LoadingSpinner-FeQKcGKO.js";import{t as E}from"./fragment-masking-DSZC2_uz.js";import{t as D}from"./Layout-CAUYrzwY.js";import{t as O}from"./_account-sZGcyNdx.js";import{t as k}from"./edit-peBclVB2.js";var A={navBar:`_nav-bar_16kbp_8`,navBarItems:`_nav-bar-items_16kbp_12`},j=c(),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)(v,{className:N.navBarErrorIcon}),I=e(s(),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)(g,{label:e,children:(0,j.jsx)(h,{ref:n,type:`button`,size:`var(--cpd-space-6x)`,className:L.editButton,...t,children:(0,j.jsx)(k,{})})})),H=({user:e,siteConfig:t})=>{let n=(0,I.useRef)(null),s=E(R,e),{displayNameChangeAllowed:c}=E(z,t),l=r(),u=a({mutationFn:({userId:e,displayName:t})=>i({query:B,variables:{userId:e,displayName:t}}),onSuccess:e=>{l.invalidateQueries({queryKey:[`currentUserGreeting`]}),e.setDisplayName.status===`SET`&&h(!1)}}),[d,h]=(0,I.useState)(!1),{t:g}=f();return(0,j.jsxs)(`div`,{className:L.user,children:[(0,j.jsx)(y,{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)(p,{size:`lg`,weight:`semibold`,children:s.matrix.displayName}),(0,j.jsx)(p,{size:`md`,className:L.mxid,children:s.matrix.mxid})]}):(0,j.jsx)(p,{size:`lg`,weight:`semibold`,children:s.matrix.mxid})}),c&&(0,j.jsxs)(w,{trigger:(0,j.jsx)(V,{label:g(`action.edit`)}),open:d,onOpenChange:e=>{n.current?.form?.reset(),h(e)},children:[(0,j.jsx)(S,{children:g(`frontend.account.edit_profile.title`)}),(0,j.jsx)(y,{size:`88px`,className:`self-center`,id:s.matrix.mxid,name:s.matrix.displayName||s.matrix.mxid}),(0,j.jsx)(x,{asChild:!0,children:(0,j.jsxs)(b.Root,{onSubmit:e=>{e.preventDefault();let t=e.currentTarget,n=new FormData(t).get(`displayname`)||null;u.mutate({displayName:n,userId:s.id})},children:[(0,j.jsxs)(`div`,{className:L.dialogForm,children:[(0,j.jsxs)(b.Field,{name:`displayname`,serverInvalid:u.data?.setDisplayName.status===`INVALID`,children:[(0,j.jsx)(b.Label,{children:g(`frontend.account.edit_profile.display_name_label`)}),(0,j.jsx)(b.ActionControl,{type:`text`,Icon:_,autoComplete:`name`,defaultValue:s.matrix.displayName||void 0,actionLabel:g(`action.clear`),ref:n,onActionClick:()=>{n.current&&(n.current.value=``,n.current.focus())}}),(0,j.jsx)(b.HelpMessage,{children:g(`frontend.account.edit_profile.display_name_help`)})]}),(0,j.jsxs)(b.Field,{name:`mxid`,children:[(0,j.jsx)(b.Label,{children:g(`frontend.account.edit_profile.username_label`)}),(0,j.jsx)(b.TextControl,{value:s.matrix.mxid,readOnly:!0})]})]}),(0,j.jsxs)(b.Submit,{disabled:u.isPending,children:[u.isPending&&(0,j.jsx)(o,{inline:!0}),g(`action.save`)]})]})}),(0,j.jsx)(C,{asChild:!0,children:(0,j.jsx)(m,{kind:`tertiary`,children:g(`action.cancel`)})})]})]})};function U(){let{t:e}=f(),n=t(O),r=n.data.viewer;if(r?.__typename!==`User`)throw l();let{siteConfig:i}=n.data,{planManagementIframeUri:a,sessionLimit:o}=i,s=null;return o&&r.unfilteredAppSessions.totalCount>=o.softLimit&&(s=(0,j.jsx)(g,{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)(T,{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`),s]}),a&&(0,j.jsx)(P,{to:`/plan`,children:e(`frontend.nav.plan`)})]})]})]}),(0,j.jsx)(u,{})]})}export{U as component};
//# sourceMappingURL=_account-B4QrnyU2.js.map