import{a7 as k,g as R,aC as O,R as I,aD as P,a5 as M,aE as L,aF as D,T as C,a8 as T,a9 as N,b as V}from"../index.js";var w={exports:{}};(function(o,e){Object.defineProperty(e,"__esModule",{value:!0});var c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol?"symbol":typeof t};e.default={onScan:function(){var u=arguments.length<=0||arguments[0]===void 0?{}:arguments[0],s=u.barcodePrefix,i=u.barcodeValueTest,n=u.finishScanOnMatch,r=u.scanDuration,a=arguments[1];if(typeof s!="string")throw new TypeError("barcodePrefix must be a string");if((typeof i>"u"?"undefined":c(i))!=="object"||typeof i.test!="function")throw new TypeError("barcodeValueTest must be a regular expression");if(n!=null&&typeof n!="boolean")throw new TypeError("finishScanOnMatch must be a boolean");if(r&&typeof r!="number")throw new TypeError("scanDuration must be a number");if(typeof a!="function")throw new TypeError("scanHandler must be a function");r=r||50;var l=null,v="",m="",S=!1,y=function(){S&&i.test(m)&&a(m),x()},x=function(){l=null,v="",m="",S=!1},b=function(g){var f=String.fromCharCode(g.which),p=s.indexOf(f),E=s.slice(0,p);l||(l=setTimeout(y,r)),v===E&&f===s.charAt(p)?v+=f:(S||s==="")&&(m+=f),v===s&&(S=!0,n&&i.test(m)&&(clearTimeout(l),y()))},d=function(){document.removeEventListener("keypress",b)};return document.addEventListener("keypress",b),d}},o.exports=e.default})(w,w.exports);var _=k(w.exports);function A(o,e){if(o.length>1||!R("pos","keyboard_shortcuts"))return;const c=O(),t=I(),u=P(),s=M(),i=L(),n=D(),r=N(),a=c.operatingMode,l=!u.cart_contents.size,v=()=>{!n.enableScanProduct||e.currentRoute.value.name!=="products"?(n.enableScanProduct=!0,e.push({name:"products"})):n.enableScanProduct=!1},m=()=>{if(a==="cart"){if(l){r(C(104),"error");return}t.initCheckout({amount:T(u.total),mode:"hold"})}},S=()=>{if(a==="cart"){if(l){r(C(104),"error");return}t.initCheckout({amount:T(u.total),mode:"default"})}if(a==="order"&&t.initCheckout({amount:T(s.order.total),mode:"pay"}),a==="refund"){if(!i.amount){r(C(385),"error");return}t.initCheckout({amount:i.amount,mode:"refund"})}};function y(){c.productAddModal=!0}function x(){P().clearCart(!0)}function b(f){var E;const p=document==null?void 0:document.getElementById(f);p&&((E=p==null?void 0:p.querySelector("input"))==null||E.focus())}function d(f){e.push({name:f})}const h=o.toUpperCase(),g={B:v,C:()=>d("coupon"),D:()=>d("discount"),F:()=>d("fee"),H:m,L:()=>b("productSearch"),N:()=>d("note"),O:()=>d("orders"),P:y,R:()=>d("products"),S:()=>d("shipping"),T:S,U:()=>b("customerSearch"),V:x};h in g&&g[h]()}function B(o){var e;!!(navigator!=null&&navigator.mediaDevices)&&!!((e=navigator.mediaDevices)!=null&&e.enumerateDevices)&&navigator.mediaDevices.enumerateDevices().then(c=>{c.length&&(o.videoInputDevices=c.filter(t=>t.kind==="videoinput").map(t=>({label:t.label,id:t.deviceId})))}).catch(c=>{window.console.error(c)})}function H(o,e){const c=()=>{var a;const n=((a=document.activeElement)==null?void 0:a.tagName)||"";return!!["INPUT","TEXTAREA"].includes(n)},t=()=>{const n=e.currentRoute.value.name||"";return!!["login","403","404"].includes(n)},u=n=>n.length===1?(A(n,e),!0):!1,s=()=>{if(o.enableScanCustomer)return"customer-scan";if(o.enableScanCustomerCard)return"customer-card-scan";if(o.enableScanNewProduct)return"new-product-scan";if(e.currentRoute.value.name==="products"&&o.enableScanProduct)return"product-scan";if(e.currentRoute.value.name==="products"&&!o.enableScanProduct)return"product-scan-ignored";if(e.currentRoute.value.name==="orders")return"order-scan";if(e.currentRoute.value.name==="coupon")return"coupon-scan"},i={barcodePrefix:"",barcodeValueTest:/.*/,finishScanOnMatch:!1,scanDuration:500};_.onScan(i,async n=>{const r=n.trim();if(!r||c()||t()||u(r))return;const a=s();a&&window.emitter.emit(a,r)})}var U=V(({router:o})=>{const e=D();B(e),H(e,o)});export{U as default};
