import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{t as n}from"./shopee-C_td5ZXe.js";import{t as r}from"./delay-CW5VuKve.js";import{t as i}from"./p-map-dazmT8sx.js";import{n as a}from"./chat-f-V4CIxG.js";import{i as o,n as s,r as c}from"./rating-BmJXiO1x.js";var l=e(r()),u=e(i()),d=t({name:`ShopeeAutoReplyReview`,data(){return{formData:{},queryRating:{star:[5],limit:20},replyRating:{text:this.$t(`SHOPEE_AUTO_REPLY_RATING_PARAM_TEXT`)},replyChat:{text:``},replyHandler:{loading:!1,log:[],sent:0,total:0,sleepPerList:5e3,sleepPerRating:500},matchText:{BUYER_NAME:this.$t(`SHOPEE_AUTO_REPLY_RATING_PARAM_BUYER_NAME`),ORDER_ID:this.$t(`SHOPEE_AUTO_REPLY_RATING_PARAM_ORDER_ID`),RATING_STAR:this.$t(`SHOPEE_AUTO_REPLY_RATING_PARAM_RATING_STAR`)}}},methods:{async getchMetaRating(){let e=await c(this.queryRating.star);this.replyHandler.total=e.to_reply_count},async handleReplyRating(){this.replyHandler.loading=!0,this.replyHandler.sent=0;let e=!0;for(;e;){let t=await s(this.queryRating.star,this.queryRating.limit);if(!(t&&t.length)||(await(0,u.default)(t,async t=>{if(!e)return!1;let{user_id:n,order_id:r,comment_id:i,rating_star:s,user_name:c,reply:u}=t;if(!(!u&&this.queryRating.star.includes(s)))return!1;let d=this.replyRating.text.replace(/BUYER_NAME/g,c).replace(/ORDER_ID/g,r).replace(/RATING_STAR/g,s),f={buyer:c,order_id:r,star:s,text:d,process_current:this.replyHandler.sent,process_total:this.replyHandler.total};if(await o(r,i,d).then(e=>{e.message===`success`?this.replyHandler.log.push(`✅ ${this.$t(`SHOPEE_AUTO_REPLY_RATING_SENT_SUCCESS`,f)}`):this.replyHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_REPLY_RATING_SENT_ERROR`,f)}`)}).catch(()=>{this.replyHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_REPLY_RATING_SENT_ERROR`,f)}`)}),this.replyChat.text){let e=n,t=n,i=this.replyChat.text.replace(/BUYER_NAME/g,c).replace(/ORDER_ID/g,r).replace(/RATING_STAR/g,s),o={buyer:c,text:i};a(e,t,i).then(()=>{this.replyHandler.log.push(`✅ ${this.$t(`SHOPEE_AUTO_CHAT_RATING_SENT_SUCCESS`,o)}`)}).catch(()=>{this.replyHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_CHAT_RATING_SENT_ERROR`,o)}`)})}if(this.replyHandler.log.push(`-------------`),this.replyHandler.sent+=1,this.replyHandler.sent>=this.autoRunLimit){let t=this.$t(`FEATURE_RUN_LIMIT_REACHED`,{sent:this.replyHandler.sent,limit:this.autoRunLimit});this.$Message.warning(t),this.replyHandler.log.push(t),e=!1}await(0,l.default)(this.replyHandler.sleepPerRating)},{concurrency:1}),!e))break;await(0,l.default)(this.replyHandler.sleepPerList)}this.replyHandler.loading=!1}},created(){this.getchMetaRating()},computed:{logText(){return this.replyHandler.log.join(`
`)},autoRunLimit(){let e=n.replyRating[this.getUserPlan];return e?e.runLimit:0},isRunLimitVisible(){return Number.isFinite(this.autoRunLimit)&&this.autoRunLimit>0},isRunLimitReached(){return this.isRunLimitVisible&&this.replyHandler.sent>=this.autoRunLimit}}},function(){var e=this,t=e._self._c;return t(`div`,{staticClass:`reply-container`},[t(`Row`,{attrs:{gutter:24}},[t(`Col`,{attrs:{span:16,offset:4}},[t(`Card`,{staticClass:`variables-card`,attrs:{bordered:!1}},[t(`div`,{staticClass:`card-title`,attrs:{slot:`title`},slot:`title`},[t(`Icon`,{attrs:{type:`ios-code`,size:`18`}}),t(`span`,{staticClass:`ml-2`},[e._v(e._s(e.$t(`SHOPEE_AUTO_REPLY_RATING_VARIABLES`)))])],1),t(`div`,{staticClass:`variables-grid`},e._l(e.matchText,function(n,r){return t(`div`,{key:r,staticClass:`variable-item`},[t(`Tag`,{staticClass:`variable-tag`,attrs:{color:`blue`}},[e._v(` `+e._s(r)+` `)]),t(`span`,{staticClass:`variable-description`},[e._v(e._s(n))])],1)}),0)]),t(`Card`,{staticClass:`config-card mt-4`,attrs:{bordered:!1}},[t(`div`,{staticClass:`card-title`,attrs:{slot:`title`},slot:`title`},[t(`Icon`,{attrs:{type:`ios-settings`,size:`18`}}),t(`span`,{staticClass:`ml-2`},[e._v(e._s(e.$t(`SHOPEE_AUTO_REPLY_RATING_CONFIG`)))])],1),e.isRunLimitVisible?t(`Alert`,{staticClass:`mb-3`,attrs:{type:`warning`,"show-icon":``}},[e._v(` `+e._s(e.$t(`FEATURE_RUN_LIMIT_INFO`,{limit:e.autoRunLimit}))+` `)]):e._e(),t(`Form`,{attrs:{model:e.formData,"label-width":120}},[t(`Row`,{attrs:{gutter:16}},[t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:e.$t(`SHOPEE_AUTO_REPLY_RATING_INPUT_CONTENT`)}},[t(`Input`,{staticClass:`form-textarea`,attrs:{type:`textarea`,rows:4,placeholder:e.$t(`SHOPEE_AUTO_REPLY_RATING_INPUT_CONTENT`)},model:{value:e.replyRating.text,callback:function(t){e.$set(e.replyRating,`text`,t)},expression:`replyRating.text`}})],1)],1),t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:e.$t(`SHOPEE_AUTO_REPLY_RATING_INPUT_CHAT`)}},[t(`Input`,{staticClass:`form-textarea`,attrs:{type:`textarea`,rows:4,placeholder:e.$t(`INPUT_PLACEHOLDER_EMPTY_WITHOUT_USE`)},model:{value:e.replyChat.text,callback:function(t){e.$set(e.replyChat,`text`,t)},expression:`replyChat.text`}})],1)],1)],1),t(`Row`,{attrs:{gutter:16}},[t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:e.$t(`SHOPEE_AUTO_REPLY_RATING_STAR_FILTER`)}},[t(`Select`,{staticStyle:{width:`100%`},attrs:{multiple:``,placeholder:e.$t(`SHOPEE_AUTO_REPLY_RATING_STAR_FILTER`)},on:{"on-change":e.getchMetaRating},model:{value:e.queryRating.star,callback:function(t){e.$set(e.queryRating,`star`,t)},expression:`queryRating.star`}},e._l([1,2,3,4,5],function(n){return t(`Option`,{key:n,attrs:{value:n}},[e._v(` `+e._s(e.$t(`RATING_STAR`,{star:n}))+` `)])}),1),t(`div`,{staticClass:`form-help-text`},[e._v(` `+e._s(e.$t(`SHOPEE_AUTO_REPLY_RATING_STAR_HELP`))+` `)])],1)],1),t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:` `}},[t(`Button`,{staticClass:`action-button`,attrs:{type:`primary`,size:`large`,loading:e.replyHandler.loading,disabled:!(e.replyRating.text&&e.queryRating.star.length)||e.isRunLimitReached},on:{click:e.handleReplyRating}},[t(`Icon`,{attrs:{type:`ios-play`,size:`16`}}),t(`span`,{staticClass:`ml-1`},[e._v(e._s(e.$t(`SHOPEE_AUTO_REPLY_RATING_BTN`)))])],1)],1)],1)],1)],1)],1),t(`Card`,{staticClass:`log-card mt-4`,attrs:{bordered:!1}},[t(`div`,{staticClass:`card-title`,attrs:{slot:`title`},slot:`title`},[t(`Icon`,{attrs:{type:`ios-list`,size:`18`}}),t(`span`,{staticClass:`ml-2`},[e._v(e._s(e.$t(`SHOPEE_AUTO_REPLY_RATING_LOG`)))]),t(`Badge`,{staticClass:`ml-2`,attrs:{count:e.replyHandler.sent,type:`primary`}}),t(`span`,{staticClass:`ml-2 text-muted`},[e._v(` / `+e._s(e._f(`addCommas`)(e.replyHandler.total))+` `)])],1),t(`div`,{staticClass:`log-container`},[t(`Input`,{staticClass:`log-textarea`,attrs:{value:e.logText,type:`textarea`,rows:15,readonly:``}})],1)])],1)],1)],1)},[],!1,null,`86a66f7c`,null,null).exports;export{d as default};