import{b as e,a as t,j as r,F as a}from"./index-7ac36ca7.js";import{r as n}from"./vendor-1f283eff.js";const s=({isOpen:s,onClose:i,onPrinterSelected:l,onPrint:c})=>{const[d,o]=n.useState([]),[m,p]=n.useState(""),[h,u]=n.useState(!1),[b,g]=n.useState("");n.useEffect(()=>{s&&y()},[s]);const y=async()=>{u(!0),g("");try{await e.detectAndConnectPrinter();const t=e.getAvailablePrinters();o(t),0===t.length&&g("No printers found. Please connect a printer and try again.")}catch(t){g("Failed to detect printers: "+t.message)}finally{u(!1)}},x=e=>{switch(e){case"usb":return"🔌";case"network":return"🌐";case"browser":return"🖨️";default:return"❓"}},w=e=>{switch(e.type){case"usb":return"Direct USB thermal printer connection";case"network":return"Network printer via IP address";case"browser":return"Use browser print dialog (works with any printer)";default:return"Unknown printer type"}};return s?t("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",children:t("div",{className:"bg-white rounded-lg shadow-xl max-w-md w-full max-h-[90vh] overflow-y-auto",children:r("div",{className:"p-6",children:[r("div",{className:"flex justify-between items-center mb-4",children:[t("h2",{className:"text-xl font-bold text-gray-900",children:"Select Printer"}),t("button",{onClick:i,className:"text-gray-400 hover:text-gray-600 text-2xl",children:"×"})]}),b&&t("div",{className:"mb-4 p-3 bg-red-100 border border-red-400 text-red-700 rounded",children:b}),h?r("div",{className:"text-center py-8",children:[t("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-2"}),t("p",{className:"text-gray-600",children:"Detecting printers..."})]}):r(a,{children:[d.length>0?r("div",{className:"space-y-3 mb-6",children:[t("p",{className:"text-sm text-gray-600 mb-3",children:"Choose a printer to print your receipt:"}),d.map(e=>r("label",{className:"block p-3 border rounded-lg cursor-pointer transition-colors "+(m===e.id?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"),children:[t("input",{type:"radio",name:"printer",value:e.id,checked:m===e.id,onChange:e=>p(e.target.value),className:"sr-only"}),r("div",{className:"flex items-start space-x-3",children:[t("span",{className:"text-2xl",children:x(e.type)}),r("div",{className:"flex-1",children:[t("div",{className:"font-medium text-gray-900",children:e.name}),t("div",{className:"text-sm text-gray-600",children:w(e)}),e.address&&r("div",{className:"text-xs text-gray-500 mt-1",children:["Address: ",e.address]})]})]})]},e.id))]}):r("div",{className:"text-center py-8",children:[t("p",{className:"text-gray-600 mb-4",children:"No printers detected"}),t("button",{onClick:async()=>{u(!0),g("");try{await e.requestPrinterAccess(),await y()}catch(t){g("Failed to access USB printer: "+t.message)}finally{u(!1)}},className:"bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors",children:"🔌 Connect USB Printer"})]}),r("div",{className:"flex space-x-3",children:[t("button",{onClick:y,disabled:h,className:"flex-1 bg-gray-100 text-gray-700 py-2 px-4 rounded-lg hover:bg-gray-200 transition-colors disabled:opacity-50",children:"🔄 Refresh"}),d.length>0&&t("button",{onClick:async()=>{if(m){u(!0),g("");try{await e.selectPrinter(m);const t=d.find(e=>e.id===m);l&&l(t),c&&await c(),i()}catch(t){g("Failed to connect to printer: "+t.message)}finally{u(!1)}}else g("Please select a printer")},disabled:!m||h,className:"flex-1 bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:h?"Connecting...":"Print Receipt"})]}),t("div",{className:"mt-4 p-3 bg-gray-50 rounded-lg",children:r("p",{className:"text-xs text-gray-600",children:[t("strong",{children:"Tip:"})," For USB thermal printers, make sure the printer is connected and powered on. For network printers, ensure they're on the same network. Browser printing works with any printer installed on your system."]})})]})]})})}):null};export{s as P};
