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"./delay-DkB8DMH7.js";import{t as i}from"./init-QitreBcL.js";import{t as a}from"./p-map-DPdBLmfu.js";import{n as o}from"./chat-Br3Z53i5.js";var s=e(n()),c=e(r()),l=e(a()),u=(e=[])=>{let t=[];for(let n=0;n<e.length;n+=5)t.push(e.slice(n,n+5));return t},d=async(e=40,t=1,n=``,r=0)=>{let a={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 i.post(`/api/v3/order/search_order_list_index`,o);a.listIndex=e.data.index_list,a.totalOrder=e.data.pagination.total,a.nextsentinel=e.data.pagination.previous_page_sentinel,a.previousSentinel=e.data.pagination.next_page_sentinel}catch{a.isError=!0}return a},f=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 i.post(`/api/v3/order/get_order_list_card_list`,n)).data.card_list.map(e=>e.order_card)}catch{return[]}},p=async(e=40,t=1,n=``)=>{let r=[],i=await d(e,t,n,500);return!i.isError&&i.listIndex&&i.listIndex.length&&await(0,l.default)(u(i.listIndex),async e=>{let t=await f(e,500);r.push(...t)}),{listOrder:r,...i}},m=async(e,t,n=5)=>{let r={order_id:e,rate_star:n,rate_comment:t};return i.post(`/api/v3/order/rate_order/`,r)},h=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 d(1,0,``,500);this.queryOrder.total=e.totalOrder},async handlerRatingOrder(){this.ratingHandler.loading=!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 p(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,l.default)(a,async t=>{if(!e)return!1;let{text:r,star:i}=this.ratingOrder,a=t.order_ext_info.order_id,s=t.order_ext_info.buyer_user_id,l={order_id:a,buyer:t.card_header.buyer_info.username,text:r,star:i,page:n};if(await m(a,r,i).then(()=>{this.ratingHandler.log.push(`✅ ${this.$t(`SHOPEE_AUTO_RATING_ORDER_SENT_SUCCESS`,l)}`)}).catch(()=>{this.ratingHandler.log.push(`❌ ${this.$t(`SHOPEE_AUTO_RATING_ORDER_SENT_ERROR`,l)}`)}),this.chatOrder.text){let e=s,t=s,n=this.chatOrder.text,r={text:n};o(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)}`)})}this.ratingHandler.log.push(`-------------`),this.getIsVipPlus||(this.$Message.warning(this.$t(`FEAUTRE_STOP_VIP_PLUS`)),this.ratingHandler.log.push(this.$t(`FEAUTRE_STOP_VIP_PLUS`)),e=!1),this.ratingHandler.sent+=1,await(0,c.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,c.default)(this.ratingHandler.sleepPerList)}e&&(this.ratingHandler.loading=!1)}},created(){this.fetchMeta()},computed:{logText(){return this.ratingHandler.log.join(`
`)},maxPage(){return this.queryOrder.total?s.default.round(this.queryOrder.total/this.queryOrder.limit,0):0}}},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),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},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,`49fe10c1`,null,null).exports;export{h as default};