import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";import useCustomNavbar from"../mixins/using-custom-navbar";const{prefix:prefix}=config,name=`${prefix}-picker`,DEFAULT_KEYS={value:"value",label:"label",icon:"icon"};let Picker=class extends SuperComponent{constructor(){super(...arguments),this.behaviors=[useCustomNavbar],this.properties=props,this.externalClasses=[`${prefix}-class`,`${prefix}-class-confirm`,`${prefix}-class-cancel`,`${prefix}-class-title`],this.options={multipleSlots:!0},this.relations={"../picker-item/picker-item":{type:"child",linked(){this.updateChildren()}}},this.observers={"value, visible"(e,i){const{usePopup:t}=this.properties;t&&!i||(this.updateChildren(),this.updateIndicatorPosition())},"itemHeight, visibleItemCount"(){this.updateIndicatorPosition()}},this.data={prefix:prefix,classPrefix:name,defaultPopUpProps:{},defaultPopUpzIndex:11500,indicatorTop:72},this.methods={updateChildren(){const{value:e,defaultValue:i,itemHeight:t,visibleItemCount:s,keys:o}=this.properties;this.$children.forEach((n,r)=>{var l,a;n.setData({value:null!==(a=null!==(l=null==e?void 0:e[r])&&void 0!==l?l:null==i?void 0:i[r])&&void 0!==a?a:"",columnIndex:r,itemHeight:t,visibleItemCount:s,keys:Object.assign(Object.assign({},DEFAULT_KEYS),o||{})}),n.update()})},getSelectedValue(){return[this.$children.map(e=>e._selectedValue),this.$children.map(e=>e._selectedLabel)]},getColumnIndexes(){return this.$children.map((e,i)=>({column:i,index:e._selectedIndex}))},onConfirm(){const e=[],i=[],t=[];this.$children.forEach((s,o)=>{const n=s.getCurrentSelected();e.push(n.value),i.push(n.label),t.push({column:o,index:n.index})}),this.close("confirm-btn"),this.triggerEvent("confirm",{value:e,label:i,columns:t}),JSON.stringify(this.data.value)!==JSON.stringify(e)&&this.triggerEvent("change",{value:e,label:i,columns:t})},triggerColumnChange({column:e,index:i}){const[t,s]=this.getSelectedValue();this.triggerEvent("pick",{value:t,label:s,column:e,index:i})},onCancel(){this.close("cancel-btn"),this.triggerEvent("cancel")},onPopupChange(e){const{visible:i}=e.detail;this.close("overlay"),this.triggerEvent("visible-change",{visible:i})},close(e){this.data.autoClose&&this.setData({visible:!1}),this.triggerEvent("close",{trigger:e})},updateIndicatorPosition(){const{itemHeight:e,visibleItemCount:i}=this.properties,t=(i-1)/2*e;this.setData({indicatorTop:t})}}}ready(){this.$children.map((e,i)=>e.columnIndex=i),this.updateIndicatorPosition()}};Picker=__decorate([wxComponent()],Picker);export default Picker;