1import{aY as Q,bS as W,bU as G,ei as ee,cR as E,f9 as se,b5 as N,eo as z,by as te,c4 as ne,b4 as ie,eN as O,et as ae,eO as re,ef as oe,cJ as ce,eS as le,dm as V,eQ as de,eY as ue,dJ as ge,f2 as fe,eL as he,cm as B,bT as D,bY as pe,cw as me,f1 as Me,cp as o,cs as v,g as ve,L as Ee,az as xe,U as ye,T as _e,R as be,c8 as Ie,a8 as Ae,Z as we,_ as Ce,N as Se,b as Te,fv as Le,bQ as Pe,cF as C}from"./index.hjxr7fye.js";import{M as Ne}from"./MessageCard.cin9wmd8.js";import{u as Be,e as De,d as k}from"./queryFilters.gxn6c2f7.js";import"./location.hi7rq8h7.js";async function Fe(s){return Q.delete(W.chat(`/messages/${s}`)).then(G)}async function Re({id:s,text:e}){return Q.put(W.chat(`/messages/${s}`),{text:e}).then(G)}async function He(s){return Q.put(W.chat(`/messages/${s}/see`)).then(G)}function Ve(){return ee(({can:s},{findRule:e},t)=>{e("create","chat_channel")&&s("create","chat_channel"),e("view","chat_channel")&&s("view","chat_channel"),e("create","chat_message")&&s("create","chat_message"),e("view","chat_message")&&s("view","chat_message");const p=e("update","chat_message",{own:!0});e("update","chat_message",{own:!1})?s("update","chat_message"):p&&s("update","chat_message",{user_id:t==null?void 0:t.id});const f=e("delete","chat_message",{own:!0});e("delete","chat_message",{own:!1})?s("delete","chat_message"):f&&s("delete","chat_message",{user_id:t==null?void 0:t.id})})}function Qe(){const[s,e]=Be({page:k(1),per_page:k(18),text:De});let t;E.useEffect(()=>{s.page!==1&&e("page",1)},[s.text]);const c={value:s.text,onChange:u=>{clearTimeout(t),t=setTimeout(()=>{e("text",u.target.value)},800)}};return{filters:s,setFilters:e,fields:{search:c}}}function We({currentUserId:s,messagesList:e,interviewer:t,onSetMessagesList:c}){const u=N.PRIVATE_CHAT_MESSAGE_CREATED+s,x=N.PRIVATE_CHAT_MESSAGE_UPDATED+s,m=N.PRIVATE_CHAT_MESSAGE_DELETED+s,p=N.PRIVATE_CHAT_MESSAGE_VIEWED+s,{socket:n}=se(),f=i=>{var l;((l=i==null?void 0:i.message)==null?void 0:l.user_id)===(t==null?void 0:t.id)&&c([{...i.message,user:t,isVirtual:!0},...e])},M=i=>{if(i!=null&&i.message){const l=[...e],d=l.findIndex(h=>{var b;return h.id===((b=i==null?void 0:i.message)==null?void 0:b.id)});d>=0&&(l[d]={...i==null?void 0:i.message,user:t},c(l))}},y=i=>{if(i){const l=[...e],d=l.findIndex(h=>h.id===(i==null?void 0:i.message_id));d>=0&&(l.splice(d,1),c(l))}},_=i=>{if(i){const l=[...e],d=l.find(h=>h.id===(i==null?void 0:i.message_id));d&&!d.is_seen&&(d.is_seen=!0,c(l))}};E.useEffect(()=>(s&&(n!=null&&n.connected)&&(n.on(u,f),n.on(x,M),n.on(m,y),n.on(p,_)),()=>{n==null||n.off(u,f),n==null||n.off(x,M),n==null||n.off(m,y),n==null||n.off(p,_)}),[s,e])}const Ge=(s,e,t,c)=>{const u=z();return te({query:ne,getKey:()=>ie(t,s),queryParams:{id:t},queryOptions:{gcTime:0,meta:{onError(){u.error("Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ ÑообÑениÑ")}},...c}})(s,e)};function ke(){return O({mutationFn:Fe})}function ze(){return O({mutationFn:Re})}function Oe(){const s=ae(),e=re(),t=z(),c=oe(ce),u=le(),x=[{title:"ÐлавнаÑ",url:V.home.url()}],{title:m}=de("ÐиÑнÑе ÑообÑениÑ"),p=Ve(),n=ue(ge),f=u.channelId?parseInt(u.channelId):void 0,M=u.interviewerId?parseInt(u.interviewerId):void 0,{data:y,refetch:_,isRefetching:i}=fe(M,{enabled:!1}),[l,d]=E.useState(null),{mutate:h,isPending:b}=he(),{mutate:S,isPending:F}=ke(),{mutate:T,isPending:L}=ze(),{filters:a,setFilters:j,fields:q}=Qe(),{data:P,refetch:R,isLoading:U,isFetching:$,pagination:K}=Ge(a,g=>j("page",g),f),[I,H]=E.useState([]);E.useEffect(()=>{u.id&&parseInt(u.id)!==n&&e(V.error.url({code:403}))},[u.id,n]);const Y=g=>{l?(T({id:l,text:g},{onSuccess(){t.success("СообÑение ÑÑпеÑно оÑÑедакÑиÑовано",3e3),R()},onError(r){B(r)&&t.error(D(r,"Ðе ÑдалоÑÑ Ð¾ÑÑедакÑиÑоваÑÑ ÑообÑение"),5e3)}}),d(null)):h({id:f,text:g},{onSuccess(){t.success("СообÑение ÑÑпеÑно оÑпÑавлено",3e3),R(),e({search:me.stringify({page:1},{encode:!1})})},onError(r){B(r)&&t.error(D(r,"Ðе ÑдалоÑÑ Ð¾ÑпÑавиÑÑ ÑообÑение"),5e3)}})},J=g=>{c({header:"УдалиÑÑ ÑообÑение?"},()=>{S(g,{onSuccess(){var w;const r=[...I],A=r.findIndex(X=>X.id===g);(w=r==null?void 0:r[A])!=null&&w.isVirtual?(r.splice(A,1),H(r)):R(),t.success("СообÑение ÑÑпеÑно Ñдалено",3e3)},onError(r){B(r)&&t.error(D(r,"Ðе ÑдалоÑÑ ÑдалиÑÑ ÑообÑение"),5e3)}})})},Z=g=>{H(g)};return E.useEffect(()=>{_()},[M,_]),E.useEffect(()=>{if(I&&I.length){const g=I.map(r=>new Promise(A=>{n!==(r==null?void 0:r.user_id)&&!(r!=null&&r.is_seen)?He(r==null?void 0:r.id).catch(w=>{B(w)&&t.error(D(w,"Ðе ÑдалоÑÑ Ð¾ÑмеÑиÑÑ ÑообÑение как пÑоÑиÑанное"),5e3)}).finally(()=>{A(!0)}):A(!1)}));Promise.all(g).then(r=>{r.includes(!0)&&s(pe())})}},[I]),E.useEffect(()=>{P&&P.length&&H(P)},[P]),We({currentUserId:n,messagesList:I,interviewer:y,onSetMessagesList:Z}),{breadcrumbs:x,title:m,currentUserId:n,messagesList:I,messagesLoading:U||$,pagination:K,channelId:f,interviewer:y,isInterviewerLoading:i,onSubmit:Y,isAddMessageLoading:b,deleteMessage:J,isDeleteMessageLoading:F,editedId:l,setEditedId:d,isEditMessageLoading:L,ability:p,fields:q}}const Ye=()=>{var L;const s=Me(),e=je(s),{title:t,messagesList:c,messagesLoading:u,pagination:x,currentUserId:m,interviewer:p,isInterviewerLoading:n,channelId:f,onSubmit:M,isAddMessageLoading:y,deleteMessage:_,isDeleteMessageLoading:i,isEditMessageLoading:l,editedId:d,setEditedId:h,ability:b,fields:S,breadcrumbs:F}=Oe(),T=()=>{h(null)};return b.cannot("view","chat_message")?null:o(Te,{ability:b,children:o("div",{css:e.PrivateMessages,children:v(Se,{children:[o(ve,{list:F}),v("div",{css:e.header,children:[o(Ee,{align:"left",className:e.heading,children:o("h1",{children:t})}),o("div",{css:e.headerActions,children:o(xe,{search:!0,variant:"outline",className:e.search,children:o("input",{type:"text",placeholder:"ÐоиÑк по пеÑепиÑкеâ¦",defaultValue:S.search.value,onChange:S.search.onChange})})})]}),v("div",{css:e.main,children:[(u||n)&&o(ye,{position:"fixed",delay:500,opacity:.3,children:o(_e,{})}),f&&p&&o("div",{css:e.channelMessages,children:v("div",{css:e.messages,children:[v("div",{css:e.messagesHeader,children:[o("div",{children:v(be,{to:V.messages.url({id:m}),css:e.backLink,children:[o("img",{src:"/images/link-arrow.svg",alt:"â"}),"Ðазад"]})}),o("div",{css:e.userName,children:Ie(p)})]}),o("div",{css:e.messagesList,children:c.map(a=>a!=null&&a.user?o(Ne,{user:a==null?void 0:a.user,message:a,className:e.card,isOwn:(a==null?void 0:a.user_id
1)===m,onEdit:()=>h(a==null?void 0:a.id),onDelete:()=>_(a==null?void 0:a.id),disabled:i||!!d||l},a==null?void 0:a.id):null)}),o(Ae,{...x,className:e.pagination}),!(c!=null&&c.length)&&o("div",{css:e.empty,children:"ÐÐµÑ ÑообÑений"}),o(we,{I:"create",a:"chat_message",children:v("div",{css:e.inputForm,children:[!!d&&v("div",{css:e.label,children:["РедакÑиÑование ÑообÑениÑ"," ",o("button",{onClick:T,css:e.cancelBtn,children:o("img",{src:"/images/close.svg",alt:"ÐÑмениÑÑ ÑедакÑиÑование"})})]}),o(Ce,{onSubmit:a=>M(a),isLoading:y,focus:!!d,defaultValue:d?(L=c==null?void 0:c.find(a=>a.id===d))==null?void 0:L.text:"",onKeyDown:a=>{d&&a.key==="Escape"&&T()}})]})})]})})]})]})})})},je=s=>({PrivateMessages:{paddingBottom:100,[C]:{paddingBottom:40}},header:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",flexWrap:"wrap",marginBottom:15},heading:{marginBottom:15},headerActions:{display:"flex",alignItems:"flex-start",marginBottom:5,paddingTop:5,flexWrap:"wrap",[C]:{paddingTop:0}},main:{},channelMessages:{},channels:{},messages:{display:"flex",flexDirection:"column",background:s.pattern.main,padding:30,maxHeight:"calc(100vh - 255px)",[C]:{padding:15,maxHeight:"none"}},messagesHeader:{display:"grid",alignItems:"center",gridTemplateColumns:"75px 1fr 75px",borderBottom:`1px solid ${s.pattern.separator}`,paddingBottom:25,[C]:{gridTemplateColumns:"75px 1fr",paddingBottom:15}},messagesList:{position:"relative",overflow:"auto"},backLink:{textTransform:"uppercase",fontSize:"0.75rem",fontWeight:500,"& img":{marginRight:4,transform:"rotate(180deg)",filter:s.filter.optional}},userName:{textAlign:"center",fontSize:"1.25rem",fontWeight:700,...Le,[C]:{textAlign:"left",fontSize:"1.125rem"}},empty:{margin:"20px 0",...Pe(s)},inputForm:{marginTop:20},pagination:{justifyContent:"flex-end",margin:"20px 0 0"},card:{padding:"5px 15px 5px 0 !important",margin:"5px 0"},label:{color:s.pattern.subcategory,fontSize:"0.875rem",marginBottom:8},cancelBtn:{background:"none",border:0,cursor:"pointer"},search:{width:338,marginRight:10}});export{Ye as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.