import{d as S,S as D,J as V,c as a,a as t,t as d,e as b,b as I,v as N,r as o,ac as j,g as B,o as r}from"./index-zfm-9r65.js";import{p as F}from"./avatar-image-DReUi3fE.js";const M={class:"h-full overflow-y-auto p-6"},R={key:0,class:"text-sm text-slate-400"},J={key:1,class:"text-sm text-rose-300"},O={key:2,class:"space-y-4 rounded-lg border border-slate-800 bg-slate-900/70 p-4"},T={key:0,class:"text-sm text-rose-300"},$={key:1,class:"text-sm text-emerald-300"},z={class:"flex items-start gap-4"},H={class:"shrink-0"},L={class:"flex h-20 w-20 items-center justify-center overflow-hidden rounded-full border border-slate-700 bg-slate-950 text-slate-500"},X=["src"],q={key:1,class:"text-xs"},G={class:"min-w-0 flex-1 space-y-2"},K=["disabled"],Q={key:0,class:"text-sm text-slate-400"},W={key:1,class:"text-sm text-rose-300"},Y={class:"block"},Z={class:"mt-1 block text-right text-xs text-slate-500"},ee=["disabled"],g=512,ae=S({__name:"UserSettingsProfileView",setup(te){const h=D(),w=j("refreshCurrentUser",void 0),y=o(!0),f=o(null),n=o(""),p=o(null),s=o(null),i=o(null),_=o(!1),v=o(null),x=o(null),c=o(null),m=o(!1),C=B(()=>s.value!==null);async function A(){y.value=!0,f.value=null;try{const l=await h.client.getCurrentUserProfile();n.value=l.description,p.value=l.avatar??null,s.value=null,c.value=null,i.value&&(i.value.value="")}catch(l){f.value=l instanceof Error?l.message:"Failed to load profile"}finally{y.value=!1}}async function P(l){c.value=null;const e=l.target,u=e.files?.[0];if(!u){s.value=null;return}m.value=!0;try{s.value=await F(u)}catch(k){c.value=k instanceof Error?k.message:"Could not process the image file.",s.value=null,e.value=""}finally{m.value=!1}}function U(){s.value=null,c.value=null,i.value&&(i.value.value="")}async function E(){if(v.value=null,x.value=null,n.value.length>g){v.value=`Description must be at most ${g} characters.`;return}_.value=!0;try{const l=C.value?{description:n.value,avatar:s.value}:{description:n.value},e=await h.client.updateCurrentUserProfile(l);n.value=e.description,p.value=e.avatar??null,s.value=null,i.value&&(i.value.value=""),x.value="Profile saved.",await w?.()}catch(l){v.value=l instanceof Error?l.message:"Failed to save profile"}finally{_.value=!1}}return V(()=>{A()}),(l,e)=>(r(),a("section",M,[e[5]||(e[5]=t("header",{class:"mb-4"},[t("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"User settings"),t("h1",{class:"mt-1 text-2xl font-semibold text-slate-100"},"Profile")],-1)),y.value?(r(),a("p",R,"Loading profile...")):f.value?(r(),a("p",J,d(f.value),1)):(r(),a("div",O,[v.value?(r(),a("p",T,d(v.value),1)):b("",!0),x.value?(r(),a("p",$,d(x.value),1)):b("",!0),t("div",z,[t("div",H,[e[3]||(e[3]=t("p",{class:"mb-2 text-xs uppercase tracking-wide text-slate-400"},"Avatar",-1)),t("div",L,[s.value||p.value?(r(),a("img",{key:0,src:s.value??p.value??void 0,alt:"",class:"h-full w-full object-cover"},null,8,X)):(r(),a("span",q,"None"))])]),t("div",G,[t("input",{ref_key:"fileInputRef",ref:i,type:"file",accept:"image/*",class:"block w-full text-sm text-slate-300 file:mr-3 file:cursor-pointer file:rounded-md file:border file:border-slate-600 file:bg-slate-800 file:px-3 file:py-1.5 file:text-sm file:text-slate-200",disabled:m.value,onChange:e[0]||(e[0]=u=>{P(u)})},null,40,K),m.value?(r(),a("p",Q,"Processing image...")):c.value?(r(),a("p",W,d(c.value),1)):b("",!0),s.value?(r(),a("button",{key:2,type:"button",class:"text-sm text-slate-400 underline decoration-slate-600 hover:text-slate-200 cursor-pointer",onClick:U}," Discard new image ")):b("",!0)])]),t("label",Y,[e[4]||(e[4]=t("span",{class:"mb-1 block text-xs uppercase tracking-wide text-slate-400"},"About you",-1)),I(t("textarea",{"onUpdate:modelValue":e[1]||(e[1]=u=>n.value=u),rows:"5",maxlength:g,class:"w-full resize-y rounded-md border border-slate-700 bg-slate-950 px-3 py-2 text-sm text-slate-100 outline-none focus:border-blue-400",placeholder:"Visible to others in member lists and elsewhere."},null,512),[[N,n.value]]),t("span",Z,d(n.value.length)+" / "+d(g),1)]),t("button",{type:"button",class:"rounded-md border border-blue-400/50 bg-blue-500/20 px-3 py-2 text-sm text-blue-100 transition hover:bg-blue-500/30 disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",disabled:_.value,onClick:e[2]||(e[2]=u=>{E()})}," Save profile ",8,ee)]))]))}});export{ae as default};
//# sourceMappingURL=UserSettingsProfileView-CbbA-WCC.js.map
