import{u as F,j as e}from"./index-D9pJRAs5.js";import{r as S}from"./vendor-D6aTFYy9.js";import{E as L}from"./pdf-Bz_mU5mG.js";import"./jspdf.plugin.autotable--NsDeQP_.js";import{X as f,bY as D,aa as v,m as P,F as U,C as _,G as A,av as w,V as j,ad as E,b as R,aX as W}from"./ui-CtYVlq7P.js";const X=({isOpen:N,onClose:k,check:a})=>{const[x,g]=S.useState(null),{t:s}=F();if(!N||!a)return null;const q=t=>{switch(t){case"passed":return"bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-300";case"failed":return"bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-300";case"requires_rework":return"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/50 dark:text-yellow-300";default:return"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-300"}},$=t=>{switch(t){case"passed":return e.jsx(_,{className:"h-5 w-5"});case"failed":return e.jsx(W,{className:"h-5 w-5"});case"requires_rework":return e.jsx(R,{className:"h-5 w-5"});default:return e.jsx(E,{className:"h-5 w-5"})}},T=t=>{switch(t){case"critical":return"bg-red-50 text-red-700 border-red-200 dark:bg-red-900/20 dark:text-red-300 dark:border-red-800";case"major":return"bg-orange-50 text-orange-700 border-orange-200 dark:bg-orange-900/20 dark:text-orange-300 dark:border-orange-800";case"minor":return"bg-yellow-50 text-yellow-700 border-yellow-200 dark:bg-yellow-900/20 dark:text-yellow-300 dark:border-yellow-800";default:return"bg-gray-50 text-gray-700 border-gray-200"}},y=()=>{const t=new L({orientation:"portrait",unit:"mm",format:[100,150]}),i=t.internal.pageSize.getWidth(),o=t.internal.pageSize.getHeight(),l=5,d=i-l*2;t.setLineWidth(.5),t.rect(l,l,d,o-l*2);let r=l+10;t.setFontSize(14),t.setFont("helvetica","bold"),t.text(s("production_modals.quality_detail.label_title"),i/2,r,{align:"center"}),r+=8,a.status==="passed"?(t.setFillColor(220,252,231),t.setTextColor(22,101,52)):a.status==="failed"?(t.setFillColor(254,226,226),t.setTextColor(153,27,27)):(t.setFillColor(254,249,195),t.setTextColor(133,77,14)),t.rect(l+2,r-5,d-4,10,"F"),t.setFontSize(12);const m=a.status==="passed"?s("production_modals.quality_check.status.pass"):a.status==="failed"?s("production_modals.quality_check.status.fail"):s("production_modals.quality_check.status.rework");t.text(m.toUpperCase(),i/2,r+1.5,{align:"center"}),t.setTextColor(0,0,0),r+=12,t.setFontSize(10),t.setFont("helvetica","bold"),t.text(s("production_modals.quality_detail.order_info",{name:a.orderTitle}),l+2,r),r+=5,t.setFontSize(8),t.setFont("helvetica","normal"),t.text(a.customerName,l+2,r),t.text(new Date(a.checkedAt).toLocaleDateString(),i-l-2,r-5,{align:"right"}),r+=8,t.line(l,r,i-l,r),r+=6,t.setFontSize(9);const p=s(`production_modals.quality_check.types.${a.checkType}`);if(t.text(`${s("production_modals.quality_detail.type_label")}: ${p}`,l+2,r),t.text(`${s("production_modals.quality_detail.inspector_label")}: ${a.inspector}`,i-l-2,r,{align:"right"}),r+=10,t.setFontSize(14),t.setFont("helvetica","bold"),t.text(`${s("production_modals.quality_check.score_label")}: ${a.score}%`,i/2,r,{align:"center"}),r+=8,t.line(l,r,i-l,r),r+=6,t.setFontSize(9),t.setFont("helvetica","bold"),t.text(s("production_modals.quality_detail.defects_title"),l+2,r),r+=5,t.setFontSize(8),t.setFont("helvetica","normal"),a.defects&&a.defects.length>0?a.defects.forEach(n=>{const c=`• [${s(`production_modals.quality_check.defect_severity.${n.severity}`)}] ${n.type}`;r>o-l-20||(t.text(c,l+4,r),r+=4)}):(t.text(s("production_modals.quality_detail.no_defects"),l+4,r),r+=4),r+=4,a.notes&&r<o-l-20){t.setFont("helvetica","bold"),t.text(s("production_modals.quality_detail.notes_title"),l+2,r),r+=4,t.setFont("helvetica","normal");const n=t.splitTextToSize(a.notes,d-4),u=Math.floor((o-l-15-r)/4),c=n.slice(0,u);t.text(c,l+2,r)}return t.setFontSize(6),t.text(`Generated: ${new Date().toLocaleString()}`,i/2,o-l-2,{align:"center"}),t},C=()=>{const i=y().output("blob"),o=URL.createObjectURL(i);g(o)},b=()=>{y().save(`QC-Label-${a.orderTitle.replace(/[^a-z0-9]/gi,"_").toLowerCase()}.pdf`)},h=()=>{const o=window.screen.width/2-200,l=window.screen.height/2-600/2,d=window.open("","_blank",`width=400,height=600,top=${l},left=${o}`);if(!d){alert(s("production_modals.quality_detail.alert_popups"));return}const r=a.status==="passed"?"#dcfce7":a.status==="failed"?"#fee2e2":"#fef9c3",m=a.status==="passed"?"#166534":a.status==="failed"?"#991b1b":"#854d0e",p=a.status==="passed"?s("production_modals.quality_check.status.pass"):a.status==="failed"?s("production_modals.quality_check.status.fail"):s("production_modals.quality_check.status.rework"),n=s(`production_modals.quality_check.types.${a.checkType}`),u=`
        <!DOCTYPE html>
        <html>
        <head>
            <title>QC Label - ${a.orderTitle}</title>
            <style>
                @page { size: 100mm 150mm; margin: 0; }
                body { font-family: Helvetica, Arial, sans-serif; margin: 0; padding: 10px; width: 100mm; height: 150mm; box-sizing: border-box; }
                .container { border: 2px solid #000; height: 100%; padding: 10px; display: flex; flex-direction: column; box-sizing: border-box; }
                .header { text-align: center; font-weight: bold; font-size: 16px; margin-bottom: 10px; text-transform: uppercase; }
                .banner { background: ${r}; color: ${m}; padding: 8px; text-align: center; font-weight: bold; font-size: 14px; text-transform: uppercase; border: 1px solid ${m}; margin-bottom: 15px; border-radius: 4px; }
                .info-row { display: flex; justify-content: space-between; margin-bottom: 5px; font-size: 10px; color: #555; }
                .info-val { font-size: 12px; font-weight: bold; color: #000; }
                .divider { border-bottom: 1px solid #ccc; margin: 10px 0; }
                .score-box { text-align: center; margin: 10px 0; }
                .score-val { font-size: 24px; font-weight: bold; }
                .defects-list { font-size: 10px; margin-top: 5px; }
                .defect { margin-bottom: 2px; }
                .footer { margin-top: auto; font-size: 8px; text-align: center; color: #888; }
            </style>
        </head>
        <body>
            <div class="container">
                <div class="header">${s("production_modals.quality_detail.label_title")}</div>
                <div class="banner">${p}</div>
                
                <div class="info-row">
                    <div>
                        <div>${s("production_modals.quality_check.order_label").replace(" *","")}</div>
                        <div class="info-val">${a.orderTitle}</div>
                    </div>
                    <div style="text-align:right">
                        <div>${s("production_modals.quality_detail.date_label")}</div>
                        <div class="info-val">${new Date(a.checkedAt).toLocaleDateString()}</div>
                    </div>
                </div>
                
                <div class="info-row">
                    <div>
                        <div>${s("production_modals.quality_detail.customer_label")}</div>
                        <div class="info-val">${a.customerName}</div>
                    </div>
                </div>

                <div class="divider"></div>

                <div class="info-row">
                     <div>${s("production_modals.quality_detail.inspector_label")}: <span class="info-val">${a.inspector}</span></div>
                     <div>${s("production_modals.quality_detail.type_label")}: <span class="info-val">${n}</span></div>
                </div>

                <div class="score-box">
                    <div>${s("production_modals.quality_check.score_label")}</div>
                    <div class="score-val">${a.score}%</div>
                </div>

                <div class="divider"></div>

                <div style="font-weight:bold; font-size:11px; margin-bottom:5px;">${s("production_modals.quality_detail.defects_title")}</div>
                <div class="defects-list">
                    ${a.defects&&a.defects.length>0?a.defects.map(c=>`<div class="defect">• [${s(`production_modals.quality_check.defect_severity.${c.severity}`).toUpperCase()}] ${c.type}</div>`).join(""):`<div>${s("production_modals.quality_detail.no_defects")}</div>`}
                </div>
                
                ${a.notes?`<div style="margin-top:10px; font-size:10px;"><strong>${s("production_modals.quality_detail.notes_title")}:</strong><br/>${a.notes}</div>`:""}

                <div class="footer">
                    Generated on ${new Date().toLocaleString()}
                </div>
            </div>
            <script>
                setTimeout(() => { window.print(); }, 500);
                window.onafterprint = function() { setTimeout(() => { window.close(); }, 500); }
            <\/script>
        </body>
        </html>
      `;d.document.write(u),d.document.close()},z=()=>{x&&URL.revokeObjectURL(x),g(null)};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl max-w-2xl w-full max-h-[90vh] flex flex-col shadow-2xl relative",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:s("production_modals.quality_detail.title")}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:s("production_modals.quality_detail.order_info",{name:a.orderTitle})})]}),e.jsx("button",{onClick:k,className:"p-2 text-gray-400 hover:text-gray-600 rounded-lg dark:hover:bg-gray-700 dark:hover:text-gray-200",children:e.jsx(f,{className:"h-6 w-6"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-xl ${q(a.status)} bg-opacity-50`,children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[$(a.status),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-lg capitalize",children:a.status==="passed"?s("production_modals.quality_check.status.pass"):a.status==="failed"?s("production_modals.quality_check.status.fail"):s("production_modals.quality_check.status.rework")}),e.jsxs("p",{className:"text-sm opacity-80",children:[s("production_modals.quality_check.score_label"),": ",a.score,"%"]})]})]}),e.jsx("div",{className:"flex items-center space-x-1",children:[...Array(5)].map((t,i)=>e.jsx(D,{className:`h-5 w-5 ${i<Math.floor(a.score/20)?"fill-current":"opacity-30"}`},i))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg",children:[e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center",children:[e.jsx(v,{className:"h-3 w-3 mr-1"})," ",s("production_modals.quality_detail.inspector_label")]}),e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:a.inspector})]}),e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg",children:[e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center",children:[e.jsx(P,{className:"h-3 w-3 mr-1"})," ",s("production_modals.quality_detail.date_label")]}),e.jsxs("p",{className:"font-medium text-gray-900 dark:text-white",children:[new Date(a.checkedAt).toLocaleDateString()," ",new Date(a.checkedAt).toLocaleTimeString()]})]}),e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg",children:[e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center",children:[e.jsx(U,{className:"h-3 w-3 mr-1"})," ",s("production_modals.quality_detail.type_label")]}),e.jsx("p",{className:"font-medium text-gray-900 dark:text-white capitalize",children:s(`production_modals.quality_check.types.${a.checkType}`)})]}),e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg",children:[e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400 mb-1 flex items-center",children:[e.jsx(v,{className:"h-3 w-3 mr-1"})," ",s("production_modals.quality_detail.customer_label")]}),e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:a.customerName})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-3",children:s("production_modals.quality_detail.defects_title")}),a.defects&&a.defects.length>0?e.jsx("div",{className:"space-y-3",children:a.defects.map((t,i)=>e.jsxs("div",{className:`p-3 rounded-lg border ${T(t.severity)}`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-1",children:[e.jsx("span",{className:"font-semibold",children:t.type}),e.jsx("span",{className:"text-xs font-bold uppercase px-2 py-0.5 rounded-full bg-white/50",children:s(`production_modals.quality_check.defect_severity.${t.severity}`)})]}),e.jsx("p",{className:"text-sm opacity-90",children:t.description})]},i))}):e.jsxs("div",{className:"text-center p-6 bg-gray-50 dark:bg-gray-700/30 rounded-lg border border-dashed border-gray-300 dark:border-gray-600",children:[e.jsx(_,{className:"h-8 w-8 text-green-500 mx-auto mb-2"}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:s("production_modals.quality_detail.no_defects")})]})]}),a.notes&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:s("production_modals.quality_detail.notes_title")}),e.jsx("div",{className:"p-4 bg-gray-50 dark:bg-gray-700/50 rounded-lg text-gray-700 dark:text-gray-300 text-sm",children:a.notes})]})]}),e.jsxs("div",{className:"p-6 border-t border-gray-200 dark:border-gray-700 flex justify-end space-x-3",children:[e.jsxs("button",{onClick:C,className:"flex items-center space-x-2 px-4 py-2 bg-blue-50 text-blue-700 hover:bg-blue-100 dark:bg-blue-900/30 dark:text-blue-300 dark:hover:bg-blue-900/50 rounded-lg transition-colors",children:[e.jsx(A,{className:"h-4 w-4"}),e.jsx("span",{children:s("production_modals.quality_detail.preview_label_button")})]}),e.jsxs("button",{onClick:b,className:"flex items-center space-x-2 px-4 py-2 bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors",children:[e.jsx(w,{className:"h-4 w-4"}),e.jsx("span",{children:s("production_modals.quality_detail.download")})]}),e.jsxs("button",{onClick:h,className:"flex items-center space-x-2 px-4 py-2 bg-blue-600 text-white hover:bg-blue-700 rounded-lg transition-colors",children:[e.jsx(j,{className:"h-4 w-4"}),e.jsx("span",{children:s("production_modals.quality_detail.print")})]})]}),x&&e.jsx("div",{className:"absolute inset-0 z-50 bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4 rounded-2xl",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full h-full max-w-sm flex flex-col overflow-hidden animate-scale-in",children:[e.jsxs("div",{className:"p-4 border-b dark:border-gray-700 flex justify-between items-center bg-gray-50 dark:bg-gray-900",children:[e.jsx("h3",{className:"font-bold text-gray-900 dark:text-white",children:s("production_modals.quality_detail.preview_title")}),e.jsx("button",{onClick:z,className:"text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-white",children:e.jsx(f,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"flex-1 bg-gray-200 dark:bg-gray-900 flex items-center justify-center p-4",children:e.jsx("iframe",{src:x,className:"w-full h-full rounded shadow-lg bg-white",title:"Label Preview"})}),e.jsxs("div",{className:"p-4 border-t dark:border-gray-700 flex justify-between bg-white dark:bg-gray-800",children:[e.jsxs("button",{onClick:b,className:"flex items-center space-x-2 text-sm text-gray-600 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400",children:[e.jsx(w,{className:"h-4 w-4"})," ",e.jsx("span",{children:s("production_modals.quality_detail.download")})]}),e.jsxs("button",{onClick:h,className:"px-4 py-2 bg-blue-600 text-white rounded-lg text-sm hover:bg-blue-700 flex items-center space-x-2",children:[e.jsx(j,{className:"h-4 w-4"})," ",e.jsx("span",{children:s("production_modals.quality_detail.print_now")})]})]})]})})]})})};export{X as default};
