import { St as ApplicationMark_default, et as $number_qty, x as _sfc_main$1 } from "../ssr.js";
import { t as PosHelper } from "./PosHelper-DzTlIAyQ.js";
import { createVNode, nextTick, onMounted, ref, resolveComponent, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderAttr, ssrRenderComponent, ssrRenderList, ssrRenderStyle } from "vue/server-renderer";
import axios from "axios";
//#region resources/js/Pages/Sma/Pos/CustomerView.vue
var _sfc_main = {
	__name: "CustomerView",
	__ssrInlineRender: true,
	props: ["pos_settings"],
	setup(__props) {
		const { orderItems, OrderSummary } = PosHelper(__props);
		const form = ref({});
		const loading = ref(true);
		const customer = ref(null);
		onMounted(() => {
			form.value = JSON.parse(localStorage.getItem("pos.form") || "{}");
			if (form.value.customer_id && customer.value?.id != form.value.customer_id) getCustomer();
			loading.value = false;
			nextTick(() => {
				document.getElementById("order-items").scrollTop = document.getElementById("order-items").scrollHeight;
			});
			window.addEventListener("storage", (event) => {
				if (event.key === "pos.form") {
					form.value = JSON.parse(event.newValue || "{}");
					if (form.value.customer_id && customer.value?.id != form.value.customer_id) getCustomer();
					nextTick(() => {
						setTimeout(() => {
							document.getElementById("order-items").scrollTop = document.getElementById("order-items").scrollHeight;
						}, 300);
					});
				}
			});
		});
		function getCustomer() {
			if (form.value.customer) {
				customer.value = form.value.customer;
				return;
			}
			if (form.value.customer_id) axios.post(route("search.customers", { id: form.value.customer_id })).then((response) => {
				if (response.data.length == 1) customer.value = response.data[0];
			}).catch((error) => {
				console.error("Error fetching customer:", error);
			});
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			const _component_Link = resolveComponent("Link");
			_push(`<!--[-->`);
			_push(ssrRenderComponent(_component_Head, { title: "POS - Customer View" }, null, _parent));
			_push(`<div><div class="flex h-screen min-h-full flex-1 grow flex-col self-stretch">`);
			if (_ctx.loadingPage) _push(ssrRenderComponent(unref(_sfc_main$1), { class: "z-20" }, null, _parent));
			else _push(`<!---->`);
			_push(`<div class="flex max-h-full w-full grow items-stretch justify-stretch overflow-hidden"><div class="hidden max-h-full max-w-full flex-1 grow flex-col sm:flex print:hidden">`);
			if (_ctx.$page.props.settings?.customer_view_show_header == 1) {
				_push(`<header class="flex h-16 items-center border-b border-gray-200 bg-white text-gray-700 lg:static lg:overflow-y-visible dark:border-gray-800 dark:bg-gray-950 dark:text-gray-300"><div class="w-full px-4"><div class="relative flex justify-between lg:gap-8"><div class="flex lg:static xl:col-span-2"><div class="flex shrink-0 items-center">`);
				_push(ssrRenderComponent(_component_Link, {
					href: _ctx.route("dashboard"),
					class: "h-8 w-auto focus:ring-0 focus:outline-hidden"
				}, {
					default: withCtx((_, _push, _parent, _scopeId) => {
						if (_push) _push(ssrRenderComponent(unref(ApplicationMark_default), null, null, _parent, _scopeId));
						else return [createVNode(unref(ApplicationMark_default))];
					}),
					_: 1
				}, _parent));
				_push(`</div></div><div class="flex-1"></div></div></div></header>`);
			} else _push(`<!---->`);
			_push(`<div style="${ssrRenderStyle({ "height": "calc(100vh - 4rem)" })}" class="flex max-h-full max-w-full flex-1 grow"><div class="relative flex-1 overflow-y-auto p-4">`);
			if (loading.value) _push(ssrRenderComponent(unref(_sfc_main$1), null, null, _parent));
			else _push(`<!---->`);
			_push(`<div class="flex h-full w-full items-center justify-center text-center"><div>`);
			if (__props.pos_settings.customer_view_heading) _push(`<h1 class="mb-2 text-2xl font-bold">${ssrInterpolate(__props.pos_settings.customer_view_heading)}</h1>`);
			else _push(`<!---->`);
			_push(`<div class="text-mute font-light whitespace-pre-line"><div>${(__props.pos_settings?.customer_view_message || _ctx.$t("You can cover this area with advertisements.")) ?? ""}</div></div></div></div></div></div></div><div class="static end-0 z-10 block h-screen max-h-full min-h-full w-full shrink-0 overflow-hidden border-s border-gray-200 bg-white sm:w-96 dark:border-gray-800 dark:bg-gray-950 print:block print:h-full print:w-full print:border-0"><div id="order-container" class="flex max-h-full min-h-full w-full flex-col"><div id="order-details" class="flex items-start justify-between px-4 pt-2"><div class="flex grow items-center gap-1 leading-6 font-semibold text-gray-900 dark:text-gray-100">${ssrInterpolate(_ctx.$t("Order Details"))} `);
			if (form.value.reference && form.value.reference != "f") _push(`<div class="text-xs">(${ssrInterpolate(form.value.reference)})</div>`);
			else _push(`<!---->`);
			_push(`</div><div class="flex items-center gap-1 text-end"><div class="text-right"><div class="text-xs">${ssrInterpolate(_ctx.$t("Order Number"))}</div><div class="text-xs font-bold">#${ssrInterpolate(form.value.number)}</div></div></div></div><div id="order-customer" class="px-4 pb-3"><div class="mb-px flex items-center gap-x-4 text-xs"><label for="customer">${ssrInterpolate(_ctx.$t("Customer"))}:</label></div><div class="relative mt-px grid grid-cols-1 items-center font-bold">${ssrInterpolate(customer.value?.company || customer.value?.name)}</div></div>`);
			if (form.value.items && form.value.items.length) {
				_push(`<div id="order-items" style="${ssrRenderStyle({ "height": "calc(100vh - 230px)" })}" class="scroll-box flex min-h-[150px] w-full flex-col overflow-auto print:h-full print:min-h-0 print:overflow-visible"><table class="divide-y divide-gray-200 dark:divide-gray-700"><!--[-->`);
				ssrRenderList(form.value.items, (item) => {
					_push(`<tbody>`);
					if (item.product.has_variants == 1 && item.variations && item.variations.length) {
						_push(`<!--[--><tr><td class="py-1.5 ps-4 pe-2 align-top"><div class="flex">`);
						if (item.product.photo) _push(`<img alt=""${ssrRenderAttr("src", item.product.photo)} class="me-2 size-9 flex-none rounded-md">`);
						else _push(`<!---->`);
						_push(`<div class="flex flex-col text-sm font-bold">${ssrInterpolate(item.name)} <div>${ssrInterpolate(item.code)}</div></div></div></td><td class="px-2 py-1.5 text-end align-top font-bold"></td><td class="py-1.5 ps-2 pe-4 text-end align-top"></td></tr><!--[-->`);
						ssrRenderList(item.variations, (variation) => {
							_push(`<tr><td class="ps-4 pr-2 pb-1.5 align-top"><div class="flex">`);
							if (item.product.photo) _push(`<div alt="" class="me-2 w-9 flex-none rounded-md"></div>`);
							else _push(`<!---->`);
							_push(` ${ssrInterpolate(_ctx.$meta(variation.meta))}</div></td><td class="px-2 pb-1.5 text-end align-top font-bold">${ssrInterpolate(unref($number_qty)(variation.quantity))} x</td><td class="ps-2 pr-4 pb-1.5 text-end align-top font-bold">${ssrInterpolate(_ctx.$number(Number(variation.net_price)))}</td></tr>`);
						});
						_push(`<!--]--><!--]-->`);
					} else {
						_push(`<tr><td class="py-1.5 ps-4 pe-2 align-top"><div class="flex">`);
						if (item.product.photo) _push(`<img alt=""${ssrRenderAttr("src", item.product.photo)} class="me-2 size-9 flex-none rounded-md">`);
						else _push(`<!---->`);
						_push(`<div class="flex flex-col text-sm font-bold">${ssrInterpolate(item.name)} <div>${ssrInterpolate(item.code)}</div></div></div></td><td class="px-2 py-1.5 text-end align-top font-bold">${ssrInterpolate(unref($number_qty)(item.quantity))} x</td><td class="py-1.5 ps-2 pe-4 text-end align-top font-bold">${ssrInterpolate(_ctx.$number(item.net_price))}</td></tr>`);
					}
					_push(`</tbody>`);
				});
				_push(`<!--]--></table></div>`);
			} else _push(`<!---->`);
			if (form.value.items?.length) {
				_push(`<div class="mt-auto p-2">`);
				_push(ssrRenderComponent(unref(OrderSummary), { form: form.value }, null, _parent));
				_push(`</div>`);
			} else _push(`<!---->`);
			_push(`</div></div></div></div></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/CustomerView.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
