import{d as E,a4 as N,k as U,E as O,c,a as t,t as C,e as P,b as f,v as _,ab as h,z as S,g as V,r as a,a2 as B,a8 as F,aa as J,i as M,o as v}from"./index-D-NVZ_qd.js";import{_ as j}from"./UserSearchPicker.vue_vue_type_script_setup_true_lang-UaxgKsyZ.js";import{u as $}from"./useCommunityApiClient-CHQb6COB.js";const z={class:"h-full overflow-y-auto p-6"},L={key:0,class:"text-sm text-slate-400"},T={key:1,class:"text-sm text-rose-300"},G={key:2,class:"space-y-4 rounded-lg border border-slate-800 bg-slate-900/70 p-4"},H={key:0,class:"text-sm text-rose-300"},K={class:"block"},Q=["disabled"],W={class:"block"},X=["disabled"],Y={class:"flex cursor-pointer items-center gap-2"},Z=["disabled"],ee={class:"flex cursor-pointer items-center gap-2"},te=["disabled"],se={class:"block"},oe={class:"flex items-center gap-2 border-t border-slate-800 pt-3"},ae=["disabled"],re=E({__name:"CommunitySettingsCommunityView",props:{communityId:{}},setup(I){const i=I,g=J("shellReloadCommunities",void 0),p=$(()=>i.communityId),A=N(),D=M(),l=V(()=>A.canUpdateCommunity(i.communityId,p.serverDomain())),w=a(!1),b=a(null),r=a(!1),n=a(null),u=a(""),d=a(""),y=a(!1),x=a(!1),m=a(null),R=V(()=>[p.serverDomain()]);async function k(){w.value=!0,b.value=null;try{const s=await p.client().getCommunity(i.communityId);u.value=s.name,d.value=s.description??"",y.value=s.isPrivate,x.value=s.allowsJoinRequests,m.value=B(s.owner)}catch(s){b.value=s instanceof Error?s.message:"Failed to load community"}finally{w.value=!1}}async function q(){if(r.value||!l.value)return;if(!u.value.trim()){n.value="Name is required.";return}if(!m.value?.trim()){n.value="Owner is required.";return}let s;try{s=F(m.value.trim())}catch{n.value="Owner must be username@home_server.";return}r.value=!0,n.value=null;try{await p.client().updateCommunity(i.communityId,{name:u.value.trim(),description:d.value.trim()?d.value.trim():void 0,isPrivate:y.value,allowsJoinRequests:x.value,owner:s}),g&&await g(),D.push({name:"community-settings-community",params:{communityId:i.communityId}})}catch(e){n.value=e instanceof Error?e.message:"Failed to save community"}finally{r.value=!1}}return U(()=>i.communityId,()=>{k()}),O(()=>{k()}),(s,e)=>(v(),c("section",z,[e[11]||(e[11]=t("header",{class:"mb-4"},[t("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"Community settings"),t("h1",{class:"mt-1 text-2xl font-semibold text-slate-100"},"Community")],-1)),w.value?(v(),c("p",L,"Loading community...")):b.value?(v(),c("p",T,C(b.value),1)):(v(),c("div",G,[n.value?(v(),c("p",H,C(n.value),1)):P("",!0),t("label",K,[e[6]||(e[6]=t("span",{class:"mb-1 block text-xs uppercase tracking-wide text-slate-400"},"Name",-1)),f(t("input",{"onUpdate:modelValue":e[0]||(e[0]=o=>u.value=o),type:"text",class:"w-full rounded-md border border-slate-700 bg-slate-950 px-3 py-2 text-sm text-slate-100 outline-none focus:border-blue-400 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"Community name",disabled:!l.value},null,8,Q),[[_,u.value]])]),t("label",W,[e[7]||(e[7]=t("span",{class:"mb-1 block text-xs uppercase tracking-wide text-slate-400"},"Description",-1)),f(t("textarea",{"onUpdate:modelValue":e[1]||(e[1]=o=>d.value=o),rows:"3",class:"w-full rounded-md border border-slate-700 bg-slate-950 px-3 py-2 text-sm text-slate-100 outline-none focus:border-blue-400 disabled:cursor-not-allowed disabled:opacity-50",placeholder:"Optional description",disabled:!l.value},null,8,X),[[_,d.value]])]),t("label",Y,[f(t("input",{"onUpdate:modelValue":e[2]||(e[2]=o=>y.value=o),type:"checkbox",class:"h-4 w-4 rounded border-slate-700 bg-slate-900 text-blue-500",disabled:!l.value},null,8,Z),[[h,y.value]]),e[8]||(e[8]=t("span",{class:"text-sm text-slate-200"},"Private community",-1))]),t("label",ee,[f(t("input",{"onUpdate:modelValue":e[3]||(e[3]=o=>x.value=o),type:"checkbox",class:"h-4 w-4 rounded border-slate-700 bg-slate-900 text-blue-500",disabled:!l.value},null,8,te),[[h,x.value]]),e[9]||(e[9]=t("span",{class:"text-sm text-slate-200"},"Allow join requests",-1))]),t("div",se,[e[10]||(e[10]=t("span",{class:"mb-1 block text-xs uppercase tracking-wide text-slate-400"},"Owner",-1)),S(j,{modelValue:m.value,"onUpdate:modelValue":e[4]||(e[4]=o=>m.value=o),mode:"search","server-domains":R.value,disabled:r.value||!l.value},null,8,["modelValue","server-domains","disabled"])]),t("div",oe,[t("button",{type:"button",class:"cursor-pointer 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",disabled:r.value||!l.value,onClick:e[5]||(e[5]=o=>{q()})}," Save ",8,ae)])]))]))}});export{re as default};
//# sourceMappingURL=CommunitySettingsCommunityView-BHKsirLU.js.map
