"use strict";const c=require("./props.js"),g=require("../../libs/mixin/mpMixin.js"),f=require("../../libs/mixin/mixin.js"),b=require("../../libs/config/props.js"),d=require("../../libs/function/index.js"),i=require("../../../../common/vendor.js"),_={name:"u-tabs",mixins:[g.mpMixin,f.mixin,c.props],data(){return{firstTime:!0,scrollLeft:0,scrollViewWidth:0,lineOffsetLeft:0,tabsRect:{left:0},innerCurrent:0,moving:!1}},watch:{current:{immediate:!0,handler(e,s){e!==this.innerCurrent&&(typeof e=="string"?this.innerCurrent=parseInt(e):this.innerCurrent=e,this.$nextTick(()=>{this.resize()}))}},list(){this.$nextTick(()=>{this.resize()})}},computed:{textStyle(){return e=>{const s={},n=e==this.innerCurrent?d.addStyle(this.activeStyle):d.addStyle(this.inactiveStyle);return this.list[e].disabled&&(s.color="#c8c9cc"),d.deepMerge(n,s)}},propsBadge(){return b.defProps.badge}},async mounted(){this.init()},emits:["click","longPress","change","update:current"],methods:{addStyle:d.addStyle,addUnit:d.addUnit,setLineLeft(){const e=this.list[this.innerCurrent];if(!e)return;let s=this.list.slice(0,this.innerCurrent).reduce((l,o)=>l+o.rect.width,0);const n=d.getPx(this.lineWidth);this.lineOffsetLeft=s+(e.rect.width-n)/2,this.firstTime&&setTimeout(()=>{this.firstTime=!1},10)},animation(e,s=0){},clickHandler(e,s){this.$emit("click",{...e,index:s},s),!e.disabled&&(this.innerCurrent=s,this.resize(),this.$emit("update:current",s),this.$emit("change",{...e,index:s},s))},longPressHandler(e,s){this.$emit("longPress",{...e,index:s})},init(){d.sleep().then(()=>{this.resize()})},setScrollLeft(){this.innerCurrent<0&&(this.innerCurrent=0);const e=this.list[this.innerCurrent],s=this.list.slice(0,this.innerCurrent).reduce((o,r)=>o+r.rect.width,0),n=d.sys().windowWidth;let l=s-(this.tabsRect.width-e.rect.width)/2-(n-this.tabsRect.right)/2+this.tabsRect.left/2;l=Math.min(l,this.scrollViewWidth-this.tabsRect.width),this.scrollLeft=Math.max(0,l)},resize(){this.list.length!==0&&Promise.all([this.getTabsRect(),this.getAllItemRect()]).then(([e,s=[]])=>{e.left>e.width&&(e.right=e.right-Math.floor(e.left/e.width)*e.width,e.left=e.left%e.width),this.tabsRect=e,this.scrollViewWidth=0,s.map((n,l)=>{this.scrollViewWidth+=n.width,this.list[l].rect=n}),this.setLineLeft(),this.setScrollLeft()})},getTabsRect(){return new Promise(e=>{this.queryRect("u-tabs__wrapper__scroll-view").then(s=>e(s))})},getAllItemRect(){return new Promise(e=>{const s=this.list.map((n,l)=>this.queryRect(`u-tabs__wrapper__nav__item-${l}`,!0));Promise.all(s).then(n=>e(n))})},queryRect(e,s){return new Promise(n=>{this.$uGetRect(`.${e}`).then(l=>{n(l)})})}}};Array||i.resolveComponent("u-badge")();const p=()=>"../u-badge/u-badge.js";Math||p();function m(e,s,n,l,o,r){return{a:i.f(e.list,(t,a,h)=>i.e(e.$slots.content?{a:"content-"+h,b:i.r("content",{item:t,keyName:e.keyName,index:a},h)}:!e.$slots.content&&(e.$slots.default||e.$slots.$default)?{c:"d-"+h,d:i.r("d",{item:t,keyName:e.keyName,index:a},h)}:{e:i.t(t[e.keyName]),f:i.n(t.disabled&&"u-tabs__wrapper__nav__item__text--disabled"),g:i.s(r.textStyle(a))},{h:"02b0c54f-0-"+h,i:i.p({show:!!(t.badge&&(t.badge.show||t.badge.isDot||t.badge.value)),isDot:t.badge&&t.badge.isDot||r.propsBadge.isDot,value:t.badge&&t.badge.value||r.propsBadge.value,max:t.badge&&t.badge.max||r.propsBadge.max,type:t.badge&&t.badge.type||r.propsBadge.type,showZero:t.badge&&t.badge.showZero||r.propsBadge.showZero,bgColor:t.badge&&t.badge.bgColor||r.propsBadge.bgColor,color:t.badge&&t.badge.color||r.propsBadge.color,shape:t.badge&&t.badge.shape||r.propsBadge.shape,numberType:t.badge&&t.badge.numberType||r.propsBadge.numberType,inverted:t.badge&&t.badge.inverted||r.propsBadge.inverted,customStyle:"margin-left: 4px;"}),j:a,k:i.o(u=>r.clickHandler(t,a),a),l:i.o(u=>r.longPressHandler(t,a),a),m:`u-tabs__wrapper__nav__item-${a}`,n:i.n(`u-tabs__wrapper__nav__item-${a}`),o:i.n(t.disabled&&"u-tabs__wrapper__nav__item--disabled")})),b:e.$slots.content,c:!e.$slots.content&&(e.$slots.default||e.$slots.$default),d:i.s(r.addStyle(e.itemStyle)),e:i.s({flex:e.scrollable?"":1}),f:i.s({width:r.addUnit(e.lineWidth),transform:`translate(${o.lineOffsetLeft}px)`,transitionDuration:`${o.firstTime?0:e.duration}ms`,height:r.addUnit(e.lineHeight),background:e.lineColor,backgroundSize:e.lineBgSize}),g:e.scrollable,h:o.scrollLeft,i:i.n(e.customClass)}}const w=i._export_sfc(_,[["render",m],["__scopeId","data-v-02b0c54f"]]);wx.createComponent(w);
