import"./rolldown-runtime-BM3Ffeng.js";import{T as e}from"./element-plus-vendor-BF9PNysW.js";import{A as t,D as n,E as r,I as i,J as a,P as o,Pt as s,Tt as c,W as l,ct as u,et as d,ht as f,k as p,l as m,qt as h,y as g}from"./vue-vendor-DMUmTARL.js";import{$a as _,Ja as v,si as y}from"./icons-vendor-Buq6V-Ga.js";import{Tt as b,y as x}from"./index-y6crcKNt.js";var S=[`disabled`,`aria-busy`,`aria-label`],C={key:`loading`,class:`inline-flex items-center gap-3`},w={class:`flex h-7 w-7 items-center justify-center rounded-full bg-zp/10 text-zp dark:bg-zp/20`},T={key:`done`,class:`zf-qrcode-preview__download-success inline-flex items-center gap-3`},E={class:`zf-qrcode-preview__download-success-badge flex h-7 w-7 items-center justify-center rounded-full`},D={key:`idle`,class:`inline-flex items-center gap-3`},O={class:`flex h-7 w-7 items-center justify-center rounded-full bg-zp/10 text-zp dark:bg-zp/20`},k={class:`relative h-5 w-16 overflow-hidden text-center leading-5`},A=b(i({inheritAttrs:!1,__name:`QrCodePreview`,props:{src:{},showDownload:{type:Boolean,default:!0},filename:{default:`qrcode.png`},alt:{default:``},imgFit:{default:`contain`}},setup(i){let b=x(),A=i,j=u(),M=c(!1),N=c(!1),P=c(!1),F,I=r(()=>M.value?`正在下载二维码`:N.value?`二维码已保存`:`下载二维码`),L=()=>{A.showDownload&&(P.value=!P.value)},R=()=>{window.clearTimeout(F),F=void 0},z=()=>{N.value=!1,P.value=!1,document.activeElement instanceof HTMLElement&&document.activeElement.blur()},B=async()=>{if(!(!A.src||M.value)){R(),N.value=!1,M.value=!0;try{let e=await V(A.src),t=document.createElement(`canvas`);t.width=e.naturalWidth||e.width,t.height=e.naturalHeight||e.height;let n=t.getContext(`2d`);if(!n)throw Error(`Canvas not supported`);n.drawImage(e,0,0);let r=await H(t),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=A.filename||`qrcode.png`,a.click(),URL.revokeObjectURL(i),N.value=!0,F=window.setTimeout(z,1600)}catch(e){console.error(`Failed to download QR code`,e),b.error(`二维码下载失败，请重试`)}finally{M.value=!1}}},V=e=>new Promise((t,n)=>{let r=new Image;r.crossOrigin=`anonymous`,r.onload=()=>t(r),r.onerror=n,r.src=e}),H=e=>new Promise((t,n)=>{e.toBlob(e=>{e?t(e):n(Error(`Failed to convert canvas to blob`))},`image/png`)});return a(R),(r,i)=>{let a=e,c=y,u=_,b=v;return d(),t(`div`,l({class:`zf-qrcode-preview group relative inline-block overflow-hidden`},s(j),{onClick:L,onMouseleave:i[0]||=e=>P.value=!1}),[o(a,{src:A.src,alt:A.alt,fit:A.imgFit,class:`block h-full w-full`},null,8,[`src`,`alt`,`fit`]),A.showDownload?(d(),t(`div`,{key:0,class:h([`zf-qrcode-preview__overlay pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-surface-80 opacity-0 backdrop-blur-sm transition-all duration-300 group-focus-within:opacity-100 group-hover:opacity-100`,P.value?`!opacity-100`:``])},[n(`button`,{type:`button`,class:h([`zf-qrcode-preview__download-pill pointer-events-auto inline-flex translate-y-1 scale-90 cursor-pointer items-center gap-3 rounded-full border border-border-dark bg-overlay py-2 pl-3 pr-6 text-sm font-medium text-regular shadow-lg transition-all duration-300 hover:shadow-xl focus:outline-none focus-visible:translate-y-0 focus-visible:scale-100 focus-visible:ring-2 focus-visible:ring-zp/50 disabled:pointer-events-none group-focus-within:translate-y-0 group-focus-within:scale-100 group-hover:translate-y-0 group-hover:scale-100`,[M.value?`cursor-wait`:``,P.value?`!translate-y-0 !scale-100`:``]]),disabled:M.value||N.value,"aria-busy":M.value,"aria-label":I.value,"data-testid":`qrcode-download`,onClick:g(B,[`stop`])},[o(m,{name:`zf-qrcode-pill-swap`,mode:`out-in`},{default:f(()=>[M.value?(d(),t(`span`,C,[n(`span`,w,[o(c,{class:`animate-spin text-base`})]),i[1]||=n(`span`,null,`下载中`,-1)])):N.value?(d(),t(`span`,T,[n(`span`,E,[o(u,{class:`text-base`})]),i[2]||=n(`span`,null,`已保存`,-1)])):(d(),t(`span`,D,[n(`span`,O,[o(b,{class:`zf-qrcode-preview__download-arrow text-base`})]),n(`span`,k,[n(`span`,{class:h([`block transition-transform duration-300 group-focus-within:-translate-y-5 group-hover:-translate-y-5`,P.value?`!-translate-y-5`:``])},` 下载 `,2),n(`span`,{class:h([`absolute inset-x-0 top-5 block text-zp transition-transform duration-300 group-focus-within:-translate-y-5 group-hover:-translate-y-5`,P.value?`!-translate-y-5`:``])},` 保存 PNG `,2)])]))]),_:1})],10,S)],2)):p(``,!0)],16)}}}),[[`__scopeId`,`data-v-e39b0517`]]);export{A as t};