import{u as S}from"./useCommunityApiClient-CDo7XB-D.js";import{d as B,k as F,E as L,c as l,a as o,t as v,e as x,F as N,n as V,r,g as $,i as D,o as n}from"./index-BhMpD06x.js";const U={class:"h-full overflow-y-auto p-6"},q={class:"mb-4"},j={class:"mt-1 truncate text-sm text-slate-400"},z={key:0,class:"text-sm text-slate-400"},G={key:1,class:"text-sm text-rose-300"},H={key:2,class:"space-y-4 rounded-lg border border-slate-800 bg-slate-900/70 p-4"},J={key:0,class:"text-sm text-rose-300"},K={key:1,class:"text-sm text-amber-200"},O={key:2,class:"text-sm text-slate-400"},P={key:3,class:"space-y-2"},Q={class:"space-y-2"},T=["id","checked","disabled","onChange"],W=["for"],X={class:"block truncate text-sm text-slate-100"},Y={key:0,class:"text-xs text-slate-500"},Z={key:0,class:"text-sm text-slate-400"},ee={class:"flex items-center gap-2 border-t border-slate-800 pt-3"},te=["disabled"],se=["disabled"],oe=B({__name:"CommunitySettingsMemberRolesView",props:{communityId:{},userRef:{}},setup(R){const a=R,p=S(()=>a.communityId),h=D(),g=r(!1),y=r(null),b=r(!1),c=r(null),f=r([]),i=r(null),u=r([]),d=r(!1),m=r(null),C=$(()=>decodeURIComponent(a.userRef));async function w(){c.value=null;const e=await p.client().getDefaultCommunityRole(a.communityId);i.value=e.id;const t=await p.client().listCommunityRoles(a.communityId);f.value=[...t.roles].sort((s,_)=>s.name.localeCompare(_.name))}async function I(){c.value=null;const e=await p.client().getCommunityMemberRoles(a.communityId,a.userRef);u.value=e.roles.map(t=>t.id)}async function k(){g.value=!0,y.value=null,b.value=!0,c.value=null;try{await w(),await I()}catch(e){const t=e instanceof Error?e.message:"Failed to load";y.value=t,c.value=t,f.value=[],u.value=[]}finally{g.value=!1,b.value=!1}}function A(e,t){if(!(i.value&&e===i.value)){if(t){u.value.includes(e)||(u.value=[...u.value,e]);return}u.value=u.value.filter(s=>s!==e)}}function E(){h.push({name:"community-settings-members",params:{communityId:a.communityId}}),m.value=null,c.value=null}async function M(){if(!d.value){d.value=!0,m.value=null;try{const e=i.value?Array.from(new Set([...u.value,i.value])):[...u.value];await p.client().updateCommunityMemberRoles(a.communityId,a.userRef,e),h.push({name:"community-settings-members",params:{communityId:a.communityId}})}catch(e){m.value=e instanceof Error?e.message:"Failed to save roles"}finally{d.value=!1}}}return F(()=>[a.communityId,a.userRef],()=>{k()}),L(()=>{k()}),(e,t)=>(n(),l("section",U,[o("header",q,[t[1]||(t[1]=o("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"Community settings",-1)),t[2]||(t[2]=o("h1",{class:"mt-1 text-2xl font-semibold text-slate-100"},"Member roles",-1)),o("p",j,v(C.value),1)]),g.value?(n(),l("p",z,"Loading...")):y.value?(n(),l("p",G,v(y.value),1)):(n(),l("div",H,[m.value?(n(),l("p",J,v(m.value),1)):x("",!0),c.value?(n(),l("p",K,v(c.value),1)):x("",!0),b.value?(n(),l("p",O,"Loading roles…")):(n(),l("div",P,[t[3]||(t[3]=o("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"Assigned community roles",-1)),o("ul",Q,[(n(!0),l(N,null,V(f.value,s=>(n(),l("li",{key:s.id,class:"flex items-center gap-2 rounded border border-slate-800 px-2 py-2"},[o("input",{id:`cr-${s.id}`,type:"checkbox",class:"h-4 w-4 rounded border-slate-600 bg-slate-900",checked:u.value.includes(s.id),disabled:!!i.value&&s.id===i.value,onChange:_=>A(s.id,_.target.checked)},null,40,T),o("label",{for:`cr-${s.id}`,class:"min-w-0 flex-1 cursor-pointer"},[o("span",X,v(s.name),1),i.value&&s.id===i.value?(n(),l("span",Y," Required for all members ")):x("",!0)],8,W)]))),128)),f.value.length===0?(n(),l("li",Z,"No roles defined.")):x("",!0)])])),o("div",ee,[o("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:d.value||b.value,onClick:t[0]||(t[0]=s=>{M()})}," Save ",8,te),o("button",{type:"button",class:"cursor-pointer rounded-md border border-slate-700 px-3 py-2 text-sm text-slate-200 transition hover:bg-slate-800",disabled:d.value,onClick:E}," Back ",8,se)])]))]))}});export{oe as default};
//# sourceMappingURL=CommunitySettingsMemberRolesView-C07S-gv8.js.map
