import{r as e}from"./chunk-qMK8H_w0.js";import{t}from"./browser-DwUZlnhy.js";import{An as n,Lt as r,Nn as i,P as a,Qt as o,W as s,_n as c,an as l,bn as u,dn as d,en as f,mn as p,nn as m,on as h,rn as g,tn as _,vn as v,wn as y}from"./app-4kCgdoJR.js";import{t as b}from"./AdminLayout-DEe0k-dp.js";var x=e(t()),S={class:`p-4`},C={key:0,class:`rounded-xl border border-gray-200 bg-white p-12 text-center dark:border-gray-700 dark:bg-gray-800`},w={class:`mt-4 text-gray-500 dark:text-gray-400`},T={class:`mb-3 flex items-center justify-between`},E={class:`text-lg font-bold text-gray-900 dark:text-gray-100`},D={key:0,class:`rounded-lg border border-gray-200 bg-white p-6 text-center text-gray-400 dark:border-gray-700 dark:bg-gray-800`},O={class:`grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4`},k={class:`rounded-t-xl border-b border-gray-100 px-4 py-3 dark:border-gray-700`},A={class:`font-bold text-gray-900 dark:text-gray-100`},j={class:`text-xs text-gray-500`},M={class:`flex items-center justify-center rounded-b-xl bg-white p-4`},N=[`id`],P={class:`flex items-center justify-center gap-2 rounded-b-xl border-t border-gray-100 px-4 py-3 dark:border-gray-700 print:hidden`},F=[`onClick`,`title`],I=[`onClick`,`title`],L=Object.assign({layout:b},{__name:`Index`,props:{halls:Array,app_name:String},setup(e){let t=e,b=async(e,t)=>{await d();let n=document.getElementById(`qr-`+e);n&&await x.toCanvas(n,t,{width:200,margin:2,color:{dark:`#000000`,light:`#ffffff`}})},L=async()=>{for(let e of t.halls)for(let t of e.tables)await b(t.id,t.menu_url)};p(()=>{L()});let R=async e=>{let n=[];for(let t of e.tables){let e=await x.toDataURL(t.menu_url,{width:300,margin:2});n.push({table:t,dataUrl:e})}let r=n.map(({table:t,dataUrl:n})=>`
      <div class="card">
        <h3>${t.name}</h3>
        <p>${e.name} &middot; ${t.seats} seats</p>
        <img src="${n}" alt="QR Code">
        <div class="scan-text">Scan to Order</div>
      </div>
    `).join(``),i=window.open(``,`_blank`);i.document.write(`
    <!DOCTYPE html>
    <html>
    <head>
      <title>${t.app_name} - ${e.name} QR Codes</title>
      <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: system-ui, -apple-system, sans-serif; padding: 20px; }
        .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
        .card { border: 2px solid #e5e7eb; border-radius: 12px; padding: 20px; text-align: center; page-break-inside: avoid; }
        .card h3 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
        .card p { font-size: 13px; color: #6b7280; margin-bottom: 12px; }
        .card img { max-width: 180px; margin: 0 auto 12px; display: block; }
        .card .scan-text { font-size: 14px; font-weight: 600; color: #2563eb; }
        .header { text-align: center; margin-bottom: 24px; }
        .header h1 { font-size: 22px; font-weight: 700; }
        .header p { font-size: 14px; color: #6b7280; }
        @media print { .grid { grid-template-columns: repeat(2, 1fr); } }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>${t.app_name}</h1>
        <p>${e.name}</p>
      </div>
      <div class="grid">${r}</div>
    </body>
    </html>
  `),i.document.close(),setTimeout(()=>{i.print(),i.close()},500)},z=async e=>{let n=t.halls.find(t=>t.tables.some(t=>t.id===e.id))?.name||``,r=await x.toDataURL(e.menu_url,{width:300,margin:2}),i=window.open(``,`_blank`);i.document.write(`
    <!DOCTYPE html>
    <html>
    <head>
      <title>${t.app_name} - ${e.name}</title>
      <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: system-ui, -apple-system, sans-serif; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
        .card { text-align: center; padding: 40px; }
        .card h2 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
        .card p { font-size: 14px; color: #6b7280; margin-bottom: 16px; }
        .card img { max-width: 300px; margin: 0 auto 16px; display: block; }
        .card .scan-text { font-size: 18px; font-weight: 600; color: #2563eb; }
      </style>
    </head>
    <body>
      <div class="card">
        <h2>${e.name}</h2>
        <p>${n} &middot; ${t.app_name}</p>
        <img src="${r}" alt="QR Code">
        <div class="scan-text">Scan to Order</div>
      </div>
    </body>
    </html>
  `),i.document.close(),setTimeout(()=>{i.print(),i.close()},500)},B=async e=>{try{let{data:t}=await s.post(r(`pos.qr-codes.regenerate`,e.id));t.success&&(e.qr_token=t.qr_token,e.menu_url=t.menu_url,await b(e.id,t.menu_url))}catch(e){console.error(`Failed to regenerate QR code`,e)}};return(t,r)=>{let s=u(`Head`),d=u(`Header`);return c(),g(o,null,[h(s,null,{default:y(()=>[f(`title`,null,i(t.$t(`QR Codes`)),1)]),_:1}),h(d,{class:`print:hidden`},{subheading:y(()=>[l(i(t.$t(`Generate and print QR codes for restaurant tables`)),1)]),default:y(()=>[l(i(t.$t(`QR Codes`))+` `,1)]),_:1}),f(`div`,S,[e.halls.length===0?(c(),g(`div`,C,[r[0]||=f(`svg`,{class:`mx-auto h-12 w-12 text-gray-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`},[f(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`1.5`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z`})],-1),f(`p`,w,i(t.$t(`No halls or tables found. Please create halls and tables first.`)),1)])):m(``,!0),(c(!0),g(o,null,v(e.halls,e=>(c(),g(`div`,{key:e.id,class:`mb-6`},[f(`div`,T,[f(`h2`,E,i(e.name),1),e.tables.length>0?(c(),_(n(a),{key:0,onClick:t=>R(e),class:`gap-2 print:hidden`},{default:y(()=>[r[1]||=f(`svg`,{class:`h-4 w-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`},[f(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z`})],-1),l(` `+i(t.$t(`Print All`)),1)]),_:1},8,[`onClick`])):m(``,!0)]),e.tables.length===0?(c(),g(`div`,D,i(t.$t(`No tables in this hall`)),1)):m(``,!0),f(`div`,O,[(c(!0),g(o,null,v(e.tables,e=>(c(),g(`div`,{key:e.id,class:`overflow-hidden rounded-xl border border-gray-200 bg-white text-center dark:border-gray-700 dark:bg-gray-800`},[f(`div`,k,[f(`h3`,A,i(e.name),1),f(`p`,j,i(e.seats)+` `+i(t.$t(`seats`)),1)]),f(`div`,M,[f(`canvas`,{id:`qr-`+e.id,class:`rounded`},null,8,N)]),f(`div`,P,[f(`button`,{onClick:t=>z(e),type:`button`,title:t.$t(`Print`),class:`inline-flex items-center gap-1 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600`},[r[2]||=f(`svg`,{class:`h-3.5 w-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`},[f(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z`})],-1),l(` `+i(t.$t(`Print`)),1)],8,F),f(`button`,{onClick:t=>B(e),type:`button`,title:t.$t(`Regenerate`),class:`inline-flex items-center gap-1 rounded-lg border border-gray-300 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 transition hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600`},[r[3]||=f(`svg`,{class:`h-3.5 w-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`},[f(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15`})],-1),l(` `+i(t.$t(`Regenerate`)),1)],8,I)])]))),128))])]))),128))])],64)}}});export{L as default};