import{_ as j,r as h,c as L,m as N,a as o,g as r,b as s,j as v,k,t as p,Q as $,h as w,n as T,af as U,aR as W}from"./index-QAlcqU00.js";const R={class:"fp-file-upload"},H={class:"p-6 text-center"},O={class:"mx-auto w-12 h-12 mb-4"},E={key:0,class:"w-full h-full text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},G={key:1,class:"flex items-center justify-center"},K={key:0},Q={class:"text-xs text-gray-500"},q={key:0},J={key:1},X={class:"w-full bg-gray-200 rounded-full h-2"},Y={class:"text-xs text-gray-500 mt-1"},Z={key:0,class:"mt-4 space-y-3"},ee={class:"flex-shrink-0 w-10 h-10 mr-3"},te=["src","alt"],se={key:1,class:"w-full h-full bg-gray-300 rounded flex items-center justify-center"},ae={class:"flex-1 min-w-0"},le={class:"text-sm font-medium text-gray-900 truncate"},oe={class:"text-xs text-gray-500"},re={key:0},ie=["onClick"],ne={key:1,class:"mt-3 text-sm text-red-600"},de=["accept","multiple","disabled"],ce={__name:"FPFileUpload",props:{modelValue:{type:[Array,File,null],default:null},accept:{type:String,default:"image/*,application/pdf,.doc,.docx"},multiple:{type:Boolean,default:!1},maxSize:{type:Number,default:10*1024*1024},maxFiles:{type:Number,default:5},disabled:{type:Boolean,default:!1},uploading:{type:Boolean,default:!1},uploadProgress:{type:Number,default:0}},emits:["update:modelValue","files-added","files-removed","error"],setup(i,{emit:M}){const a=i,m=M,F=h(null),g=h(!1),f=h(""),n=h([]),B=L(()=>a.accept==="image/*"?"Images only":a.accept.includes("image")&&a.accept.includes("pdf")?"Images and PDFs":"Files"),D=()=>{var t;!a.disabled&&!a.uploading&&((t=F.value)==null||t.click())},A=t=>{const e=Array.from(t.target.files);b(e),t.target.value=""},V=t=>{!a.disabled&&!a.uploading&&(g.value=!0)},P=()=>{g.value=!1},S=t=>{if(g.value=!1,!a.disabled&&!a.uploading){const e=Array.from(t.dataTransfer.files);b(e)}},b=t=>{f.value="";const e=[];for(const d of t){if(d.size>a.maxSize){f.value=`File "${d.name}" is too large. Maximum size is ${x(a.maxSize)}.`;continue}if(a.accept&&a.accept!=="*/*"&&!a.accept.split(",").map(u=>u.trim()).some(u=>u.startsWith(".")?d.name.toLowerCase().endsWith(u.toLowerCase()):u.includes("/*")?d.type.startsWith(u.replace("/*","")):d.type===u)){f.value=`File "${d.name}" is not an accepted file type.`;continue}e.push(d)}if(e.length===0)return;const c=(a.multiple?n.value.length:0)+e.length;if(a.multiple&&c>a.maxFiles){f.value=`Maximum ${a.maxFiles} files allowed.`;return}if(a.multiple){const d=e.map(y);n.value.push(...d);const z=n.value.map(C=>C.file);m("update:modelValue",z)}else{const d=y(e[0]);n.value=[d],m("update:modelValue",e[0])}m("files-added",e)},I=t=>{const e=n.value[t];if(n.value.splice(t,1),a.multiple){const l=n.value.map(c=>c.file);m("update:modelValue",l.length>0?l:null)}else m("update:modelValue",null);m("files-removed",[e.file])},y=t=>{const e={id:Date.now()+Math.random(),name:t.name,size:t.size,type:t.type,file:t,preview:null};if(_(t)){const l=new FileReader;l.onload=c=>{e.preview=c.target.result},l.readAsDataURL(t)}return e},_=t=>{var e;return((e=t.type)==null?void 0:e.startsWith("image/"))||!1},x=t=>{if(t===0)return"0 Bytes";const e=1024,l=["Bytes","KB","MB","GB"],c=Math.floor(Math.log(t)/Math.log(e));return parseFloat((t/Math.pow(e,c)).toFixed(2))+" "+l[c]};return N(()=>a.modelValue,t=>{t?Array.isArray(t)?n.value=t.map(y):n.value=[y(t)]:n.value=[]},{immediate:!0}),(t,e)=>(r(),o("div",R,[s("div",{class:T(["upload-area border-2 border-dashed rounded-lg transition-colors duration-200",[g.value?"border-primary-500 bg-primary-50":"border-gray-300",i.disabled?"opacity-50 cursor-not-allowed":"cursor-pointer hover:border-primary-400"]]),onClick:D,onDragover:w(V,["prevent"]),onDragleave:w(P,["prevent"]),onDrop:w(S,["prevent"])},[s("div",H,[s("div",O,[i.uploading?(r(),o("div",G,e[1]||(e[1]=[s("svg",{class:"animate-spin w-8 h-8 text-primary-500",fill:"none",viewBox:"0 0 24 24"},[s("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),s("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1)]))):(r(),o("svg",E,e[0]||(e[0]=[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"},null,-1)])))]),i.uploading?(r(),o("div",J,[e[3]||(e[3]=s("p",{class:"text-sm text-gray-600 mb-2"},"Uploading...",-1)),s("div",X,[s("div",{class:"bg-primary-500 h-2 rounded-full transition-all duration-300",style:$({width:`${i.uploadProgress}%`})},null,4)]),s("p",Y,p(i.uploadProgress)+"%",1)])):(r(),o("div",K,[e[2]||(e[2]=s("p",{class:"text-sm text-gray-600 mb-1"},[s("span",{class:"font-medium text-primary-600"},"Click to upload"),k(" or drag and drop ")],-1)),s("p",Q,[k(p(B.value)+" ",1),i.maxSize?(r(),o("span",q," (max "+p(x(i.maxSize))+")",1)):v("",!0)])]))])],34),n.value.length>0?(r(),o("div",Z,[(r(!0),o(U,null,W(n.value,(l,c)=>(r(),o("div",{key:l.id||c,class:"flex items-center p-3 bg-gray-50 rounded-lg"},[s("div",ee,[l.preview&&_(l)?(r(),o("img",{key:0,src:l.preview,alt:l.name,class:"w-full h-full object-cover rounded"},null,8,te)):(r(),o("div",se,e[4]||(e[4]=[s("svg",{class:"w-5 h-5 text-gray-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)])))]),s("div",ae,[s("p",le,p(l.name),1),s("p",oe,[k(p(x(l.size))+" ",1),l.type?(r(),o("span",re," • "+p(l.type),1)):v("",!0)])]),i.disabled?v("",!0):(r(),o("button",{key:0,onClick:d=>I(c),class:"flex-shrink-0 ml-3 p-1 rounded-full text-gray-400 hover:text-gray-600 hover:bg-gray-200 transition-colors",type:"button"},e[5]||(e[5]=[s("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)]),8,ie))]))),128))])):v("",!0),f.value?(r(),o("div",ne,p(f.value),1)):v("",!0),s("input",{ref_key:"fileInput",ref:F,type:"file",accept:i.accept,multiple:i.multiple,disabled:i.disabled,class:"hidden",onChange:A},null,40,de)]))}},pe=j(ce,[["__scopeId","data-v-3b4b2a2a"]]);export{pe as F};