import{r as d,j as r,X as f}from"./index-D4ZMoJFe.js";import{Q as g}from"./index-iEHcFRfU.js";import{Q as j}from"./qr-code-46TMfM9m.js";import{P as h}from"./printer-vb2Kes09.js";import{D as w}from"./download-CFmyYwm2.js";const y=(e,i)=>({module:"mgx_vehicle",company_id:Number(i)||null,vehicle_id:Number(e.id),reference:e.reference||"",plate_number:e.plate_number||"",brand:e.brand||"",model:e.model||"",url:`${window.location.origin}/mgx/vehicles/${e.id}`});function Q({vehicle:e,companyId:i,onClose:c}){const o=d.useRef(null),m=d.useMemo(()=>y(e,i),[i,e]),u=JSON.stringify(m),x=`${e.plate_number||e.reference||"vehicule"}`.replace(/[^\w.-]+/g,"-"),p=()=>{var a;const t=(a=o.current)==null?void 0:a.querySelector("svg");if(!t)return;const n=new Blob([new XMLSerializer().serializeToString(t)],{type:"image/svg+xml;charset=utf-8"}),s=URL.createObjectURL(n),l=document.createElement("a");l.href=s,l.download=`qr-${x}.svg`,l.click(),URL.revokeObjectURL(s)},b=()=>{var s;const t=(s=o.current)==null?void 0:s.querySelector("svg");if(!t)return;const n=window.open("","_blank","width=420,height=560");n&&(n.document.write(`
      <html>
        <head>
          <title>QR ${e.plate_number||e.reference||""}</title>
          <style>
            body { font-family: Arial, sans-serif; display: grid; place-items: center; min-height: 100vh; margin: 0; }
            .card { text-align: center; border: 1px solid #d1d5db; border-radius: 18px; padding: 28px; }
            h1 { font-size: 22px; margin: 0 0 6px; }
            p { margin: 0 0 18px; color: #475569; }
          </style>
        </head>
        <body>
          <div class="card">
            <h1>${e.plate_number||"Véhicule"}</h1>
            <p>${e.reference||""} ${e.brand||""} ${e.model||""}</p>
            ${new XMLSerializer().serializeToString(t)}
          </div>
          <script>window.print(); window.close();<\/script>
        </body>
      </html>
    `),n.document.close())};return r.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-700/30 p-4 backdrop-blur-sm",children:r.jsxs("div",{className:"w-full max-w-md rounded-3xl border border-border bg-white p-6 shadow-2xl",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{children:[r.jsxs("p",{className:"inline-flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.18em] text-gold",children:[r.jsx(j,{size:15}),"QR véhicule"]}),r.jsx("h3",{className:"mt-2 text-2xl font-semibold text-text",children:e.plate_number||e.reference}),r.jsxs("p",{className:"mt-1 text-sm text-textMuted",children:[e.reference||"—"," · ",e.brand||"—"," ",e.model||""]})]}),r.jsx("button",{type:"button",className:"btn-secondary px-3 py-2",onClick:c,children:r.jsx(f,{size:16})})]}),r.jsxs("div",{className:"mt-6 rounded-3xl border border-border bg-surface2 p-6 text-center",children:[r.jsx("div",{ref:o,className:"mx-auto inline-block rounded-2xl bg-white p-4",children:r.jsx(g,{value:u,size:220,level:"M",includeMargin:!0})}),r.jsx("p",{className:"mt-4 text-xs text-textMuted",children:"Ce QR code ouvre la fiche véhicule et contient les informations d'identification du véhicule."})]}),r.jsxs("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:[r.jsxs("button",{type:"button",className:"btn-secondary inline-flex items-center justify-center gap-2",onClick:b,children:[r.jsx(h,{size:16}),"Imprimer"]}),r.jsxs("button",{type:"button",className:"btn-primary inline-flex items-center justify-center gap-2",onClick:p,children:[r.jsx(w,{size:16}),"Télécharger SVG"]})]})]})})}export{Q as M};
