import{_ as ee,a as te,b as le}from"./index-DwuhEmSW.js";import{k as P,d as ae,b as ie,l as oe,m as se,n as U,_ as ne}from"./index-D7dBOFlH.js";import{x as re,k as D,r as u,c as f,f as b,y as v,I as ue,O as s,U as w,G as ce,M as me,a4 as pe,u as a,P as de,C as y,V as B,H as _e,j as F,F as g,af as A,z as k}from"./vue-vendor-vBC20LeU.js";import{j as fe,E as ve}from"./element-plus-DckSU5ni.js";const ye={class:"material-picker"},ge=["onClick"],ke={class:"material-picker__item-actions"},Ce={class:"min-w-[780px] h-[560px] border-t border-b border-br"},he=re({__name:"Picker",props:{modelValue:{default:""},type:{default:"image"},limit:{default:-1},pageLimit:{default:30},size:{default:80},uploadClass:{default:""},uploadStyle:{default:()=>({})},fileSize:{default:100},dialogOnly:{type:Boolean,default:!1}},emits:["update:modelValue","change"],setup(z,{expose:N,emit:O}){const V=D([{type:"",name:"文件"},{type:"image",name:"图片"},{type:"video",name:"视频"}]),l=z,x=O,i=u([]),c=u([]),n=u(!1),m=u(!1),o=D({url:[],index:0,type:l.type}),p=u(!0),C=u(-1),S=f(()=>({...l.uploadStyle,width:P(l.size),height:P(l.size)})),$=f(()=>V.find(t=>t.type===l.type)||V[0]),j=f(()=>l.limit===-1||i.value.length<l.limit),Z=f(()=>{if(!p.value)return 1;if(l.limit!==-1)return l.limit-i.value.length}),L=e=>{i.value=Array.isArray(e)?e:e?[e]:[]},h=e=>{e>=0?(p.value=!1,C.value=e):(p.value=!0,C.value=-1),c.value=[],n.value=!0},G=e=>{c.value=e},H=oe(()=>{const e=c.value.map(t=>t.url);if(!p.value&&e.length>0)i.value.splice(C.value,1,e[0]);else if(e.length>0){const t=new Set(i.value);e.forEach(d=>{t.has(d)||t.add(d)}),i.value=Array.from(t)}n.value=!1,E()},1e3,!1),T=e=>{if(l.type=="image")o.url=i.value,o.index=e;else{const t=se(o.url);if(U.imageType.includes(`.${t}`))o.type="image",o.index=0;else if(U.videoType.includes(`.${t}`))o.type="video";else{window.open(o.url);return}}o.type=l.type,o.url=i.value[e],m.value=!0},R=e=>{i.value.splice(e,1),E()},E=()=>{const e=l.limit!==1?i.value:i.value[0]||"";x("update:modelValue",e),x("change",e)};return b(()=>l.modelValue,e=>{L(e)},{immediate:!0}),b(()=>l.type,()=>{L(l.modelValue)}),b(n,e=>{e||(c.value=[])}),N({open:h,openPreview:T}),(e,t)=>{const d=le,q=A("ZoomIn"),I=ve,J=A("Delete"),K=ae,Q=ee,W=fe,X=ie,Y=te;return k(),v("div",ye,[z.dialogOnly?ue("",!0):(k(),v("div",{key:0,class:"material-picker__list",onClick:t[1]||(t[1]=w(()=>{},["stop"]))},[(k(!0),v(me,null,pe(a(i),(r,_)=>(k(),v("div",{class:"material-picker__item",key:_,style:B(a(S)),onClick:M=>h(_)},[s(d,{url:r,"file-size":l.size},null,8,["url","file-size"]),y("div",ke,[s(I,{size:20,onClick:w(M=>T(_),["stop"])},{default:g(()=>[s(q)]),_:1},8,["onClick"]),s(I,{size:20,onClick:w(M=>R(_),["stop"])},{default:g(()=>[s(J)]),_:1},8,["onClick"])])],12,ge))),128)),ce(y("div",{class:_e(["material-picker__upload",l.uploadClass]),style:B(a(S)),onClick:t[0]||(t[0]=r=>h(-1))},[s(K,{size:24,name:"Plus"}),t[4]||(t[4]=y("span",{class:"text-base"},"添加",-1))],6),[[de,a(j)]])])),s(X,{modelValue:a(n),"onUpdate:modelValue":t[2]||(t[2]=r=>F(n)?n.value=r:null),title:`选择${a($).name}`,width:"940px",onConfirm:a(H)},{default:g(()=>[s(W,null,{default:g(()=>[y("div",Ce,[s(Q,{"select-tab":a($),limit:a(Z),"page-limit":l.pageLimit,"is-picker":!0,"file-size":l.fileSize,onChange:G},null,8,["select-tab","limit","page-limit","file-size"])])]),_:1})]),_:1},8,["modelValue","title","onConfirm"]),s(Y,{modelValue:a(m),"onUpdate:modelValue":t[3]||(t[3]=r=>F(m)?m.value=r:null),url:a(o).url,index:a(o).index,type:a(o).type},null,8,["modelValue","url","index","type"])])}}}),xe=ne(he,[["__scopeId","data-v-a5c4a1b0"]]);export{xe as _};
