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

    siteConfig {
      ...UserGreeting_siteConfig
      planManagementIframeUri
    }
  }
`),pe=P({queryKey:["currentUserGreeting"],queryFn:({signal:a})=>I({query:xe,signal:a})});function Ie(){const{t:a}=N(),r=H(pe),t=r.data.viewer;if(t?.__typename!=="User")throw Q();const{siteConfig:s}=r.data,{planManagementIframeUri:d}=s;return e.jsxs(K,{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(x,{to:"/",children:a("frontend.nav.settings")}),e.jsx(x,{to:"/sessions",children:a("frontend.nav.devices")}),d&&e.jsx(x,{to:"/plan",children:a("frontend.nav.plan")})]})]})]}),e.jsx(V,{})]})}export{Ie as component};
//# sourceMappingURL=_account-BEbq55UG.js.map
