import { t as __exportAll } from "./rolldown-runtime-rSIU-vHC.js";
import { $ as $number, J as $datetime, K as $currency, Q as $meta, W as $address, X as $decimal_qty, et as $number_qty, q as $date } from "../ssr.js";
import { usePage } from "@inertiajs/vue3";
import { computed, onMounted, resolveComponent, unref, useSSRContext } from "vue";
import { useI18n } from "vue-i18n";
import { ssrInterpolate, ssrRenderAttr, ssrRenderAttrs, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/Sma/Pos/Components/PrintReceipt.vue
var PrintReceipt_exports = /* @__PURE__ */ __exportAll({ default: () => _sfc_main });
var _sfc_main = {
	__name: "PrintReceipt",
	__ssrInlineRender: true,
	props: [
		"receipt",
		"show",
		"sendPrint",
		"halls"
	],
	setup(__props) {
		const page = usePage();
		const { t } = useI18n({});
		const props = __props;
		const tables = computed(() => {
			return props.halls.find((h) => h.id === props.receipt.hall_id)?.tables || [];
		});
		onMounted(() => {
			if (page.props.settings?.print_dialog == 1) setTimeout(print, 250);
		});
		function print() {
			if (page.props.settings?.pos_server == 1) {
				const data = {
					type: "print-json-receipt",
					data: {}
				};
				data.data.logo = props.receipt.store.logo || page.props.settings?.logo || "";
				data.data.heading = page.props.settings?.name;
				data.data.store_heading = props.receipt.store.name || "";
				data.data.store_details = {};
				data.data.store_details["name"] = props.receipt.store.name || "";
				data.data.store_details["email"] = props.receipt.store.email ? t("Email") + ": " + props.receipt.store.email : "";
				data.data.store_details["phone"] = props.receipt.store.phone ? t("Phone") + ": " + props.receipt.store.phone : "";
				data.data.store_details["address"] = props.receipt.store?.address ? $address(props.receipt.store) : "";
				data.data.type = t("Receipt");
				data.data.headers = [page.props.settings?.receipt_header || null, props.receipt.store?.header || null];
				data.data.info = [
					[t("Id"), props.receipt.id || ""],
					[t("Date"), props.receipt.date ? $date(props.receipt.date) : $date(props.receipt.created_at)],
					[t("Ref"), props.receipt.reference],
					[t("Order No."), props.receipt.number],
					[t("Customer"), props.receipt.customer?.company || props.receipt.customer?.name || ""],
					[t("Created by"), props.receipt.user?.name || page.props.auth?.user?.name || ""],
					[t("Created at"), props.receipt.created_at ? $datetime(props.receipt.created_at) : $datetime((/* @__PURE__ */ new Date()).toISOString(), null, null, true)]
				];
				data.data.table_headers = [
					{ label: t("Description") },
					{ label: t("Price") },
					{ label: t("Qty") },
					{ label: t("Subtotal") }
				];
				let items = props.receipt.items.map((item) => {
					if (item.variations && item.variations.length) {
						const variations = item.variations.map((variation) => ({
							type: "item",
							name: $meta(variation.meta),
							qty: $number_qty(variation.quantity),
							price: $number(variation.price),
							subtotal: $number(variation.total)
						}));
						return { variations: [{
							type: "text",
							text: item.product.name + (item.comment ? "\n" + item.comment : "")
						}, ...variations] };
					} else return {
						type: "item",
						name: item.product.name + (item.comment ? "\n" + item.comment : ""),
						qty: $decimal_qty(item.quantity),
						price: $number(item.price),
						subtotal: $number(item.total)
					};
				});
				const variations = items.filter((i) => i.variations).map((i) => i.variations);
				const simpleItems = items.filter((i) => !i.variations);
				items = [...variations.flat(), ...simpleItems];
				data.data.items = [items];
				data.data.totals = [
					{
						label: t("Total"),
						value: $currency(props.receipt.total)
					},
					{
						label: t("Discount"),
						value: $currency(props.receipt.total_discount_amount)
					},
					{
						label: t("Tax"),
						value: $currency(props.receipt.total_tax_amount)
					},
					{
						label: t("Grand Total"),
						value: $currency(props.receipt.grand_total)
					},
					{
						label: t("Paid"),
						value: $currency(props.receipt.paid)
					},
					{
						label: t("Balance"),
						value: $currency(props.receipt.grand_total - props.receipt.paid)
					},
					Number(props.receipt.tendered) > 0 ? {
						label: t("Tender Amount"),
						value: $currency(props.receipt.tendered)
					} : null,
					Number(props.receipt.tendered) > 0 ? {
						label: t("Return Amount"),
						value: $currency(props.receipt.change_returned)
					} : null
				];
				data.data.footers = [
					props.receipt.details || null,
					page.props.settings?.receipt_footer || null,
					props.receipt.store?.footer || null
				];
				props.sendPrint(data);
			} else window.print();
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Icon = resolveComponent("Icon");
			_push(`<div${ssrRenderAttrs(_attrs)}><div class="border-b border-gray-200 p-4 sm:px-6 dark:border-gray-700 print:hidden"><div class="absolute end-8 top-0 flex items-center gap-3 pe-4 pt-4"><button type="button" class="focus relative rounded-md text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"><span class="absolute -inset-2.5"></span><span class="sr-only">${ssrInterpolate(_ctx.$t("Print"))}</span>`);
			_push(ssrRenderComponent(_component_Icon, {
				name: "print-o",
				className: "size-6"
			}, null, _parent));
			_push(`</button></div><div><h3 class="text-base leading-6 font-semibold text-gray-900 dark:text-gray-100">${ssrInterpolate(_ctx.$t("Print Receipt"))}</h3></div></div>`);
			if (__props.receipt && __props.receipt.items && __props.receipt.items.length) {
				_push(`<div class="m-6 flex flex-col gap-4"><div class="text-center">`);
				if (__props.receipt.store.logo) _push(`<img class="h-8 max-w-[200pc]"${ssrRenderAttr("src", __props.receipt.store.logo)} alt="Logo">`);
				else _push(`<h2 class="text-center text-lg font-bold">${ssrInterpolate(__props.receipt.store.name || _ctx.settings.name)}</h2>`);
				if (__props.receipt.store?.address) _push(`<div>${ssrInterpolate(__props.receipt.store.address || "")}</div>`);
				else _push(`<!---->`);
				if (__props.receipt.store?.phone) _push(`<div>${ssrInterpolate(_ctx.$t("Phone"))}: ${ssrInterpolate(__props.receipt.store.phone || "")}</div>`);
				else _push(`<!---->`);
				if (__props.receipt.store?.email) _push(`<div>${ssrInterpolate(_ctx.$t("Email"))}: ${ssrInterpolate(__props.receipt.store.email || "")}</div>`);
				else _push(`<!---->`);
				_push(`</div>`);
				if (_ctx.$page.props.settings?.receipt_header) _push(`<div class="text-center">${ssrInterpolate(_ctx.$page.props.settings?.receipt_header)}</div>`);
				else _push(`<!---->`);
				if (__props.receipt.store?.header) _push(`<div class="text-center">${ssrInterpolate(__props.receipt.store.header || "")}</div>`);
				else _push(`<!---->`);
				_push(`<h2 class="text-center text-lg font-bold">${ssrInterpolate(_ctx.$t("Receipt"))}</h2><div><div>${ssrInterpolate(_ctx.$t("Sale No."))}: ${ssrInterpolate(__props.receipt.id || "")}</div><div>${ssrInterpolate(_ctx.$t("Customer"))}: ${ssrInterpolate(__props.receipt.customer?.name || "")}</div><div>${ssrInterpolate(_ctx.$t("Reference"))}: ${ssrInterpolate(__props.receipt.reference)}</div><div>${ssrInterpolate(_ctx.$t("Order Number"))}: #${ssrInterpolate(__props.receipt.order_number)}</div>`);
				if (__props.receipt.table) _push(`<div>${ssrInterpolate(_ctx.$t("Table"))}: ${ssrInterpolate(__props.receipt.table?.name || tables.value.find((table) => table.id == __props.receipt.table_id)?.name || "")} (${ssrInterpolate(__props.receipt.hall?.name || __props.halls.find((hall) => hall.id == __props.receipt.hall_id)?.name || "Main")}) </div>`);
				else _push(`<!---->`);
				_push(`<div>${ssrInterpolate(_ctx.$t("Created at"))}: ${ssrInterpolate(__props.receipt.created_at ? unref($datetime)(__props.receipt.created_at) : unref($datetime)((/* @__PURE__ */ new Date()).toISOString(), null, null, true))}</div><div>${ssrInterpolate(_ctx.$t("Created  by"))}: ${ssrInterpolate(__props.receipt.user?.name || "")}</div></div><div class="-mx-2"><table class="w-full divide-y divide-gray-200 dark:divide-gray-700 print:divide-gray-400 dark:print:divide-gray-400"><thead><tr><th class="px-2 py-0.5 text-start">${ssrInterpolate(_ctx.$t("Description"))}</th><th class="w-10 px-2 py-0.5 text-center">${ssrInterpolate(_ctx.$t("Qty"))}</th><th class="w-10 px-2 py-0.5 text-center">${ssrInterpolate(_ctx.$t("Price"))}</th><th class="w-10 px-2 py-0.5 text-center">${ssrInterpolate(_ctx.$t("Total"))}</th></tr></thead><!--[-->`);
				ssrRenderList(__props.receipt.items, (item) => {
					_push(`<!--[-->`);
					if (item.variations && item.variations.length) {
						_push(`<tbody><tr><td class="px-2 py-0.5 text-start">${ssrInterpolate(item.product.name)} `);
						if (item.comment) _push(`<div class="pb-1 text-xs">${ssrInterpolate(item.comment)}</div>`);
						else _push(`<!---->`);
						_push(`</td><td class="w-10 px-2 py-0.5 text-center"></td><td class="w-10 px-2 py-0.5 text-end"></td><td class="w-10 px-2 py-0.5 text-end"></td></tr><!--[-->`);
						ssrRenderList(item.variations, (variation) => {
							_push(`<tr><td class="px-2 py-0.5 text-start">${ssrInterpolate(unref($meta)(variation.meta))}</td><td class="w-10 px-2 py-0.5 text-center"><div class="flex">${ssrInterpolate(unref($number_qty)(variation.pivot.quantity))}${ssrInterpolate(variation.pivot?.unit?.code || "")}</div></td><td class="w-10 px-2 py-0.5 text-end">${ssrInterpolate(unref($number)(variation.pivot.price))}</td><td class="p&lt;/template&gt;y-0.5 w-10 px-2 text-end">${ssrInterpolate(unref($number)(variation.pivot.total))}</td></tr>`);
						});
						_push(`<!--]--></tbody>`);
					} else {
						_push(`<!--[-->`);
						if (item.quantity > 0) {
							_push(`<tbody><tr><td class="px-2 py-0.5 text-start">`);
							if (item.type == "Gift Card") _push(`<div class="flex items-center">${ssrInterpolate(_ctx.$t("Gift Card"))} <span class="ms-1 text-xs font-bold">(${ssrInterpolate(item.code)})</span></div>`);
							else {
								_push(`<!--[-->${ssrInterpolate(item.product?.name)} `);
								if (item.comment) _push(`<div class="pb-1 text-xs">${ssrInterpolate(item.comment)}</div>`);
								else _push(`<!---->`);
								_push(`<!--]-->`);
							}
							_push(`</td><td class="w-10 px-2 py-0.5 text-center"><div class="flex">${ssrInterpolate(unref($number_qty)(item.quantity))}${ssrInterpolate(item.unit?.code || "")}</div></td><td class="w-10 px-2 py-0.5 text-end">${ssrInterpolate(unref($number)(item.price))}</td><td class="w-10 px-2 py-0.5 text-end">${ssrInterpolate(unref($number)(item.total))}</td></tr></tbody>`);
						} else _push(`<!---->`);
						_push(`<!--]-->`);
					}
					_push(`<!--]-->`);
				});
				_push(`<!--]--><tfoot><tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Total"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.total))}</th></tr>`);
				if (__props.receipt.discount_amount > 0) _push(`<tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Discount"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.discount_amount))}</th></tr>`);
				else _push(`<!---->`);
				if (__props.receipt.total_tax_amount > 0) _push(`<tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Tax"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.total_tax_amount))}</th></tr>`);
				else if (unref(page).props.settings.show_zero_taxes == 1) _push(`<tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Tax"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.total_tax_amount))}</th></tr>`);
				else _push(`<!---->`);
				if (Number(__props.receipt.total_tax_amount) > 0 || Number(__props.receipt.discount_amount) > 0 || Number(__props.receipt.total) != Number(__props.receipt.grand_total)) _push(`<tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Grand Total"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.grand_total))}</th></tr>`);
				else _push(`<!---->`);
				_push(`<tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Paid"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.paid))}</th></tr><tr><th colspan="3" class="px-2 py-0.5 text-end">${ssrInterpolate(_ctx.$t("Balance"))}</th><th class="w-10 px-2 py-0.5 text-end whitespace-nowrap">${ssrInterpolate(unref($number)(__props.receipt.grand_total - __props.receipt.paid))}</th></tr></tfoot></table></div>`);
				if (Number(__props.receipt.tendered) > 0) _push(`<div><div>${ssrInterpolate(_ctx.$t("Tender Amount"))}: ${ssrInterpolate(unref($number)(__props.receipt.tendered))}</div><div>${ssrInterpolate(_ctx.$t("Return Amount"))}: ${ssrInterpolate(unref($number)(__props.receipt.change_returned))}</div></div>`);
				else _push(`<!---->`);
				if (__props.receipt.details) _push(`<div class="text-center">${ssrInterpolate(__props.receipt.details || "")}</div>`);
				else _push(`<!---->`);
				if (__props.receipt.store?.footer) _push(`<div class="text-center">${ssrInterpolate(__props.receipt.store.footer || "")}</div>`);
				else _push(`<!---->`);
				if (_ctx.$page.props.settings?.receipt_footer) _push(`<div class="text-center">${ssrInterpolate(_ctx.$page.props.settings?.receipt_footer)}</div>`);
				else _push(`<!---->`);
				_push(`</div>`);
			} else _push(`<!---->`);
			_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/Components/PrintReceipt.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as n, PrintReceipt_exports as t };
