import { t as __exportAll } from "./rolldown-runtime-rSIU-vHC.js";
import { t as B } from "./index.esm-0G7eAEV5.js";
import { t as _sfc_main$1 } from "./SecondaryButton-ub85RH3e.js";
import { A as _sfc_main$8, M as _sfc_main$4, O as _sfc_main$5, P as vKeyboard, S as _sfc_main$3, T as _sfc_main$6, Y as $decimal, f as _sfc_main$7, vt as _sfc_main$2, z as http_default } from "../ssr.js";
import { notify } from "notiwind";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, mergeProps, openBlock, ref, renderList, resolveComponent, toDisplayString, unref, useSSRContext, vModelText, watch, withCtx, withDirectives } from "vue";
import { useI18n } from "vue-i18n";
import { ssrGetDirectiveProps, ssrGetDynamicModelProps, ssrInterpolate, ssrRenderAttrs, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
import debounce from "lodash/debounce.js";
//#region resources/js/Pages/Sma/Pos/Components/FinalizeSale.vue
var FinalizeSale_exports = /* @__PURE__ */ __exportAll({ default: () => _sfc_main });
var _sfc_main = {
	__name: "FinalizeSale",
	__ssrInlineRender: true,
	props: [
		"show",
		"form",
		"saveForm",
		"custom_fields",
		"payment_fields"
	],
	emits: ["close"],
	setup(__props, { emit: __emit }) {
		const { t } = useI18n({});
		const emit = __emit;
		const props = __props;
		const saving = ref(false);
		const totalPaymentsAmount = ref(0);
		const cash_notes = ref(props.form.notes || []);
		watch(cash_notes, (notes) => {
			props.form.notes = notes;
			props.form.tendered = notes.reduce((a, i) => Number($decimal(i)) + a, 0);
			props.form.change_returned = $decimal(props.form.tendered - (props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0) + Number(props.form.rounding || 0)));
			props.form.payable_amount = $decimal(props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0) + (props.form.rounding || 0));
			props.form.payments[0].amount = $decimal(props.form.tendered < props.form.payable_amount ? props.form.tendered : props.form.payable_amount);
			props.saveForm();
		});
		watch(() => props.show, (show) => {
			if (show) {
				if (!props.form.payments || !Object.keys(props.form.payments).length) props.form.payments = [{
					amount: $decimal(props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0)),
					method: "Cash",
					method_data: {}
				}];
				else {
					props.form.payments[0].amount = $decimal(Number(props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0)));
					props.form.payments[0].method = "Cash";
				}
				calcTotalPaymentsAmount();
			}
		});
		function closeNow() {
			emit("close");
			clearNotes();
		}
		function clearNotes() {
			cash_notes.value = [];
			props.form.tendered = 0;
			props.form.change_returned = 0;
		}
		function addMorePayment() {
			if (!props.form.payments) props.form.payments = [{
				amount: props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0),
				method: "Cash",
				method_data: {}
			}];
			props.form.payments = [...props.form.payments, {
				amount: 0,
				method: "Cash",
				method_data: {}
			}];
		}
		function checkPayments(re) {
			if (!props.form.payments) return false;
			let payments = props.form.payments.map((p) => p);
			payments = payments.filter((p) => p.amount > 0 && p.method != "Stripe Terminal");
			payments = payments.filter((p) => p.method == "Card Terminal" && !p.cc_slip ? false : true);
			payments = payments.filter((p) => {
				if (p.method == "Gift Card") {
					if (!p.gift_card) return false;
					if (Number(p.gift_card.balance) < Number(p.amount)) return false;
					if (p.gift_card.customer_id && p.gift_card.customer_id != props.form.customer_id) return false;
				}
				return true;
			});
			const total_amount = $decimal(payments.reduce((a, p) => a + Number($decimal(p.amount)), 0));
			if (re) return total_amount;
			return Number(total_amount) == Number($decimal(props.form.items.reduce((a, i) => Number($decimal(i.total)) + a, 0)) + Number(props.form.rounding || 0));
		}
		function calcTotalPaymentsAmount(index = null) {
			totalPaymentsAmount.value = checkPayments(true);
			if (index !== null) {
				const payment = props.form.payments[index];
				if (payment && payment.method == "Gift Card") payment.method_data = {
					...payment.method_data,
					gift_card_no: payment.method_data?.gift_card_no || null
				};
			}
		}
		const checkGiftCard = debounce((e, index) => {
			if (e.target.value) http_default.get(B("gift_cards.details", e.target.value)).then((res) => {
				props.form.payments[index].gift_card = res.data;
				if (props.form.payments[index].amount > res.data.balance) {
					notify({
						group: "main",
						type: "error",
						title: "Error!",
						text: t("Gift card balance is not enough.")
					});
					props.form.payments[index].amount = res.data.balance;
					calcTotalPaymentsAmount();
				}
			});
		}, 500);
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Icon = resolveComponent("Icon");
			const _component_icons = resolveComponent("icons");
			let _temp0;
			_push(ssrRenderComponent(unref(_sfc_main$2), mergeProps({
				show: __props.show,
				onClose: closeNow,
				maxWidth: "lg",
				backdrop: false,
				round: _ctx.$page.props.settings?.pos_design == "Modern"
			}, _attrs), {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div${_scopeId}><div class="relative border-b border-gray-200 p-4 sm:px-6 dark:border-gray-700"${_scopeId}><div class="absolute end-0 top-0 hidden pe-4 pt-4 sm:block"${_scopeId}><button type="button" class="rounded-md text-gray-400 hover:text-gray-500 focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 focus:outline-hidden"${_scopeId}><span class="sr-only"${_scopeId}>${ssrInterpolate(_ctx.$t("Close"))}</span><svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"${_scopeId}><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"${_scopeId}></path></svg></button></div><div${_scopeId}><h3 class="text-base leading-6 font-semibold text-gray-900 dark:text-gray-100"${_scopeId}>${ssrInterpolate(_ctx.$t("Finalize Sale"))}</h3><p class="mt-1 text-sm"${_scopeId}>${ssrInterpolate(_ctx.$t("Please fill the payment details to finalize."))}</p></div></div>`);
						if (__props.form.items && __props.form.items.length) {
							_push(`<div class="mb-6 flex flex-col gap-6"${_scopeId}><div class="text-base"${_scopeId}><dl class="divide-y divide-gray-100 dark:divide-gray-700"${_scopeId}><div class="bg-gray-50 px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50"${_scopeId}><dt class="leading-6 font-medium"${_scopeId}>${ssrInterpolate(_ctx.$t("Total"))}</dt><dd class="mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0"${_scopeId}>${ssrInterpolate(_ctx.$currency(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)))}</dd></div><div class="px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4"${_scopeId}><dt class="leading-6 font-medium"${_scopeId}>${ssrInterpolate(_ctx.$t("Rounding"))}</dt><dd class="mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0"${_scopeId}>${ssrInterpolate(_ctx.$number(__props.form.rounding || 0))}</dd></div><div class="bg-gray-50 px-6 py-2 text-lg sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50"${_scopeId}><dt class="leading-6 font-medium"${_scopeId}>${ssrInterpolate(_ctx.$t("Payable Amount"))}</dt><dd class="mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0"${_scopeId}>${ssrInterpolate(_ctx.$currency(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) + (__props.form.rounding || 0)))}</dd></div><div class="px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4"${_scopeId}><dt class="leading-6 font-medium"${_scopeId}>${ssrInterpolate(_ctx.$t("Tender Amount"))} <br${_scopeId}> ${ssrInterpolate(Number(__props.form.tendered || 0) < Number((props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) || 0) + (__props.form.rounding || 0)) ? _ctx.$t("Get") + " " + _ctx.$number(0 - (__props.form.tendered - ((props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) || 0) + (__props.form.rounding || 0)))) + " " + _ctx.$t("more") : "")}</dt><dd class="mt-1 flex items-end justify-end text-end leading-6 font-bold sm:col-span-2 sm:mt-0"${_scopeId}><input${ssrRenderAttrs((_temp0 = mergeProps({
								id: "tender-amount",
								value: __props.form.tendered,
								class: "-mx-2 rounded-xs border-0 border-b border-gray-200 bg-transparent px-2 py-0.5 text-end focus:ring-0 dark:border-gray-700"
							}, ssrGetDirectiveProps(_ctx, unref(vKeyboard))), mergeProps(_temp0, ssrGetDynamicModelProps(_temp0, __props.form.tendered))))}${_scopeId}></dd></div><div class="bg-gray-50 px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50"${_scopeId}><dt class="leading-6 font-medium"${_scopeId}>${ssrInterpolate(_ctx.$t("Return Amount"))}</dt><dd class="mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0"${_scopeId}>${ssrInterpolate(__props.form.change_returned || _ctx.$number(Number(__props.form.tendered || 0) > Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) + (__props.form.rounding || 0) ? __props.form.tendered - (__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) + (__props.form.rounding || 0)) : 0))}</dd></div></dl></div>`);
							if (_ctx.$page.props.settings?.quick_cash?.length) {
								_push(`<div class="px-6"${_scopeId}><div class="flex items-start justify-between gap-2"${_scopeId}><div class="flex flex-wrap items-center gap-2"${_scopeId}><!--[-->`);
								ssrRenderList(_ctx.$page.props.settings.quick_cash, (cash, index) => {
									_push(`<button type="button" class="btn-primary relative"${_scopeId}>${ssrInterpolate(cash)} `);
									if (cash_notes.value.filter((c) => c == Number(cash.replace(",", "").replace(".", ""))).length) _push(`<div class="absolute top-0 -right-2.5 z-10 flex min-h-5 min-w-5 -translate-y-1/2 items-center justify-center rounded-full bg-gray-700 px-1 text-xs text-gray-100 dark:bg-white dark:text-gray-700"${_scopeId}>${ssrInterpolate(cash_notes.value.filter((c) => c == Number(cash.replace(",", "").replace(".", ""))).length)}</div>`);
									else _push(`<!---->`);
									_push(`</button>`);
								});
								_push(`<!--]--></div><button type="button" class="btn-danger"${_scopeId}>`);
								_push(ssrRenderComponent(_component_Icon, {
									name: "x",
									class: "h-4 w-4"
								}, null, _parent, _scopeId));
								_push(`</button></div></div>`);
							} else _push(`<!---->`);
							_push(`<!--[-->`);
							ssrRenderList(__props.form.payments, (payment, index) => {
								_push(`<!--[--><div class="grid grid-cols-2 gap-4 border-t border-gray-200 px-6 pt-6 dark:border-gray-700"${_scopeId}><div${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$3), {
									keyboard: "",
									type: "number",
									label: _ctx.$t("Amount"),
									onChange: calcTotalPaymentsAmount,
									modelValue: __props.form.payments[index].amount,
									"onUpdate:modelValue": ($event) => __props.form.payments[index].amount = $event,
									max: Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) - Number(__props.form.rounding || 0)
								}, null, _parent, _scopeId));
								_push(`</div><div${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$4), {
									keyboard: "",
									json: false,
									placement: "top",
									searchable: false,
									label: _ctx.$t("Method"),
									modelValue: __props.form.payments[index].method,
									"onUpdate:modelValue": ($event) => __props.form.payments[index].method = $event,
									onChange: ($event) => calcTotalPaymentsAmount(index),
									suggestions: [
										"Cash",
										"Gift Card",
										"Card Terminal",
										"Stripe Terminal",
										"Others"
									]
								}, null, _parent, _scopeId));
								_push(`</div></div>`);
								if (__props.form.payments[index]?.method == "Gift Card") {
									_push(`<div class="px-6"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$3), {
										keyboard: "",
										label: _ctx.$t("Gift Card Number"),
										onChange: calcTotalPaymentsAmount,
										onInput: (e) => unref(checkGiftCard)(e, index),
										modelValue: __props.form.payments[index].method_data.gift_card_no,
										"onUpdate:modelValue": ($event) => __props.form.payments[index].method_data.gift_card_no = $event
									}, null, _parent, _scopeId));
									if (__props.form.payments[index].gift_card && __props.form.payments[index].method_data.gift_card_no) {
										_push(`<div class="mt-3 rounded-md border px-3 py-2 text-sm whitespace-pre-wrap dark:border-gray-700"${_scopeId}><div${_scopeId}>${ssrInterpolate(_ctx.$t("Balance Amount"))}: ${ssrInterpolate(_ctx.$number(__props.form.payments[index].gift_card.balance))}</div>`);
										if (__props.form.payments[index].gift_card.customer) _push(`<div${_scopeId}>${ssrInterpolate(_ctx.$t("Customer"))}: ${ssrInterpolate(__props.form.payments[index].gift_card.customer?.company || __props.form.payments[index].gift_card.customer?.name)}</div>`);
										else _push(`<!---->`);
										_push(`</div>`);
									} else _push(`<!---->`);
									_push(`</div>`);
								} else _push(`<!---->`);
								if (__props.form.payments[index]?.method == "Card Terminal") {
									_push(`<div class="px-6"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$5), {
										onChange: calcTotalPaymentsAmount,
										checked: __props.form.payments[index].cc_slip,
										"onUpdate:checked": ($event) => __props.form.payments[index].cc_slip = $event,
										label: _ctx.$t("I have collected payment & saved receipt")
									}, null, _parent, _scopeId));
									_push(`</div>`);
								} else _push(`<!---->`);
								if (__props.form.payments[index]?.method == "Stripe Terminal") _push(`<div class="px-6 text-sm font-bold text-yellow-500"${_scopeId}> Work in Progress </div>`);
								else _push(`<!---->`);
								if (__props.payment_fields.length) {
									_push(`<div class="col-span-full -mt-6 flex flex-col gap-6 border-y border-gray-200 px-6 py-6 dark:border-gray-700"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$6), {
										onUpdate: __props.saveForm,
										errors: __props.form.errors,
										custom_fields: __props.payment_fields,
										extra_attributes: __props.form.payments[index].extra_attributes
									}, null, _parent, _scopeId));
									_push(`</div>`);
								} else _push(`<!---->`);
								_push(`<!--]-->`);
							});
							_push(`<!--]--><div class="border-t border-gray-200 pt-6 dark:border-gray-700"${_scopeId}>`);
							if (Number(totalPaymentsAmount.value) < Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0))) {
								_push(`<div class="mb-6 flex items-center justify-center"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$1), {
									type: "button",
									onClick: ($event) => addMorePayment(),
									class: "flex items-center justify-center rounded-md px-6 py-2 text-sm text-gray-600 hover:text-gray-700"
								}, {
									default: withCtx((_, _push, _parent, _scopeId) => {
										if (_push) {
											_push(ssrRenderComponent(_component_icons, {
												name: "plus",
												class: "me-1 h-4 w-4"
											}, null, _parent, _scopeId));
											_push(` ${ssrInterpolate(_ctx.$t("Add another Payment"))}`);
										} else return [createVNode(_component_icons, {
											name: "plus",
											class: "me-1 h-4 w-4"
										}), createTextVNode(" " + toDisplayString(_ctx.$t("Add another Payment")), 1)];
									}),
									_: 1
								}, _parent, _scopeId));
								_push(`</div>`);
							} else _push(`<!---->`);
							_push(`<h4 class="bg-gray-100 px-6 py-2 text-center dark:bg-gray-900"${_scopeId}>${ssrInterpolate(_ctx.$t("Total Payment Amount"))}: <strong${_scopeId}>${ssrInterpolate(_ctx.$number(totalPaymentsAmount.value))}</strong></h4></div>`);
							if (__props.custom_fields.length) {
								_push(`<div class="col-span-full -mt-6 flex flex-col gap-6 border-y border-gray-200 px-6 py-6 dark:border-gray-700"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$6), {
									errors: __props.form.errors,
									custom_fields: __props.custom_fields,
									extra_attributes: __props.form.extra_attributes,
									onUpdate: __props.saveForm
								}, null, _parent, _scopeId));
								_push(`</div>`);
							} else _push(`<!---->`);
							_push(`<div class="px-6"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$7), {
								keyboard: "",
								label: "",
								modelValue: __props.form.details,
								"onUpdate:modelValue": ($event) => __props.form.details = $event,
								onChange: __props.saveForm,
								placeholder: _ctx.$t("Any sale details")
							}, null, _parent, _scopeId));
							_push(`</div><div class="px-6"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$8), {
								type: "button",
								loading: saving.value,
								class: "w-full justify-center",
								onClick: ($event) => emit("finalize", __props.form),
								disabled: saving.value || _ctx.$page.props.settings?.allow_sale_without_payment != 1 && Number(totalPaymentsAmount.value) != Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) + Number(__props.form.rounding || 0)
							}, {
								default: withCtx((_, _push, _parent, _scopeId) => {
									if (_push) _push(`<span class="text-base"${_scopeId}>${ssrInterpolate(_ctx.$t("Submit"))}</span>`);
									else return [createVNode("span", { class: "text-base" }, toDisplayString(_ctx.$t("Submit")), 1)];
								}),
								_: 1
							}, _parent, _scopeId));
							_push(`</div></div>`);
						} else _push(`<div class="m-6 flex flex-col gap-4 text-yellow-600"${_scopeId}>${ssrInterpolate(_ctx.$t("Please add at least one item to form."))}</div>`);
						_push(`</div>`);
					} else return [createVNode("div", null, [createVNode("div", { class: "relative border-b border-gray-200 p-4 sm:px-6 dark:border-gray-700" }, [createVNode("div", { class: "absolute end-0 top-0 hidden pe-4 pt-4 sm:block" }, [createVNode("button", {
						type: "button",
						onClick: closeNow,
						class: "rounded-md text-gray-400 hover:text-gray-500 focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 focus:outline-hidden"
					}, [createVNode("span", { class: "sr-only" }, toDisplayString(_ctx.$t("Close")), 1), (openBlock(), createBlock("svg", {
						class: "h-6 w-6",
						fill: "none",
						viewBox: "0 0 24 24",
						"stroke-width": "1.5",
						stroke: "currentColor",
						"aria-hidden": "true"
					}, [createVNode("path", {
						"stroke-linecap": "round",
						"stroke-linejoin": "round",
						d: "M6 18L18 6M6 6l12 12"
					})]))])]), createVNode("div", null, [createVNode("h3", { class: "text-base leading-6 font-semibold text-gray-900 dark:text-gray-100" }, toDisplayString(_ctx.$t("Finalize Sale")), 1), createVNode("p", { class: "mt-1 text-sm" }, toDisplayString(_ctx.$t("Please fill the payment details to finalize.")), 1)])]), __props.form.items && __props.form.items.length ? (openBlock(), createBlock("div", {
						key: 0,
						class: "mb-6 flex flex-col gap-6"
					}, [
						createVNode("div", { class: "text-base" }, [createVNode("dl", { class: "divide-y divide-gray-100 dark:divide-gray-700" }, [
							createVNode("div", { class: "bg-gray-50 px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50" }, [createVNode("dt", { class: "leading-6 font-medium" }, toDisplayString(_ctx.$t("Total")), 1), createVNode("dd", { class: "mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0" }, toDisplayString(_ctx.$currency(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0))), 1)]),
							createVNode("div", { class: "px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4" }, [createVNode("dt", { class: "leading-6 font-medium" }, toDisplayString(_ctx.$t("Rounding")), 1), createVNode("dd", { class: "mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0" }, toDisplayString(_ctx.$number(__props.form.rounding || 0)), 1)]),
							createVNode("div", { class: "bg-gray-50 px-6 py-2 text-lg sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50" }, [createVNode("dt", { class: "leading-6 font-medium" }, toDisplayString(_ctx.$t("Payable Amount")), 1), createVNode("dd", { class: "mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0" }, toDisplayString(_ctx.$currency(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) + (__props.form.rounding || 0))), 1)]),
							createVNode("div", { class: "px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4" }, [createVNode("dt", { class: "leading-6 font-medium" }, [
								createTextVNode(toDisplayString(_ctx.$t("Tender Amount")) + " ", 1),
								createVNode("br"),
								createTextVNode(" " + toDisplayString(Number(__props.form.tendered || 0) < Number((props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) || 0) + (__props.form.rounding || 0)) ? _ctx.$t("Get") + " " + _ctx.$number(0 - (__props.form.tendered - ((props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) || 0) + (__props.form.rounding || 0)))) + " " + _ctx.$t("more") : ""), 1)
							]), createVNode("dd", { class: "mt-1 flex items-end justify-end text-end leading-6 font-bold sm:col-span-2 sm:mt-0" }, [withDirectives(createVNode("input", {
								id: "tender-amount",
								"onUpdate:modelValue": ($event) => __props.form.tendered = $event,
								onClick: (e) => e.target.select(),
								onChange: () => {
									__props.form.tendered = unref($decimal)(__props.form.tendered);
									__props.form.change_returned = unref($decimal)(Number(__props.form.tendered || 0) > Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) + (__props.form.rounding || 0) ? __props.form.tendered - (__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) + (__props.form.rounding || 0)) : 0);
									props.saveForm();
								},
								class: "-mx-2 rounded-xs border-0 border-b border-gray-200 bg-transparent px-2 py-0.5 text-end focus:ring-0 dark:border-gray-700"
							}, null, 40, [
								"onUpdate:modelValue",
								"onClick",
								"onChange"
							]), [[unref(vKeyboard)], [vModelText, __props.form.tendered]])])]),
							createVNode("div", { class: "bg-gray-50 px-6 py-2 sm:grid sm:grid-cols-3 sm:gap-4 dark:bg-gray-900/50" }, [createVNode("dt", { class: "leading-6 font-medium" }, toDisplayString(_ctx.$t("Return Amount")), 1), createVNode("dd", { class: "mt-1 text-end leading-6 font-bold sm:col-span-2 sm:mt-0" }, toDisplayString(__props.form.change_returned || _ctx.$number(Number(__props.form.tendered || 0) > Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) + (__props.form.rounding || 0) ? __props.form.tendered - (__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0) + (__props.form.rounding || 0)) : 0)), 1)])
						])]),
						_ctx.$page.props.settings?.quick_cash?.length ? (openBlock(), createBlock("div", {
							key: 0,
							class: "px-6"
						}, [createVNode("div", { class: "flex items-start justify-between gap-2" }, [createVNode("div", { class: "flex flex-wrap items-center gap-2" }, [(openBlock(true), createBlock(Fragment, null, renderList(_ctx.$page.props.settings.quick_cash, (cash, index) => {
							return openBlock(), createBlock("button", {
								key: index,
								type: "button",
								class: "btn-primary relative",
								onClick: () => cash_notes.value = [...cash_notes.value, Number(cash.replace(",", "").replace(".", ""))]
							}, [createTextVNode(toDisplayString(cash) + " ", 1), cash_notes.value.filter((c) => c == Number(cash.replace(",", "").replace(".", ""))).length ? (openBlock(), createBlock("div", {
								key: 0,
								class: "absolute top-0 -right-2.5 z-10 flex min-h-5 min-w-5 -translate-y-1/2 items-center justify-center rounded-full bg-gray-700 px-1 text-xs text-gray-100 dark:bg-white dark:text-gray-700"
							}, toDisplayString(cash_notes.value.filter((c) => c == Number(cash.replace(",", "").replace(".", ""))).length), 1)) : createCommentVNode("", true)], 8, ["onClick"]);
						}), 128))]), createVNode("button", {
							type: "button",
							class: "btn-danger",
							onClick: clearNotes
						}, [createVNode(_component_Icon, {
							name: "x",
							class: "h-4 w-4"
						})])])])) : createCommentVNode("", true),
						(openBlock(true), createBlock(Fragment, null, renderList(__props.form.payments, (payment, index) => {
							return openBlock(), createBlock(Fragment, { key: index }, [
								createVNode("div", { class: "grid grid-cols-2 gap-4 border-t border-gray-200 px-6 pt-6 dark:border-gray-700" }, [createVNode("div", null, [createVNode(unref(_sfc_main$3), {
									keyboard: "",
									type: "number",
									label: _ctx.$t("Amount"),
									onChange: calcTotalPaymentsAmount,
									modelValue: __props.form.payments[index].amount,
									"onUpdate:modelValue": ($event) => __props.form.payments[index].amount = $event,
									max: Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) - Number(__props.form.rounding || 0)
								}, null, 8, [
									"label",
									"modelValue",
									"onUpdate:modelValue",
									"max"
								])]), createVNode("div", null, [createVNode(unref(_sfc_main$4), {
									keyboard: "",
									json: false,
									placement: "top",
									searchable: false,
									label: _ctx.$t("Method"),
									modelValue: __props.form.payments[index].method,
									"onUpdate:modelValue": ($event) => __props.form.payments[index].method = $event,
									onChange: ($event) => calcTotalPaymentsAmount(index),
									suggestions: [
										"Cash",
										"Gift Card",
										"Card Terminal",
										"Stripe Terminal",
										"Others"
									]
								}, null, 8, [
									"label",
									"modelValue",
									"onUpdate:modelValue",
									"onChange"
								])])]),
								__props.form.payments[index]?.method == "Gift Card" ? (openBlock(), createBlock("div", {
									key: 0,
									class: "px-6"
								}, [createVNode(unref(_sfc_main$3), {
									keyboard: "",
									label: _ctx.$t("Gift Card Number"),
									onChange: calcTotalPaymentsAmount,
									onInput: (e) => unref(checkGiftCard)(e, index),
									modelValue: __props.form.payments[index].method_data.gift_card_no,
									"onUpdate:modelValue": ($event) => __props.form.payments[index].method_data.gift_card_no = $event
								}, null, 8, [
									"label",
									"onInput",
									"modelValue",
									"onUpdate:modelValue"
								]), __props.form.payments[index].gift_card && __props.form.payments[index].method_data.gift_card_no ? (openBlock(), createBlock("div", {
									key: 0,
									class: "mt-3 rounded-md border px-3 py-2 text-sm whitespace-pre-wrap dark:border-gray-700"
								}, [createVNode("div", null, toDisplayString(_ctx.$t("Balance Amount")) + ": " + toDisplayString(_ctx.$number(__props.form.payments[index].gift_card.balance)), 1), __props.form.payments[index].gift_card.customer ? (openBlock(), createBlock("div", { key: 0 }, toDisplayString(_ctx.$t("Customer")) + ": " + toDisplayString(__props.form.payments[index].gift_card.customer?.company || __props.form.payments[index].gift_card.customer?.name), 1)) : createCommentVNode("", true)])) : createCommentVNode("", true)])) : createCommentVNode("", true),
								__props.form.payments[index]?.method == "Card Terminal" ? (openBlock(), createBlock("div", {
									key: 1,
									class: "px-6"
								}, [createVNode(unref(_sfc_main$5), {
									onChange: calcTotalPaymentsAmount,
									checked: __props.form.payments[index].cc_slip,
									"onUpdate:checked": ($event) => __props.form.payments[index].cc_slip = $event,
									label: _ctx.$t("I have collected payment & saved receipt")
								}, null, 8, [
									"checked",
									"onUpdate:checked",
									"label"
								])])) : createCommentVNode("", true),
								__props.form.payments[index]?.method == "Stripe Terminal" ? (openBlock(), createBlock("div", {
									key: 2,
									class: "px-6 text-sm font-bold text-yellow-500"
								}, " Work in Progress ")) : createCommentVNode("", true),
								__props.payment_fields.length ? (openBlock(), createBlock("div", {
									key: 3,
									class: "col-span-full -mt-6 flex flex-col gap-6 border-y border-gray-200 px-6 py-6 dark:border-gray-700"
								}, [createVNode(unref(_sfc_main$6), {
									onUpdate: __props.saveForm,
									errors: __props.form.errors,
									custom_fields: __props.payment_fields,
									extra_attributes: __props.form.payments[index].extra_attributes
								}, null, 8, [
									"onUpdate",
									"errors",
									"custom_fields",
									"extra_attributes"
								])])) : createCommentVNode("", true)
							], 64);
						}), 128)),
						createVNode("div", { class: "border-t border-gray-200 pt-6 dark:border-gray-700" }, [Number(totalPaymentsAmount.value) < Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) ? (openBlock(), createBlock("div", {
							key: 0,
							class: "mb-6 flex items-center justify-center"
						}, [createVNode(unref(_sfc_main$1), {
							type: "button",
							onClick: ($event) => addMorePayment(),
							class: "flex items-center justify-center rounded-md px-6 py-2 text-sm text-gray-600 hover:text-gray-700"
						}, {
							default: withCtx(() => [createVNode(_component_icons, {
								name: "plus",
								class: "me-1 h-4 w-4"
							}), createTextVNode(" " + toDisplayString(_ctx.$t("Add another Payment")), 1)]),
							_: 1
						}, 8, ["onClick"])])) : createCommentVNode("", true), createVNode("h4", { class: "bg-gray-100 px-6 py-2 text-center dark:bg-gray-900" }, [createTextVNode(toDisplayString(_ctx.$t("Total Payment Amount")) + ": ", 1), createVNode("strong", null, toDisplayString(_ctx.$number(totalPaymentsAmount.value)), 1)])]),
						__props.custom_fields.length ? (openBlock(), createBlock("div", {
							key: 1,
							class: "col-span-full -mt-6 flex flex-col gap-6 border-y border-gray-200 px-6 py-6 dark:border-gray-700"
						}, [createVNode(unref(_sfc_main$6), {
							errors: __props.form.errors,
							custom_fields: __props.custom_fields,
							extra_attributes: __props.form.extra_attributes,
							onUpdate: __props.saveForm
						}, null, 8, [
							"errors",
							"custom_fields",
							"extra_attributes",
							"onUpdate"
						])])) : createCommentVNode("", true),
						createVNode("div", { class: "px-6" }, [createVNode(unref(_sfc_main$7), {
							keyboard: "",
							label: "",
							modelValue: __props.form.details,
							"onUpdate:modelValue": ($event) => __props.form.details = $event,
							onChange: __props.saveForm,
							placeholder: _ctx.$t("Any sale details")
						}, null, 8, [
							"modelValue",
							"onUpdate:modelValue",
							"onChange",
							"placeholder"
						])]),
						createVNode("div", { class: "px-6" }, [createVNode(unref(_sfc_main$8), {
							type: "button",
							loading: saving.value,
							class: "w-full justify-center",
							onClick: ($event) => emit("finalize", __props.form),
							disabled: saving.value || _ctx.$page.props.settings?.allow_sale_without_payment != 1 && Number(totalPaymentsAmount.value) != Number(__props.form.items.reduce((a, i) => Number(unref($decimal)(i.total)) + a, 0)) + Number(__props.form.rounding || 0)
						}, {
							default: withCtx(() => [createVNode("span", { class: "text-base" }, toDisplayString(_ctx.$t("Submit")), 1)]),
							_: 1
						}, 8, [
							"loading",
							"onClick",
							"disabled"
						])])
					])) : (openBlock(), createBlock("div", {
						key: 1,
						class: "m-6 flex flex-col gap-4 text-yellow-600"
					}, toDisplayString(_ctx.$t("Please add at least one item to form.")), 1))])];
				}),
				_: 1
			}, _parent));
		};
	}
};
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/FinalizeSale.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as n, FinalizeSale_exports as t };
