import m from"qrcode";import{useMemo as w}from"react";import{Fragment as q,jsx as s,jsxs as M}from"react/jsx-runtime";var z=(a,f)=>{let i=Array.prototype.slice.call(m.create(a,{errorCorrectionLevel:f}).modules.data,0),u=Math.sqrt(i.length);return i.reduce((l,d,x)=>(x%u===0?l.push([d]):l[l.length-1].push(d))&&l,[])};function A({ecl:a="M",size:f=200,uri:i,clearArea:u=!1,image:l,imageBackground:d="transparent"}){let x=u?76:0,n=f-10*2,$=w(()=>{let g=[],o=z(i,a),t=n/o.length;if([{x:0,y:0},{x:1,y:0},{x:0,y:1}].forEach(({x:h,y:e})=>{let b=(o.length-7)*t*h,c=(o.length-7)*t*e;for(let r=0;r<3;r++)g.push(s("rect",{fill:r%2!==0?"var(--bad-colors-background, var(--bad-colors-background))":"var(--bad-colors-foreground)",rx:(r-2)*-5+(r===0?2:3),ry:(r-2)*-5+(r===0?2:3),width:t*(7-r*2),height:t*(7-r*2),x:b+t*r,y:c+t*r},`${r}-${h}-${e}`))}),l){let h=(o.length-7)*t*1,e=(o.length-7)*t*1;g.push(M(q,{children:[s("rect",{fill:d,rx:(0-2)*-5+2,ry:(0-2)*-5+2,width:t*(7-0*2),height:t*(7-0*2),x:h+t*0,y:e+t*0}),s("foreignObject",{width:t*(7-0*2),height:t*(7-0*2),x:h+t*0,y:e+t*0,children:s("div",{style:{borderRadius:(0-2)*-5+2,overflow:"hidden"},children:l})})]}))}let y=Math.floor((x+25)/t),p=o.length/2-y/2,v=o.length/2+y/2-1;return o.forEach((h,e)=>{h.forEach((b,c)=>{o[e][c]&&(e<7&&c<7||e>o.length-8&&c<7||e<7&&c>o.length-8||(l||!(e>p&&e<v&&c>p&&c<v))&&g.push(s("circle",{cx:e*t+t/2,cy:c*t+t/2,fill:"var(--bad-colors-foreground)",r:t/3},`circle-${e}-${c}`)))})}),g},[a,n,i]);return M("svg",{height:n,width:n,viewBox:`0 0 ${n} ${n}`,style:{width:n,height:n},children:[s("rect",{fill:"transparent",height:n,width:n}),$]})}export{A as QRCode};
