import "./index.esm-0G7eAEV5.js";
import { k as _sfc_main$1 } from "../ssr.js";
import { t as _sfc_main$2 } from "./AdminLayout-eZgRfDMK.js";
import { createBlock, createTextVNode, createVNode, nextTick, onMounted, openBlock, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderAttr, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
import QRCode from "qrcode";
//#region resources/js/Pages/Sma/Pos/QrCode/Index.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$2 }, {
	__name: "Index",
	__ssrInlineRender: true,
	props: {
		halls: Array,
		app_name: String
	},
	setup(__props) {
		const props = __props;
		const generateQrCode = async (tableId, url) => {
			await nextTick();
			const canvas = document.getElementById("qr-" + tableId);
			if (canvas) await QRCode.toCanvas(canvas, url, {
				width: 200,
				margin: 2,
				color: {
					dark: "#000000",
					light: "#ffffff"
				}
			});
		};
		const generateAllQrCodes = async () => {
			for (const hall of props.halls) for (const table of hall.tables) await generateQrCode(table.id, table.menu_url);
		};
		onMounted(() => {
			generateAllQrCodes();
		});
		const printHall = async (hall) => {
			const qrImages = [];
			for (const table of hall.tables) {
				const dataUrl = await QRCode.toDataURL(table.menu_url, {
					width: 300,
					margin: 2
				});
				qrImages.push({
					table,
					dataUrl
				});
			}
			const cardsHtml = qrImages.map(({ table, dataUrl }) => `
      <div class="card">
        <h3>${table.name}</h3>
        <p>${hall.name} &middot; ${table.seats} seats</p>
        <img src="${dataUrl}" alt="QR Code">
        <div class="scan-text">Scan to Order</div>
      </div>
    `).join("");
			const printWindow = window.open("", "_blank");
			printWindow.document.write(`
    <!DOCTYPE html>
    <html>
    <head>
      <title>${props.app_name} - ${hall.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>${props.app_name}</h1>
        <p>${hall.name}</p>
      </div>
      <div class="grid">${cardsHtml}</div>
    </body>
    </html>
  `);
			printWindow.document.close();
			setTimeout(() => {
				printWindow.print();
				printWindow.close();
			}, 500);
		};
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			const _component_Header = resolveComponent("Header");
			_push(`<!--[-->`);
			_push(ssrRenderComponent(_component_Head, null, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`<title${_scopeId}>${ssrInterpolate(_ctx.$t("QR Codes"))}</title>`);
					else return [createVNode("title", null, toDisplayString(_ctx.$t("QR Codes")), 1)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(_component_Header, { class: "print:hidden" }, {
				subheading: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Generate and print QR codes for restaurant tables"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Generate and print QR codes for restaurant tables")), 1)];
				}),
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("QR Codes"))} `);
					else return [createTextVNode(toDisplayString(_ctx.$t("QR Codes")) + " ", 1)];
				}),
				_: 1
			}, _parent));
			_push(`<div class="p-4">`);
			if (__props.halls.length === 0) _push(`<div class="rounded-xl border border-gray-200 bg-white p-12 text-center dark:border-gray-700 dark:bg-gray-800"><svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor"><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"></path></svg><p class="mt-4 text-gray-500 dark:text-gray-400">${ssrInterpolate(_ctx.$t("No halls or tables found. Please create halls and tables first."))}</p></div>`);
			else _push(`<!---->`);
			_push(`<!--[-->`);
			ssrRenderList(__props.halls, (hall) => {
				_push(`<div class="mb-6"><div class="mb-3 flex items-center justify-between"><h2 class="text-lg font-bold text-gray-900 dark:text-gray-100">${ssrInterpolate(hall.name)}</h2>`);
				if (hall.tables.length > 0) _push(ssrRenderComponent(unref(_sfc_main$1), {
					onClick: ($event) => printHall(hall),
					class: "gap-2 print:hidden"
				}, {
					default: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(`<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"${_scopeId}><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"${_scopeId}></path></svg> ${ssrInterpolate(_ctx.$t("Print All"))}`);
						else return [(openBlock(), createBlock("svg", {
							class: "h-4 w-4",
							fill: "none",
							viewBox: "0 0 24 24",
							stroke: "currentColor"
						}, [createVNode("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"
						})])), createTextVNode(" " + toDisplayString(_ctx.$t("Print All")), 1)];
					}),
					_: 2
				}, _parent));
				else _push(`<!---->`);
				_push(`</div>`);
				if (hall.tables.length === 0) _push(`<div class="rounded-lg border border-gray-200 bg-white p-6 text-center text-gray-400 dark:border-gray-700 dark:bg-gray-800">${ssrInterpolate(_ctx.$t("No tables in this hall"))}</div>`);
				else _push(`<!---->`);
				_push(`<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4"><!--[-->`);
				ssrRenderList(hall.tables, (table) => {
					_push(`<div class="overflow-hidden rounded-xl border border-gray-200 bg-white text-center dark:border-gray-700 dark:bg-gray-800"><div class="rounded-t-xl border-b border-gray-100 px-4 py-3 dark:border-gray-700"><h3 class="font-bold text-gray-900 dark:text-gray-100">${ssrInterpolate(table.name)}</h3><p class="text-xs text-gray-500">${ssrInterpolate(table.seats)} ${ssrInterpolate(_ctx.$t("seats"))}</p></div><div class="flex items-center justify-center rounded-b-xl bg-white p-4"><canvas${ssrRenderAttr("id", "qr-" + table.id)} class="rounded"></canvas></div><div 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"><button type="button"${ssrRenderAttr("title", _ctx.$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"><svg class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><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"></path></svg> ${ssrInterpolate(_ctx.$t("Print"))}</button><button type="button"${ssrRenderAttr("title", _ctx.$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"><svg class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><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"></path></svg> ${ssrInterpolate(_ctx.$t("Regenerate"))}</button></div></div>`);
				});
				_push(`<!--]--></div></div>`);
			});
			_push(`<!--]--></div><!--]-->`);
		};
	}
});
var _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
	const ssrContext = useSSRContext();
	(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("resources/js/Pages/Sma/Pos/QrCode/Index.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
