import{o as e}from"./chunk-mlkTr37E.js";import{t}from"./_plugin-vue2_normalizer-BHc2Ljhs.js";import{E as n}from"./api-UprNrhON.js";import{t as r}from"./iview-Ckd7L-Pt.js";import{a as i}from"./logger-m2skRwRe.js";import{a,i as o}from"./cookies-sMX4awhg.js";import"./render-DhJOzvl-.js";import{n as s,r as c,t as l}from"./shop-BtzLb4EE.js";import{i as u}from"./shop-DcNvy7H3.js";import{i as d}from"./seller-cERX_DxK.js";import{i as f}from"./utils-B_MUq4Cg.js";var p=e(n()),m=e(r()),h=t({name:`ShopInfo`,data(){return{msg:``,name:``,username:``,id:``,image:``,password:``,phone:``,email:``,spcf:``,cookie:``,edit:{spcf:!1,cookie:!1},listUrl:[],rootDomain:``,loading:!1}},methods:{async init(){this.listUrl=[this.configAppApi.shopee.home,this.configAppApi.shopee.seller],this.rootDomain=this.configAppApi.shopee.domain,this.spcf=await c(),this.cookie=JSON.stringify(await l());let e=await s();if(e&&e.shopid)return this.name=e.display_name,this.username=e.username,this.phone=e.phone,this.email=e.email,this.id=e.shopid,this.image=f(e.portrait),!0;let t=await d();this.name=t.shopName,this.username=t.username,this.id=t.shopId},async setCookie(e,t,n=0){await p.default.mapSeries(this.listUrl,async r=>{await o(e,r).catch(()=>{}),await a(e,t,r,this.rootDomain,n).catch(()=>{})})},async changeSpcf(){let e=this.spcf;e&&(await this.setCookie(`SPC_F`,e).catch(()=>{}),this.reloadTabCurrent(!0))},async changeCookie(){let e=this.cookie;if(e)try{let t=JSON.parse(e);await p.default.mapSeries(t,async({name:e,value:t,expirationDate:n})=>{e===`SPC_F`&&(this.spcf=t),await this.setCookie(e,t,n).catch(()=>{})}).catch(()=>{}),this.reloadTabCurrent(!0)}catch{}},async createShop(){this.$Modal.confirm({render:e=>e(m.Input,{props:{autofocus:!0,placeholder:this.$t(`ENTER_SHOP_PASSWORD`)},on:{input:e=>{this.password=e}}}),onOk:async()=>{this.loading=!0;try{let e=await u({account:this.username,password:this.password,cookies:JSON.parse(this.cookie),id:this.id,spcf:this.spcf});e.success?this.$Message.success(e.msg):this.$Message.error(e.msg)}catch(e){i.error({msg:`ERROR_CONNECT_SHOP`,error:e}),this.$Message.error(this.$t(`SHOP_CONNECT_ERROR`))}this.loading=!1}})}},created(){this.init()},computed:{isShopAuthed(){return!!this.id}}},function(){var e=this,t=e._self._c;return t(`div`,[t(`Form`,{attrs:{"label-position":`left`,"label-width":100}},[e.name?t(`FormItem`,{attrs:{label:e.$t(`SHOP_USERNAME`)}},[t(`Input`,{attrs:{readonly:``},model:{value:e.username,callback:function(t){e.username=t},expression:`username`}})],1):e._e(),t(`FormItem`,{attrs:{label:e.$t(`SHOP_SPCF`)}},[t(`Row`,[t(`Col`,{attrs:{span:20}},[t(`Input`,{attrs:{disabled:!e.edit.spcf},on:{"on-change":e.changeSpcf},model:{value:e.spcf,callback:function(t){e.spcf=t},expression:`spcf`}})],1),t(`Col`,{staticStyle:{"padding-left":`5px`},attrs:{span:4}},[t(`Checkbox`,{attrs:{size:`default`},model:{value:e.edit.spcf,callback:function(t){e.$set(e.edit,`spcf`,t)},expression:`edit.spcf`}},[e._v(` `+e._s(e.$t(`CHANGE_BTN`))+` `)])],1)],1)],1),t(`FormItem`,{attrs:{label:e.$t(`SHOP_COOKIES`)}},[t(`Row`,[t(`Col`,{attrs:{span:20}},[t(`Input`,{attrs:{disabled:!e.edit.cookie},on:{"on-change":e.changeCookie},model:{value:e.cookie,callback:function(t){e.cookie=t},expression:`cookie`}})],1),t(`Col`,{staticStyle:{"padding-left":`5px`},attrs:{span:4}},[t(`Checkbox`,{attrs:{size:`default`},model:{value:e.edit.cookie,callback:function(t){e.$set(e.edit,`cookie`,t)},expression:`edit.cookie`}},[e._v(` `+e._s(e.$t(`CHANGE_BTN`))+` `)])],1)],1)],1),e.isShopAuthed?t(`FormItem`,{attrs:{label:e.$t(`SHOP_PHONE_NUMBER`)}},[t(`Input`,{attrs:{readonly:``},model:{value:e.phone,callback:function(t){e.phone=t},expression:`phone`}})],1):e._e(),e.isShopAuthed?t(`FormItem`,{attrs:{label:e.$t(`SHOP_EMAIL`)}},[t(`Input`,{attrs:{readonly:``},model:{value:e.email,callback:function(t){e.email=t},expression:`email`}})],1):e._e(),e.isShopAuthed?t(`FormItem`,{attrs:{label:e.$t(`SHOP_ID`)}},[t(`Input`,{attrs:{readonly:``},model:{value:e.id,callback:function(t){e.id=t},expression:`id`}})],1):e._e()],1),e.isShopAuthed?t(`div`,{staticClass:`text-right mt-10`},[t(`span`,{staticStyle:{float:`left`}},[e._v(e._s(e.msg))]),e.getIsAuthed?t(`Button`,{attrs:{size:`default`,type:`success`,loading:e.loading,disabled:e.loading},on:{click:e.createShop}},[e._v(` `+e._s(e.$t(`SYNC_SHOP_TO_CLOUD`))+` `)]):e._e()],1):e._e()],1)},[],!1,null,null,null,null).exports;export{h as t};