"use strict";const t=require("vue"),y=require("../Shared/base-iCmnU-fv.js"),g=require("../Shared/index-Ul6uY51t.js"),N=require("../Shared/resize-COkswDOq.js");require("js-cookie");require("decimal.js");const $=t.defineComponent({name:"ClWaterfall",__name:"Index",props:{className:String,list:{type:Array,default:()=>[]},itemKey:{type:String,default:"id"},width:{type:Number,default:-1},colNum:{type:Number,default:-1},spacing:{type:Number,default:10},animationName:{type:String,default:"animated fadeIn"}},setup(x,{expose:k}){const c=x,d=t.ref(null),m=t.reactive({keyIndex:`waterfall-${y.CommonBase.getRandom(8)}`,pWidth:0,pHeight:0}),C=t.ref([]),i={colPosY:[],resizeEvent:null,resizeDelayFun:null,isExistItemKey:!0},p=t.computed(()=>{const e=m.pWidth,{width:s,colNum:n,spacing:l}=c;let a=300;const o=s>0,r=n>0,u=r?parseInt(((e+l)/n).toString())-l:0;if(o&&r){const h=(s+l)*n-l;a=e>=h?s:u}else!o&&r?a=u:o&&!r&&(a=e>s?s:e);return a}),E=t.computed(()=>{const e=m.pWidth,s=p.value,{colNum:n,spacing:l}=c,a=n>0;let o=-1;const r=parseInt(((e+l)/(s+l)).toString());if(a){const u=(s+l)*n-l;o=e>=u?n:r}else o=r;return o}),_=t.computed(()=>{const e=m.pWidth,s=p.value,n=E.value,{spacing:l}=c,a=(s+l)*n-l;return parseInt(((e-a)/2).toString())}),b=t.computed(()=>{const e={"panel-waterfall":!0},{className:s}=c;return s&&!y.CommonBase.isEmpty(s)&&s.split(" ").forEach(n=>{y.CommonBase.isEmpty(n)||(e[n]=!0)}),e}),z=()=>{const{list:e,itemKey:s}=c;e.forEach(n=>{i.isExistItemKey&&(i.isExistItemKey=y.CommonBase.isExistJsonKey(n,s))})},w=()=>{C.value=c.list},B=()=>{const{spacing:e}=c;i.colPosY=new Array(E.value).fill(e)},S=e=>{const{spacing:s}=c,n=p.value;return _.value+(n+s)*e},W=()=>{let e;if(d.value&&(e=d.value.querySelectorAll(".waterfall-item")),y.CommonBase.isUndefined(e)||!e||e.length===0)return;B();const s=p.value,{spacing:n,animationName:l}=c;for(let a=0;a<e.length;a++){const o=e[a],r=g.CommonElement.getPositionView(o).height,u=Math.min.apply(null,i.colPosY),h=i.colPosY.indexOf(u),P=S(h);o.style.width=`${s}px`,o.style.transform=`translate3d(${P}px,${u}px, 0)`,i.colPosY[h]+=r+n;const f=o.firstChild,v=f.style;f.style.visibility="visible",g.CommonElement.checkHasClass(f.className,l)||(v["animation-duration"]="1000ms",v["animation-delay"]="200ms",v["animation-fill-mode"]="both",f.className=g.CommonElement.getAddClass(f.className,l))}m.pHeight=Math.max.apply(null,i.colPosY)},I=()=>{i.isExistItemKey?(w(),i.resizeDelayFun.run(()=>{W()})):i.resizeDelayFun.run(()=>{w(),t.nextTick(()=>{W()})})},K=()=>{i.resizeDelayFun=new N.DelayFun(null,200),i.resizeEvent=new N.Resize({element:d.value,callback:e=>{m.pWidth=e.contentRect.width}})};return t.onMounted(()=>{t.nextTick(()=>{K()})}),t.onUnmounted(()=>{i.resizeEvent&&i.resizeEvent.destroy()}),t.watch(()=>[m.pWidth,p,c.list],()=>{z(),I()},{deep:!0}),t.provide("$WaterfallTop",{imgCallback:I}),k({deleteItem:e=>{const s=d.value?.querySelectorAll(".waterfall-item");if(s&&s[e]){const n=s[e];n.firstChild&&(n.firstChild.style.visibility="hidden")}}}),(e,s)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(b.value)},[t.createElementVNode("div",{ref_key:"refElList",ref:d,class:"waterfall-list",style:t.normalizeStyle({height:`${m.pHeight}px`})},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(C.value,(n,l)=>(t.openBlock(),t.createElementBlock("div",{key:`${m.keyIndex}_${n[x.itemKey]||l}`,class:"waterfall-item"},[t.createElementVNode("div",null,[t.renderSlot(e.$slots,"default",{data:n,index:l})])]))),128))],4)],2))}});module.exports=$;
//# sourceMappingURL=ClWaterfall.cjs.map
