import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{t as n}from"./lodash-DulIlzb9.js";import{t as r}from"./shopee-C_td5ZXe.js";import{t as i}from"./delay-CW5VuKve.js";import{t as a}from"./init-BAEIYk91.js";import{t as o}from"./p-map-dazmT8sx.js";import{n as s}from"./chat-f-V4CIxG.js";var c=e(n()),l=e(i()),u=e(o()),d=(e=[])=>{let t=[];for(let n=0;n<e.length;n+=5)t.push(e.slice(n,n+5));return t},f=async(e=40,t=1,n=``,r=0)=>{let i={listIndex:[],totalOrder:0,previousSentinel:``,nextsentinel:``,isError:!1},o={order_list_tab:r,entity_type:1,pagination:{from_page_number:1,page_number:t,page_size:e,page_sentinel:``},filter:{fulfillment_type:0,is_drop_off:0,fulfillment_source:0,action_filter:0}};t>1&&(o.pagination.from_page_number=t-1),n&&(o.pagination.page_sentinel=n);try{let e=await a.post(`/api/v3/order/search_order_list_index`,o);i.listIndex=e.data.index_list,i.totalOrder=e.data.pagination.total,i.nextsentinel=e.data.pagination.previous_page_sentinel,i.previousSentinel=e.data.pagination.next_page_sentinel}catch{i.isError=!0}return i},p=async(e=[],t=0)=>{if(!(e&&e.length&&t))return[];let n={order_list_tab:t,need_count_down_desc:!1,order_param_list:e};try{return(await a.post(`/api/v3/order/get_order_list_card_list`,n)).data.card_list.map(e=>e.order_card)}catch{return[]}},m=async(e=40,t=1,n=``)=>{let r=[],i=await f(e,t,n,500);return!i.isError&&i.listIndex&&i.listIndex.length&&await(0,u.default)(d(i.listIndex),async e=>{let t=await p(e,500);r.push(...t)}),{listOrder:r,...i}},h=async(e,t,n=5)=>{let r={order_id:e,rate_star:n,rate_comment:t};return a.post(`/api/v3/order/rate_order/`,r)},g=t({name:`ShopeeAutoReplyReview`,data(){return{formData:{},ratingOrder:{text:this.$t(`SHOPEE_AUTO_RATING_ORDER_PARAM_TEXT`),star:5},chatOrder:{text:``},ratingHandler:{loading:!1,log:[],sent:0,sleepPerList:15e3,sleepPerRating:200},queryOrder:{limit:40,page:1,setensel:``,total:0,isStopped:!1,isError:!1}}},methods:{async fetchMeta(){let e=await f(1,0,``,500);this.queryOrder.total=e.totalOrder},async handlerRatingOrder(){this.ratingHandler.loading=!0,this.ratingHandler.sent=0,this.queryOrder.setensel=``,this.queryOrder.page=Number(this.queryOrder.page)||1;let e=!0;for(let t=this.queryOrder.page;t<1e3;t++){let{limit:t,page:n,setensel:r}=this.queryOrder,i=await m(t,n,r);if(i.isError&&(this.queryOrder.isError=!0),!i.listOrder.length){this.queryOrder.isStopped=!0,this.ratingHandler.log.push(this.$t(`SHOPEE_AUTO_RATING_ORDER_EMPTY`,{page:n}));break}i.nextsentinel&&(this.queryOrder.setensel=i.nextsentinel),i.totalOrder&&(this.queryOrder.total=i.totalOrder),this.queryOrder.page++;let a=i.listOrder.filter(e=>e.order_ext_info.is_order_ratable);if(a.length?await(0,u.default)(a,async t=>{if(!e)return!1;let{text:r,star:i}=this.ratingOrder,a=t.order_ext_info.order_id,o=t.order_ext_info.buyer_user_id,c={order_id:a,buyer:t.card_header.buyer_info.username,text:r,star:i,page:n};if(await h(a,r,i).then(()=>{this.ratingHandler.log.push(`✅ ${this.$t(`SHOPEE_AUTO_RATING_ORDER_SENT_SUCCESS`,c)}`)}).catch(()=>{this.ratingHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_RATING_ORDER_SENT_ERROR`,c)}`)}),this.chatOrder.text){let e=o,t=o,n=this.chatOrder.text,r={text:n};s(e,t,n).then(()=>{this.replyHandler.log.push(`✅ ${this.$t(`SHOPEE_AUTO_CHAT_ORDER_SENT_SUCCESS`,r)}`)}).catch(()=>{this.replyHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_CHAT_ORDER_SENT_ERROR`,r)}`)})}if(this.ratingHandler.log.push(`-------------`),this.ratingHandler.sent+=1,this.ratingHandler.sent>=this.autoRunLimit){let t=this.$t(`FEATURE_RUN_LIMIT_REACHED`,{sent:this.ratingHandler.sent,limit:this.autoRunLimit});this.$Message.warning(t),this.ratingHandler.log.push(t),e=!1}await(0,l.default)(this.ratingHandler.sleepPerRating)},{concurrency:1}):this.ratingHandler.log.push(this.$t(`SHOPEE_AUTO_RATING_ORDER_EMPTY`,{page:n})),!e)break;this.ratingHandler.log.push(this.$t(`SLEEP_TINE`,{wait:`${this.ratingHandler.sleepPerList/1e3}s`})),await(0,l.default)(this.ratingHandler.sleepPerList)}this.ratingHandler.loading=!1}},created(){this.fetchMeta()},computed:{logText(){return this.ratingHandler.log.join(`
`)},maxPage(){return this.queryOrder.total?c.default.round(this.queryOrder.total/this.queryOrder.limit,0):0},autoRunLimit(){let e=r.ratingOrder[this.getUserPlan];return e?e.runLimit:0},isRunLimitVisible(){return Number.isFinite(this.autoRunLimit)&&this.autoRunLimit>0},isRunLimitReached(){return this.isRunLimitVisible&&this.ratingHandler.sent>=this.autoRunLimit}}},function(){var e=this,t=e._self._c;return t(`div`,{staticClass:`rating-container`},[t(`Row`,{attrs:{gutter:24}},[t(`Col`,{attrs:{span:16,offset:4}},[t(`Card`,{staticClass:`config-card`,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_RATING_ORDER_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_RATING_ORDER_INPUT_CONTENT`)}},[t(`Input`,{staticClass:`form-textarea`,attrs:{type:`textarea`,rows:4,placeholder:e.$t(`SHOPEE_AUTO_RATING_ORDER_INPUT_CONTENT`)},model:{value:e.ratingOrder.text,callback:function(t){e.$set(e.ratingOrder,`text`,t)},expression:`ratingOrder.text`}})],1)],1),t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:e.$t(`SHOPEE_AUTO_RATING_ORDER_INPUT_CHAT`)}},[t(`Input`,{staticClass:`form-textarea`,attrs:{type:`textarea`,rows:4,placeholder:e.$t(`INPUT_PLACEHOLDER_EMPTY_WITHOUT_USE`)},model:{value:e.chatOrder.text,callback:function(t){e.$set(e.chatOrder,`text`,t)},expression:`chatOrder.text`}})],1)],1)],1),t(`Row`,{attrs:{gutter:16}},[t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:e.$t(`ORDER_PAGE_START`)}},[t(`InputNumber`,{staticStyle:{width:`100%`},attrs:{min:1,max:e.maxPage,disabled:e.ratingHandler.loading,placeholder:e.$t(`ORDER_PAGE_START`)},model:{value:e.queryOrder.page,callback:function(t){e.$set(e.queryOrder,`page`,t)},expression:`queryOrder.page`}}),t(`div`,{staticClass:`form-help-text`},[e._v(` `+e._s(e.$t(`MAX_PAGE`,{page:e.maxPage}))+` `)])],1)],1),t(`Col`,{attrs:{span:12}},[t(`FormItem`,{attrs:{label:` `}},[t(`Button`,{staticClass:`action-button`,attrs:{type:`primary`,size:`large`,loading:e.ratingHandler.loading,disabled:!e.ratingOrder.text||e.isRunLimitReached},on:{click:e.handlerRatingOrder}},[t(`Icon`,{attrs:{type:`ios-play`,size:`16`}}),t(`span`,{staticClass:`ml-1`},[e._v(e._s(e.$t(`SHOPEE_AUTO_RATING_ORDER_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_RATING_ORDER_LOG`)))]),t(`Badge`,{staticClass:`ml-2`,attrs:{count:e.ratingHandler.sent,type:`primary`}})],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,`fbc22056`,null,null).exports;export{g as default};