"use strict";(globalThis["webpackChunkkiarashFit"]=globalThis["webpackChunkkiarashFit"]||[]).push([[335],{4335:(e,s,t)=>{t.r(s),t.d(s,{default:()=>K});var a=t(1347),r=t(8633);const n={class:"q-px-md hide-scrollbar",style:{width:"100%",height:"calc(100% - 4em)","overflow-y":"scroll"}};function i(e,s,t,i,o,l){const c=(0,a.g2)("q-chat-message"),h=(0,a.g2)("q-btn"),g=(0,a.g2)("q-input"),d=(0,a.g2)("q-page");return(0,a.uX)(),(0,a.Wv)(d,{class:"",style:{position:"absolute",left:"0",right:"0",top:"0",bottom:"0"}},{default:(0,a.k6)((()=>[(0,a.Lk)("div",n,[((0,a.uX)(!0),(0,a.CE)(a.FK,null,(0,a.pI)(e.messages,((s,t)=>((0,a.uX)(),(0,a.Wv)(c,{name:s._sender==e.coachId?"مربی":"من",text:[s.message],sent:s._sender!=e.coachId,key:t},null,8,["name","text","sent"])))),128))]),(0,a.bF)(g,{type:"text",modelValue:e.messageText,"onUpdate:modelValue":s[0]||(s[0]=s=>e.messageText=s),outlined:"",dense:"",color:"white",class:"bg-secondary text-white",label:"متن پیام",style:{position:"absolute",bottom:"0",right:"0",left:"0"},onKeyup:(0,r.jR)(e.sendMessage,["enter"])},{append:(0,a.k6)((()=>[(0,a.bF)(h,{flat:"",icon:"send",color:"primary",onClick:e.sendMessage},null,8,["onClick"])])),_:1},8,["modelValue","onKeyup"])])),_:1})}var o=t(4393);const l=(0,o.s)(),c=1,h=(0,a.pM)({name:"DashPage",data(){return{messages:[],messageCounter:6,messageText:"",coachId:c,refreshTimer:null,interval:5}},mounted(){this.fetchMessages(),this.resetInterval()},unmounted(){clearInterval(this.refreshTimer)},methods:{resetInterval(){clearInterval(this.refreshTimer),this.refreshTimer=setInterval((()=>this.fetchMessages()),1e3*this.interval)},async fetchMessages(){const e=await l.fetch(c);console.log(e.slice(-1),this.messages.slice(-1),e.slice(-1).id==this.messages.slice(-1).id),this.messages.length>0&&e.slice(-1).id==this.messages.slice(-1).id?this.interval=Math.min(this.interval+1,30):this.interval=1,this.messages=e,console.log(this.interval),this.resetInterval()},async sendMessage(){const e={message:this.messageText,_receiver:c,createdOn:new Date,status:"sent"};this.interval=1,await l.addNew(e),this.messages.push(e),this.messageText=""}}});var g=t(2968),d=t(4001),m=t(6865),u=t(6739),p=t(2677),A=t(5305),v=t(5873),Q=t(3933),y=t(5389),f=t(3766),b=t(2589),k=t(4958),w=t(3961),I=t(6067),T=t(5460),x=t(9039),M=t(970),C=t(5797),F=t(7861),_=t(5013),q=t(1022),S=t(4028),L=t(272),z=t.n(L);const D=(0,g.A)(h,[["render",i]]),K=D;z()(h,"components",{QLayout:d.A,QHeader:m.A,QToolbar:u.A,QBtn:p.A,QAvatar:A.A,QSpace:v.A,QIcon:Q.A,QMenu:y.A,QList:f.A,QItem:b.A,QItemSection:k.A,QDrawer:w.A,QInput:I.A,QScrollArea:T.A,QItemLabel:x.A,QPageContainer:M.A,QFooter:C.A,QField:F.A,QPage:_.A,QChatMessage:q.A}),z()(h,"directives",{Ripple:S.A})},4393:(e,s,t)=>{t.d(s,{s:()=>o});var a=t(5679),r=t(6568),n=t(1400);const i=(0,n.Z)(),o=(0,a.nY)("messagesStore",{state:()=>({messages:[]}),getters:{},actions:{async fetchAll(){try{const e=await r.api.get("messages",{headers:{Authorization:i.getToken},params:{fields:{is_trashed:0}}});return console.log(e.data.data),this.messages=e.data.data,this.messages}catch(e){return console.error(e),null}},async fetch(e){try{const s=await r.api.get("messages",{headers:{Authorization:i.getToken},params:{otherSide:e}});return s.data.data}catch(e){return console.error(e),null}},async addNew(e){try{const s=await r.api.post("messages",e,{headers:{Authorization:i.getToken}});return s}catch(e){return console.error(e),null}}}})}}]);