import{b as k,G as F,c as E,j as e,a as o,F as P}from"./index-b983ad9b.js";import{r as a}from"./react-b0e0d18a.js";/* empty css                *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              */import{u as B}from"./Messenger-5d5560db.js";import{F as f,R as G,a as R,M,m as N,d as h,S as O,c as A,B as x,e as U,f as V,g as q,P as z}from"./antd-8ca2e36c.js";const C=new Map;class y{constructor(t){t&&this.setData(t)}setData(t){Object.assign(this,t)}static async findAll(t){const i=k(),{items:r}=await i.get({path:"api/v1/roles",query:{pp:-1,...t}});return(r||[]).map(m=>y.get(m))}static get(t){let i=C.get(t.id);return i||(i=new y(t),C.set(t.id,i)),i}}const H=y;class v{constructor(t){t&&this.setData(t)}setData(t){Object.assign(this,t)}async save(){await F().patch(`api/v1/notifier/${this.roleId}`,{mode:this.mode,tags:this.tags})}static async findByPk(t){const r=await F().get(`api/v1/notifier/${t}`);return r&&r.roleId?v.get(r):void 0}static get(t){return new v(t)}}const _=v,J="_page_c7w11_1",K="_section-title_c7w11_34",L="_section-content_c7w11_48",Q="_message-filter-radio_c7w11_54",c={page:J,sectionTitle:K,sectionContent:L,messageFilterRadio:Q};function me(){const[I,t]=a.useReducer(s=>!s,!1),[i,r]=a.useState(),[m]=f.useForm(),[g,D]=a.useState(),[u,w]=a.useState(),[b,S]=a.useState(),T=E(),{subscribe:j}=B(),n=a.useRef(!0);a.useEffect(()=>(n.current=!0,()=>{n.current=!1}),[]),a.useEffect(()=>{(async()=>{try{const s=await H.findAll({"platform-roles":1});n.current&&s&&r([...s.filter(p=>{var l;return(l=p.group_types)==null?void 0:l.includes("room")})])}catch{n.current&&r([])}})()},[I]),a.useEffect(()=>{if(!g){w(void 0),m.resetFields();return}(async()=>{try{const s=await _.findByPk(g.id);n.current&&w(s)}catch(s){n.current&&s.code===404&&w(new _({roleId:g.id,mode:"none"}))}finally{setTimeout(()=>{n.current&&m.resetFields()})}})()},[g,m]);async function $(){S(0),F().post("api/v1/notifier-sync").then(({jobId:p})=>{if(!n.current)return;const l=j(`progress:${p}`,d=>{d.total>0&&n.current&&(d.processed===d.total?(l(),S(void 0)):S(100*d.processed/d.total))})})}return e("div",{className:c.page,children:o(G,{children:[o(R,{span:6,className:"role-list",children:[e("div",{className:c.sectionTitle,children:"人员角色"}),e("div",{className:c.sectionContent,children:i&&(i.length>0?e(M,{onSelect:({key:s})=>{const p=Number(s),l=i.find(d=>d.id===p);l&&D(l)},items:i.map(s=>({key:s.id,label:s.name}))}):o("p",{style:{color:"gray",padding:"1em"},children:["无法找到适用于房间的用户角色",e("br",{}),"请联系管理员进行角色配置"]}))})]}),o(R,{span:12,children:[e("div",{className:c.sectionTitle,children:"事件通知设置"}),e("div",{className:c.sectionContent,style:{padding:12},children:e(f,{form:m,initialValues:u,onValuesChange:s=>{u.setData({...s}),T()},onFinish:async s=>{u.setData({...s});try{await u.save(),t(),N.success("保存成功",1)}catch{N.error("保存意外失败, 请稍后再试",1)}},children:u&&o(P,{children:[o(f.Item,{children:[e(f.Item,{name:"mode",noStyle:!0,children:o(h.Group,{children:[e(h,{className:c.messageFilterRadio,value:"none",children:"不接收任何事件通知"}),e(h,{className:c.messageFilterRadio,value:"any",children:"接收所有可能的事件通知"}),e(h,{className:c.messageFilterRadio,value:"tagged",children:"仅接收具有以下任一指定标签的事件通知"})]})}),u.mode==="tagged"&&e(f.Item,{name:"tags",noStyle:!0,children:e(O,{mode:"tags"})})]}),e(f.Item,{children:e(A,{children:e(x,{type:"primary",htmlType:"submit",icon:e(U,{}),children:"保存"})})})]})})})]}),e(R,{span:6,children:o("div",{style:{height:"100%",display:"flex",flexDirection:"column",padding:12},children:[e(V,{title:"耗时可能较长, 请谨慎运行!",children:e(x,{block:!0,icon:e(q,{}),onClick:()=>$(),children:"同步当前的事件订阅"})}),e("div",{style:{flex:1,display:"flex",justifyContent:"center",alignItems:"center"},children:b!==void 0&&e(z,{type:"circle",percent:b,format:s=>`${s==null?void 0:s.toFixed(0)}%`})})]})})]})})}export{me as default};
