document.addEventListener("alpine:init",()=>{Alpine.data("contackMe",()=>({firstShow:!0,isShowInfo:!1,isSubmit:!1,tab:"newData",form:{username:"",wa:"",title:"",pesan:""},kodeBefore:"",dataBefore:null,nomorTicket:"",textMessage:"",init(){setTimeout(()=>{scrollInMenuHome()}),this.$watch("tab",e=>scrollInMenuHome()),this.$watch("dataBefore",e=>this.scrollButtonChat()),window.addEventListener("resize",e=>this.scrollButtonChat())},submitForm(){this.isSubmit||(this.isSubmit=!0,axios.post("/client/blog/contackMe/pesan",this.form).then(e=>{this.nomorTicket=e.data.ticket,this.isShowInfo=!0,this.form.username="",this.form.wa="",this.form.title="",this.form.pesan="",this.isSubmit=!1}).catch(e=>{this.isSubmit=!1,Toast(e.message)}))},cariTicket(){this.isSubmit||(this.isSubmit=!0,axios.patch("/client/blog/contackMe/pesan/",{ticket:this.kodeBefore}).then(e=>{let a=e.data;a.filterData=a.keluhan_message.map(t=>(t.dateFormat=moment(t.created_at).format("dddd, DD MMMM YYYY"),t.unix=moment(t.created_at).unix(),t.time=moment(t.created_at).format("HH:mm"),t)).sort((t,s)=>t.unix-s.unix).groupBy("dateFormat"),this.dataBefore=a,this.isSubmit=!1,scrollInMenuHome()}).catch(e=>{this.isSubmit=!1,Toast(e.message)}))},onKeyupTextAreaMessage(e){if(e.keyCode==13){var a=e.target.value,t=this.getCaret(e.target);e.shiftKey?(e.target.value=a.substring(0,t-1)+`
`+a.substring(t,a.length),e.stopPropagation()):(e.target.value=a.substring(0,t-1)+a.substring(t,a.length),this.sendMessage())}},getCaret(e){if(e.selectionStart)return e.selectionStart;if(document.selection){e.focus();var a=document.selection.createRange();if(a==null)return 0;var t=e.createTextRange(),s=t.duplicate();return t.moveToBookmark(a.getBookmark()),s.setEndPoint("EndToStart",t),s.text.length}return 0},scrollButtonChat(){this.$refs.containerChat&&this.$refs.containerChat.scrollTo({behavior:"smooth",top:this.$refs.containerChat.scrollHeight})},sendMessage(){if(this.textMessage.trim()){let e={ticketId:this.dataBefore.id,pesan:this.textMessage};this.textMessage="",axios.put("/client/blog/contackMe/pesan/",e).then(a=>{let t=a.data;t.dateFormat=moment(t.created_at).format("dddd, DD MMMM YYYY"),t.unix=moment(t.created_at).unix(),t.time=moment(t.created_at).format("HH:mm"),this.dataBefore.filterData[t.dateFormat]?this.dataBefore.filterData[t.dateFormat].push(t):this.dataBefore.filterData[t.dateFormat]=[t],this.scrollButtonChat()}).catch(a=>{Toast(a.message)})}}}))});