1import{aP as $,j as e,a7 as I,S as q,ap as M,I as L,a6 as D,a9 as P,aa as S,ab as N,T as f,aU as w,N as _,ad as B,z as A}from"./mui-CRsYZxVY.js";import{r as i}from"./vendor-Dwao9eNC.js";import{dt as W,eZ as c,e_ as F,c1 as G,e$ as V,T as Y,f0 as R,dN as H}from"./index-TALscxEc.js";import{d as k,B as U,a as O,b as Z}from"./BluetoothPermissionDialog-BXZtrYiq.js";import{d as J}from"./Refresh-C4waymBA.js";import"./query-8ViTdhdk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./lab-DSem1Osk.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new t.Error().stack;n&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[n]="def52988-0ab2-4e30-a4f5-acb0c0d43949",t._sentryDebugIdIdentifier="sentry-dbid-def52988-0ab2-4e30-a4f5-acb0c0d43949")})()}catch{}var z={},K=$;Object.defineProperty(z,"__esModule",{value:!0});var E=z.default=void 0,Q=K(W()),X=e;E=z.default=(0,Q.default)((0,X.jsx)("path",{d:"m7 12-2-2-2 2 2 2zm10.71-4.29L12 2h-1v7.59L6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 11 14.41V22h1l5.71-5.71-4.3-4.29zM13 5.83l1.88 1.88L13 9.59zm1.88 10.46L13 18.17v-3.76zM19 10l-2 2 2 2 2-2z"}),"BluetoothConnected");const ee=({onConnectionChanged:t})=>{var x;const[n,g]=i.useState({isConnected:c.isDeviceConnected(),device:c.getCurrentDevice(),error:null}),[m,l]=i.useState(!1),[v,a]=i.useState(!1),[d,p]=i.useState(!1);i.useEffect(()=>{const s=c.subscribeToConnectionStatus(o=>{g(o),t&&t(o.isConnected)});return()=>{s()}},[t]);const r=async()=>{if(G.isNativePlatform()&&!await V()){a(!0);return}l(!0)},h=()=>{n.isConnected||r()},u=async s=>{s.stopPropagation(),r()},j=async()=>{p(!0);try{const s=await c.initialize(!0);if(a(!1),!s){l(!0);return}await F(),l(!0)}catch(s){console.error("Error initializing after permission rationale:",s),a(!1),l(!0)}finally{p(!1)}},C=()=>{a(!1)},y=s=>{console.log("Printer selected:",s),l(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs(I,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(q,{icon:n.isConnected?e.jsx(E,{}):e.jsx(k,{}),label:d?"Inicializando...":n.isConnected?`Conectado: ${(x=n.device)==null?void 0:x.name}`:"Impressora não conectada",color:n.isConnected?"success":"default",variant:n.isConnected?"filled":"outlined",onClick:h,sx:{cursor:"pointer",height:32}}),e.jsx(M,{title:"Atualizar conexão",children:e.jsx(L,{size:"small",onClick:u,sx:{ml:.5},children:d?e.jsx(D,{size:18}):e.jsx(J,{fontSize:"small"})})})]}),e.jsx(U,{open:v,onClose:C,onContinue:j,loading:d}),e.jsx(O,{open:m,onClose:()=>l(!1),onPrinterConnected:y})]})},de=()=>{var s;const[t,n]=i.useState({isConnected:!1,device:null,error:null}),[g,m]=i.useState(!1),[l,v]=i.useState("Teste da impressora"),[a,d]=i.useState(!1),[p,r]=i.useState(null),[h,u]=i.useState(null);i.useEffect(()=>{(async()=>{try{await c.initialize()}catch(T){console.error("Error initializing printer service:",T)}})();const b=c.subscribeToConnectionStatus(T=>{n(T)});return()=>{b()}},[]);const j=()=>{m(!0)},C=async()=>{try{await c.disconnect(),u("Desconectado com sucesso"),setTimeout(()=>u(null),3e3)}catch(o){r(`Erro ao desconectar: ${o}`),setTimeout(()=>r(null),3e3)}},y=async()=>{if(!t.isConnected){r("Impressora não conectada"),setTimeout(()=>r(null),3e3);return}try{d(!0);const b=new H().initialize().align("center").bold(!0).width(2).text(l).width(1).bold(!1).newline().text(new Date().toLocaleString("pt-BR")).newline().newline().text("Teste realizado com sucesso!").newline().newline().cut("partial").encode();await c.printData(b),u("Texto impresso com sucesso"),setTimeout(()=>u(null),3e3)}catch(o){r(`Erro ao imprimir: ${o}`),setTimeout(()=>r(null),3e3)}finally{d(!1)}},x=async()=>{if(!t.isConnected){r("Impressora não conectada"),setTimeout(()=>r(null),3e3);return}try{d(!0);const o={pedido_id:123,numero_pedido:45678,data_pedido:new Date().toISOString(),status_pedido:"new",subtotal:84.95,valor_desconto:10,cliente:{nome:"Cliente Teste",telefone:"11999999999",profile_url:"",customer_user_id:""},cliente_id:1,endereco_entrega:{id:1,cep:"04500-000",logradouro:"Rua de Teste",bairro:"Bairro Teste",localidade:"São Paulo",uf:"SP",numero:"123",complemento:"Apto 45",nome_destinatario:"Cliente Teste"},frete_pedido:{id:1,tipo_frete:"frete_personalizado",valor_frete:15.5,transportadora:"Transportadora Teste",modalidade:"Expressa"},itens_pedido:[{produto_id:"123456",produto_variacao_id:1,quantidade:2,preco_snapshot:29.99,produto:{id:"123456",nome:"Produto Teste 1",image_url:[""],peso:.5},produto_variacao:{id:1,nome:"Variação 1",produto_variacao_valor:[{atributo_valor:{valor:"Azul",atributo:{nome:"Cor"}}},{atributo_valor:{valor:"M",atributo:{nome:"Tamanho"}}}],image_url:null}},{produto_id:"789012",produto_variacao_id:null,quantidade:1,preco_snapshot:24.97,produto:{id:"789012",nome:"Produto Teste 2 com um nome bem comprido para testar a quebra de linha na impressão",image_url:[""],peso:.3},produto_variacao:null}],cupom_codigo:"TESTE10",cupom_id:1,cupom_tipo_desconto:"valor",cupom_valor_desconto:10,cupom_aplicado_em:new Date().toISOString()};await c.printOrder({order:o,storeName:"Loja de Demonstração",paymentData:null}),u("Recibo de demonstração impresso com sucesso"),setTimeout(()=>u(null),3e3)}catch(o){r(`Erro ao imprimir recibo: ${o}`),setTimeout(()=>r(null),3e3)}finally{d(!1)}};return e.jsxs(I,{sx:{overflowY:"auto",height:"100%"},children:[e.jsx(Y,{title:"Impressora Bluetooth",navigateBack:!0}),e.jsxs(I,{sx:{p:2}
1,children:[e.jsxs(P,{sx:{mb:3},children:[e.jsxs(S,{children:[e.jsxs(N,{direction:"row",spacing:1,alignItems:"center",mb:1,children:[t.isConnected?e.jsx(E,{color:"success"}):e.jsx(k,{color:"disabled"}),e.jsx(f,{variant:"h6",children:"Status da impressora"})]}),e.jsx(f,{variant:"body1",mb:2,children:t.isConnected?`Conectado a: ${(s=t.device)==null?void 0:s.name}`:"Nenhuma impressora conectada"}),e.jsx(ee,{})]}),e.jsxs(w,{children:[e.jsx(_,{variant:"contained",color:"primary",onClick:j,startIcon:e.jsx(Z,{}),fullWidth:!0,children:"Conectar impressora"}),t.isConnected&&e.jsx(_,{variant:"outlined",color:"error",onClick:C,fullWidth:!0,children:"Desconectar"})]})]}),p&&e.jsx(B,{severity:"error",sx:{mb:2},children:p}),h&&e.jsx(B,{severity:"success",sx:{mb:2},children:h}),e.jsxs(P,{sx:{mb:3},children:[e.jsxs(S,{children:[e.jsx(f,{variant:"h6",mb:2,children:"Teste de impressão"}),e.jsx(A,{label:"Texto para teste",variant:"outlined",fullWidth:!0,value:l,onChange:o=>v(o.target.value),disabled:!t.isConnected||a,sx:{mb:2}})]}),e.jsx(w,{children:e.jsx(_,{variant:"contained",color:"primary",fullWidth:!0,onClick:y,disabled:!t.isConnected||a,startIcon:a?e.jsx(D,{size:20,color:"inherit"}):e.jsx(R,{}),children:a?"Imprimindo...":"Imprimir texto"})})]}),e.jsxs(P,{children:[e.jsxs(S,{children:[e.jsx(f,{variant:"h6",mb:1,children:"Demonstração de recibo"}),e.jsx(f,{variant:"body2",color:"text.secondary",mb:2,children:"Imprima um recibo de pedido de demonstração para testar o formato."})]}),e.jsx(w,{children:e.jsx(_,{variant:"contained",color:"success",fullWidth:!0,onClick:x,disabled:!t.isConnected||a,startIcon:a?e.jsx(D,{size:20,color:"inherit"}):e.jsx(R,{}),children:a?"Imprimindo...":"Imprimir recibo demo"})})]})]}),e.jsx(O,{open:g,onClose:()=>m(!1),onPrinterConnected:o=>{console.log("Printer connected:",o),m(!1)}})]})};export{de as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.