!function(){"use strict";window.exportVisibleTableCSV=function(t){t=t||"datos";for(var e=document.querySelectorAll("table"),o=null,n=0;n✕',r.appendChild(a),n.forEach((function(t){var o=document.createElement("div"),n=document.createElement("label");n.style.cssText="display:block;font-size:12px;color:var(--color-text-muted);margin-bottom:4px;text-transform:uppercase;letter-spacing:0.05em;",n.textContent=t.label,o.appendChild(n);var a=document.createElement("select");a.style.cssText="width:100%;padding:8px 10px;background:var(--glass-bg,#222);border:1px solid var(--glass-border,#444);border-radius:6px;color:var(--color-text-primary,#fff);font-size:13px;",a.dataset.filterColumn=t.column;var i=document.createElement("option");i.value="",i.textContent=t.allLabel||"Todos",a.appendChild(i),(t.values||[]).forEach((function(t){if(t){var e=document.createElement("option");e.value=t,e.textContent=t,a.appendChild(e)}})),a.addEventListener("change",(function(){e(r)})),o.appendChild(a),r.appendChild(o)}));var i=document.createElement("button");i.style.cssText="padding:8px;background:transparent;border:1px dashed var(--glass-border,#444);border-radius:6px;color:var(--color-text-muted);cursor:pointer;font-size:12px;",i.textContent="Limpiar filtros",i.addEventListener("click",(function(){r.querySelectorAll("select").forEach((function(t){t.value=""})),e(r)})),r.appendChild(i);var l=o.parentElement;l&&(l.style.position="relative"),(l||document.body).appendChild(r),t=r,setTimeout((function(){document.addEventListener("click",(function t(e){r.contains(e.target)||e.target===o||(closeFilterPanel(),document.removeEventListener("click",t))}))}),100)},window.closeFilterPanel=function(){t&&(t.remove(),t=null)},window.getUniqueColumnValues=function(t,e,o){o=o||30;var n={};return t?(t.querySelectorAll("tbody tr").forEach((function(t){var o=t.querySelectorAll("td");if(o[e]){var r=o[e].textContent.trim();r&&"-"!==r&&""!==r&&(n[r]=(n[r]||0)+1)}})),Object.keys(n).sort((function(t,e){return n[e]-n[t]})).slice(0,o)):[]};var o=null;function n(t,e){fetch("/pos/api/quotations/"+t+"/print",{method:"POST",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"},body:JSON.stringify({printer_type:"browser"})}).then((function(t){return t.json()})).then((function(o){var n="Cotización #"+o.id+"";n+="",n+="

COTIZACIÓN

",n+='

COT-'+o.id+"

",n+="

Fecha: "+(o.created_at||"").substring(0,10)+"

",o.customer_name&&(n+="

Cliente: "+o.customer_name+"

"),o.wa_phone&&(n+="

WhatsApp: "+o.wa_phone+"

"),n+="
",(o.items||[]).forEach((function(t){n+="",t.part_number&&(n+='")})),n+="
"+t.quantity+"x "+t.name+'$'+t.subtotal.toFixed(2)+"
#'+t.part_number+"

",n+='

Subtotal: $'+o.subtotal.toFixed(2)+"

",n+='

IVA: $'+o.tax_total.toFixed(2)+"

",n+='

TOTAL: $'+o.total.toFixed(2)+"

",n+='

Esta cotización no es comprobante fiscal
Precios sujetos a disponibilidad

',n+="";var a=window.open("","_blank","width=400,height=600");a.document.write(n),a.document.close(),setTimeout((function(){a.print()}),500),r(t,e)})).catch((function(t){console.error("[auto-print] Browser print failed:",t)}))}function r(t,e){fetch("/pos/api/quotations/"+t+"/mark-printed",{method:"POST",headers:{Authorization:"Bearer "+e}}).catch((function(){}))}(window.startAutoPrint=function(){if(!o){0;var t=localStorage.getItem("pos_token");t&&(o=setInterval((function(){fetch("/pos/api/quotations/print-queue",{headers:{Authorization:"Bearer "+t}}).then((function(t){return t.json()})).then((function(e){e.data&&e.data.length&&e.data.forEach((function(e){console.log("[auto-print] Cotización #"+e.id+" confirmada por WhatsApp — imprimiendo..."),showToast("🖨️ Imprimiendo cotización #"+e.id+" (WhatsApp)","ok"),function(t,e){"undefined"!=typeof NexusPrinter&&NexusPrinter.isConnected&&NexusPrinter.isConnected()?fetch("/pos/api/quotations/"+t+"/print",{method:"POST",headers:{Authorization:"Bearer "+e,"Content-Type":"application/json"},body:JSON.stringify({printer_type:"escpos_raw",width:80})}).then((function(t){return t.arrayBuffer()})).then((function(o){NexusPrinter.sendRaw(new Uint8Array(o)),r(t,e)})).catch((function(o){console.error("[auto-print] Thermal print failed:",o),n(t,e)})):n(t,e)}(e.id,t)}))})).catch((function(){}))}),15e3),console.log("[auto-print] Enabled — polling every 15s"))}},window.stopAutoPrint=function(){o&&(clearInterval(o),o=null)},-1!==window.location.pathname.indexOf("/pos/sale")||-1!==window.location.pathname.indexOf("/pos/quotation")||-1!==window.location.pathname.indexOf("/pos/dashboard"))&&(localStorage.getItem("pos_token")&&setTimeout((function(){startAutoPrint()}),3e3));if(!document.getElementById("pos-utils-styles")){var a=document.createElement("style");a.id="pos-utils-styles",a.textContent="@keyframes slideInRight{from{transform:translateX(100%);opacity:0}to{transform:translateX(0);opacity:1}}.filter-panel select:focus{outline:none;border-color:var(--color-primary,#F5A623);box-shadow:0 0 0 2px var(--glow-color-soft,rgba(245,166,35,0.15));}",document.head.appendChild(a)}}();