"use strict";const e=require("../../../../common/vendor.js"),n=require("../common/util.js"),t=require("./types.js");Math||l();const l=()=>"../wd-loading/wd-loading.js",a=e.defineComponent({name:"wd-picker-view",options:{virtualHost:!0,addGlobalClass:!0,styleIsolation:"shared"},props:t.pickerViewProps,emits:["change","pickstart","pickend","update:modelValue"],setup(l,{expose:a,emit:o}){const u=l,i=o,r=e.ref([]),c=e.ref([]);e.watch([()=>u.modelValue,()=>u.columns],((e,l)=>{n.isEqual(l[1],e[1])||(n.isArray(e[1])&&e[1].length>0?r.value=t.formatArray(e[1],u.valueKey,u.labelKey):(r.value=[],c.value=[])),n.isDef(e[0])&&function(e){if(0===r.value.length)return void(c.value=[]);(""===e||!n.isDef(e)||n.isArray(e)&&0===e.length)&&(e=r.value.map((e=>e[0][u.valueKey])));const t=n.getType(e),l=["string","number","boolean","array"];-1===l.indexOf(t)&&console.error(`value must be one of ${l.toString()}`);e=(e=n.isArray(e)?e:[e]).slice(0,r.value.length);let a=n.deepClone(c.value);e.forEach(((e,n)=>{let t=r.value[n].findIndex((n=>n[u.valueKey].toString()===e.toString()));t=-1===t?0:t,a=d(n,t,a)})),c.value=a.slice(0,e.length)}(e[0])}),{deep:!0,immediate:!0});const{proxy:s}=e.getCurrentInstance();function d(e,t,l){const a=r.value[e];if(!a||!a[t])throw Error(`The value to select with Col:${e} Row:${t} is incorrect`);const o=n.deepClone(l);if(o[e]=t,a[t].disabled){const n=a.slice(0,t).reverse().findIndex((e=>!e.disabled)),l=a.slice(t+1).findIndex((e=>!e.disabled));-1!==n?o[e]=t-1-n:-1!==l?o[e]=t+1+l:void 0===o[e]&&(o[e]=0)}return o}function v({detail:{value:t}}){const l=function(e){e=e.slice(0,r.value.length);const t=n.deepClone(c.value);let l=n.deepClone(c.value);e.forEach(((e,a)=>{(e=n.range(e,0,r.value[a].length-1))!==t[a]&&(l=d(a,e,l))}));const a=function(e,n){if(!e||!n)return-1;return e.findIndex(((e,t)=>e!==n[t]))}(l,t);if(-1===a)return;const o=l[a];return 1===l.length?o:a}(t=t.map((e=>Number(e||0))));c.value=n.deepClone(t),e.nextTick$1((()=>{c.value=function(e){let t=n.deepClone(e);return e.forEach(((e,l)=>{e=n.range(e,0,r.value[l].length-1),t=d(l,e,t)})),t}(t),u.columnChange?u.columnChange.length<4?(u.columnChange(s.$.exposed,g(),l||0,(()=>{})),m(l||0)):u.columnChange(s.$.exposed,g(),l||0,(()=>{m(l||0)})):m(l||0)}))}function m(e){const t=p();n.isEqual(t,u.modelValue)||(i("update:modelValue",t),setTimeout((()=>{i("change",{picker:s.$.exposed,value:t,index:e})}),0))}function g(){const e=c.value.map(((e,n)=>r.value[n][e]));return 1===e.length?e[0]:e}function p(){const{valueKey:e}=u,n=c.value.map(((n,t)=>r.value[t][n][e]));return 1===n.length?n[0]:n}function f(){i("pickstart")}function h(){i("pickend")}return a({getSelects:g,getValues:p,setColumnData:function(e,n,l=0){r.value[e]=t.formatArray(n,u.valueKey,u.labelKey).reduce(((e,n)=>e.concat(n)),[]),c.value=d(e,l,c.value)},getColumnsData:function(){return n.deepClone(r.value)},getColumnData:function(e){return r.value[e]},getColumnIndex:function(e){return c.value[e]},getLabels:function(){const{labelKey:e}=u;return c.value.map(((n,t)=>r.value[t][n][e]))},getSelectedIndex:function(){return c.value},resetColumns:function(e){n.isArray(e)&&e.length&&(r.value=t.formatArray(e,u.valueKey,u.labelKey))}}),(n,t)=>e.e({a:n.loading},n.loading?{b:e.p({color:n.loadingColor})}:{},{c:e.f(r.value,((t,l,a)=>({a:e.f(t,((t,a,o)=>({a:e.t(t[n.labelKey]),b:a,c:e.n(`wd-picker-view-column__item ${t.disabled?"wd-picker-view-column__item--disabled":""}  ${c.value[l]==a?"wd-picker-view-column__item--active":""}`)}))),b:l}))),d:e.s(`line-height: ${n.itemHeight}px;`),e:`height: ${n.itemHeight}px;`,f:e.s(`height: ${n.columnsHeight-20}px;`),g:c.value,h:n.immediateChange,i:e.o(v),j:e.o(f),k:e.o(h),l:e.s(`height: ${n.columnsHeight-20}px;`),m:e.n(`wd-picker-view ${n.customClass}`),n:e.s(n.customStyle)})}}),o=e._export_sfc(a,[["__scopeId","data-v-fb198451"]]);wx.createComponent(o);
