import{t as e}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{a as t}from"./logger-m2skRwRe.js";import"./render-DhJOzvl-.js";import{t as n}from"./moment-_z2ecU4r.js";import{i as r,n as i,t as a}from"./spy-Qi5RtOg4.js";import{c as o}from"./api-C8igxqc9.js";import{c as s,o as c}from"./utils-B_MUq4Cg.js";import{t as l}from"./get-DkgjvOxb.js";import"./product-n8PIgGwR.js";import{i as u}from"./Table-BIvaHlVU.js";var d=e({name:`ShopeeSpyDashboard`,data(){return{listProductSpy:[]}},methods:{async fetchList(){this.listProductSpy=(await a.findMany({type:`product`})).map(e=>({...e,loading:!1}))},getSpyId(e){return this.listProductSpy.find(t=>t._id===e)},async onFetchProduct(e){let n=this.getSpyId(e._id);n.loading=!0;try{if(e.type===`product`){let t=await l(e.productId,e.shopId);t||=(await o(e.productUrl,2e3).catch(()=>{}),await l(e.productId,e.shopId)),t&&r(e,t)}}catch(e){t.error({msg:`SHOPEE_SPY_FETCH_ERROR`,error:e})}n.loading=!1},onRemoveProduct(e){this.$Modal.confirm({content:e.name,title:this.$t(`REMOVE_CONFIRM`),onOk:async()=>{this.$Message.success(this.$t(`REMOVE_SUCCESS`)),a.removeId(e._id),e.type===`product`&&(this.listProductSpy=this.listProductSpy.filter(t=>t._id!==e._id))}})}},created(){this.fetchList(),a.syncRemote(),i.syncRemote()},computed:{tableProductSpy(){return{columns:u.columns,data:this.listProductSpy.map(e=>({...e,productUrl:c(e.productId,e.shopId),shopUrl:s(e.shopId),showTime:n(new Date(e.time)),sale:e.sale,sold:e.sold,price:e.price,promotion:e.promotion}))}}}},function(){var e=this,t=e._self._c;return t(`div`,[t(`Table`,{ref:`TableProductList`,attrs:{columns:e.tableProductSpy.columns,data:e.tableProductSpy.data,"highlight-row":``,size:`small`,height:`800`,border:``},scopedSlots:e._u([{key:`name`,fn:function({row:n}){return[t(`a`,{attrs:{href:n.productUrl,target:`_blank`}},[e._v(e._s(e._f(`maxString`)(n.name,80)))])]}},{key:`shopName`,fn:function({row:n}){return[t(`a`,{attrs:{href:n.shopUrl,target:`_blank`}},[e._v(e._s(n.shopName))])]}},{key:`image`,fn:function({row:e}){return[t(`img`,{staticStyle:{width:`50px`},attrs:{src:e.image}})]}},{key:`action`,fn:function({row:n}){return[t(`Button`,{staticClass:`mr-5`,attrs:{type:`primary`,ghost:``,size:`small`,loading:n.loading},on:{click:function(t){return e.onFetchProduct(n)}}},[e._v(` `+e._s(e.$t(`FETCH_BTN`))+` `)]),t(`Button`,{attrs:{type:`error`,ghost:``,size:`small`,loading:n.loading},on:{click:function(t){return e.onRemoveProduct(n)}}},[e._v(` `+e._s(e.$t(`REMOVE_BTN`))+` `)])]}}])})],1)},[],!1,null,null,null,null).exports;export{d as default};