1import{ef as l,dY as e,dl as v,ak as N,dp as C,dn as k,bu as I,ey as g}from"./vendor-ByPPybGq.js";import"./vendor-date-HeizJUN9.js";const Z=o=>new Promise((a,n)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>a(s),s.onerror=()=>n(new Error("Impossible de charger l'image à recadrer")),s.src=o});async function E(o,a,n=.9){const s=await Z(o),t=document.createElement("canvas");t.width=Math.max(1,Math.round(a.width)),t.height=Math.max(1,Math.round(a.height));const d=t.getContext("2d");if(!d)throw new Error("Canvas indisponible");d.drawImage(s,a.x,a.y,a.width,a.height,0,0,t.width,t.height);const c=await new Promise(m=>t.toBlob(m,"image/webp",n));if(!c)throw new Error("Ãchec de l'encodage de l'image recadrée");return c}const M=({open:o,src:a,upload:n,aspect:s=12/5,onCancel:t,onCropped:d})=>{const[c,m]=l.useState({x:0,y:0}),[b,h]=l.useState(1),[u,f]=l.useState(null),[i,p]=l.useState(!1),w=l.useCallback((r,x)=>{f(x)},[]),y=async()=>{if(u){p(!0);try{const r=await E(a,u),x=new File([r],`crop-${Date.now()}.webp`,{type:"image/webp"}),j=await n(x);d(j),g.success("Image recadrée.")}catch(r){console.error(r),g.error("Ãchec du recadrage. Réessaie ou recharge la page.")}finally{p(!1)}}};return o?e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center bg-black/70 backdrop-blur-sm p-4",onClick:r=>{r.target===r.currentTarget&&!i&&t()},children:e.jsxs("div",{className:"w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-2xl",onClick:r=>r.stopPropagation(),children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-border px-5 py-3",children:[e.jsx("h3",{className:"font-display text-lg font-bold",children:"Recadrer l'image"}),e.jsx("button",{type:"button",onClick:t,disabled:i,className:"rounded-lg p-1 hover:bg-muted disabled:opacity-50","aria-label":"Fermer",children:e.jsx(v,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"relative h-[320px] w-full bg-black",children:e.jsx(N,{image:a,crop:c,zoom:b,aspect:s,minZoom:1,maxZoom:4,zoomSpeed:.2,showGrid:!0,restrictPosition:!0,onCropChange:m,onZoomChange:h,onCropComplete:w})}),e.jsxs("div",{className:"flex items-center gap-3 border-t border-border px-5 py-3",children:[e.jsx(C,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0}),e.jsx("input",{type:"range",min:1,max:4,step:.01,value:b,onChange:r=>h(Number(r.target.value)),className:"h-1.5 flex-1 cursor-pointer accent-primary","aria-label":"Zoom"}),e.jsx(k,{className:"h-4 w-4 shrink-0 text-muted-foreground","aria-hidden":!0})]}),e.jsxs("footer",{className:"flex flex-col gap-3 border-t border-border bg-muted/30 px-5 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Glisse l'image, ajuste le zoom - le cadre correspond au bandeau affiché."}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:t,disabled:i,className:"rounded-lg px-3 py-1.5 text-sm font-medium hover:bg-muted disabled:opacity-50",children:"Annuler"}),e.jsxs("button",{type:"button",onClick:y,disabled:i||!u,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-1.5 text-sm font-semibold text-primary-foreground transition-all hover:bg-primary/90 active:scale-[0.98] disabled:opacity-60",children:[i&&e.jsx(I,{className:"h-4 w-4 animate-spin"}),"Valider le recadrage"]})]})]})]})}):null};export{M as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.