import { t as B } from "./index.esm-0G7eAEV5.js";
import { t as _sfc_main$1 } from "./ActionMessage-DRAWBZho.js";
import { t as _sfc_main$2 } from "./SecondaryButton-ub85RH3e.js";
import { A as _sfc_main$12, B as VariationSelection, C as _sfc_main$7, F as _sfc_main$8, M as _sfc_main$4, S as _sfc_main$6, T as _sfc_main$10, U as FormHelper, V as searchItems, Z as $extras, _ as _sfc_main$9, at as convert_to_base_unit, dt as _sfc_main$3, f as _sfc_main$11, j as _sfc_main$14, nt as calculate_item, ot as discount_keypress, vt as _sfc_main$13, w as _sfc_main$5, z as http_default } from "../ssr.js";
import { t as _sfc_main$15 } from "./AdminLayout-eZgRfDMK.js";
import { router, useForm, usePage } from "@inertiajs/vue3";
import { notify } from "notiwind";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, onMounted, openBlock, ref, renderList, resolveComponent, toDisplayString, unref, useSSRContext, withCtx, withKeys, withModifiers } from "vue";
import { useI18n } from "vue-i18n";
import { ssrIncludeBooleanAttr, ssrInterpolate, ssrRenderAttr, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
import dayjs from "dayjs";
import debounce from "lodash/debounce.js";
//#region resources/js/Pages/Sma/Order/ReturnOrder/Form.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$15 }, {
	__name: "Form",
	__ssrInlineRender: true,
	props: [
		"current",
		"custom_fields",
		"stores",
		"taxes",
		"sale_id",
		"purchase_id"
	],
	setup(__props) {
		const page = usePage();
		const { t } = useI18n();
		const scannerOpen = ref(false);
		const props = __props;
		const form = useForm({
			_method: props.current?.id ? "put" : "post",
			calculate_on: props.current?.type == "Purchase" ? "cost" : "price",
			type: props.current?.type,
			type_ref: props.current?.type_ref,
			sale_id: props.current?.sale_id,
			purchase_id: props.current?.purchase_id,
			date: dayjs(props.current?.date).format("YYYY-MM-DD"),
			reference: props.current?.reference,
			customer_id: props.current?.customer_id,
			supplier_id: props.current?.supplier_id,
			details: props.current?.details,
			attachments: null,
			return_payment_amount: props.current?.return_payment_amount || null,
			return_payment_method: props.current?.return_payment_method || "Cash",
			items: props.current && props.current.items && props.current.items.length ? props.current.items.map((i) => {
				return calculate_item({
					...i,
					id: i.id,
					discount: i.discount,
					name: i.product.name,
					cost: Number(i.cost),
					price: Number(i.price),
					product_id: i.product_id,
					quantity: Number(i.quantity),
					old_quantity: Number(i.quantity),
					sale_item_id: i.sale_item_id,
					purchase_item_id: i.purchase_item_id,
					taxes: i.taxes?.map((t) => t.id) || [],
					tax_included: i.product.tax_included == 1,
					variations: i.variations.map((v) => ({
						...v,
						discount: v.pivot.discount,
						cost: Number(v.pivot.cost),
						price: Number(v.pivot.price),
						quantity: Number(v.pivot.quantity),
						old_quantity: Number(v.pivot.quantity),
						tax_included: i.product.tax_included == 1,
						taxes: v.pivot.taxes?.map((t) => Number(t)) || []
					}))
				}, props.current?.type == "Purchase" ? "cost" : "price");
			}) : [],
			extra_attributes: props.current ? $extras(props.custom_fields, props.current.extra_attributes) : $extras(props.custom_fields)
		});
		const { currentItem, emptyVariation, variantModal, SelectVariant } = VariationSelection();
		const { openItemModal, selectItem, selectedItem, removeItem, resetForm, saveForm, updateItem } = FormHelper(form);
		async function addItem(item) {
			if (form.items.find((i) => i.product_id == item.id)) form.items = form.items.map((i) => {
				if (i.product_id == item.id) if (i.product.has_variants == 1) {
					i.variations = [...i.variations, emptyVariation(i.product)];
					currentItem.value = i;
					variantModal.value = true;
				} else i.quantity++;
				return i;
			});
			else {
				const product = await http_default.get(B("products.show", item.id)).then((r) => r.data);
				currentItem.value = calculate_item({
					...item,
					id: null,
					quantity: 1,
					cost: Number(product.cost),
					price: Number(product.price),
					taxes: product.taxes.map((t) => t.id),
					tax_included: product.tax_included == 1,
					product_id: product.id,
					unit_id: product.unit_id,
					product
				}, form.calculate_on);
				if (product.has_variants == 1) {
					currentItem.value.variations = [emptyVariation(product)];
					variantModal.value = true;
				}
				form.items = [...form.items, { ...currentItem.value }];
			}
			saveForm();
		}
		const getSale = debounce(() => {
			if (form.type_ref) http_default.post(B("search.sale"), { ref: form.type_ref }).then((res) => {
				if (res.data?.id) {
					const sale = res.data;
					form.purchase_id = null;
					form.supplier_id = null;
					form.sale_id = sale.id;
					form.customer_id = sale.customer_id;
					form.items = sale.items.map((i) => {
						return calculate_item({
							...i,
							id: null,
							sale_item_id: i.id,
							discount: i.discount,
							name: i.product.name,
							cost: Number(i.cost),
							price: Number(i.price),
							product_id: i.product_id,
							quantity: Number(i.quantity),
							max_quantity: Number(i.quantity),
							taxes: i.taxes?.map((t) => t.id) || [],
							tax_included: i.product.tax_included == 1,
							variations: i.variations.map((v) => ({
								...v,
								discount: v.pivot.discount,
								cost: Number(v.pivot.cost),
								price: Number(v.pivot.price),
								quantity: Number(v.pivot.quantity),
								max_quantity: Number(v.pivot.quantity),
								tax_included: i.product.tax_included == 1,
								taxes: v.pivot.taxes?.map((t) => Number(t)) || []
							}))
						}, "price");
					});
					notify({
						group: "main",
						type: "success",
						title: t("Sale items are loaded, please choose only return ones.")
					});
					saveForm();
				} else notify({
					group: "main",
					type: "error",
					title: t("Sale not found with No./ref {x}.", { x: form.type_ref })
				});
			});
		}, 250);
		const getPurchase = debounce(() => {
			if (form.type_ref) http_default.post(B("search.purchase"), { ref: form.type_ref }).then((res) => {
				if (res.data?.id) {
					const purchase = res.data;
					form.sale_id = null;
					form.customer_id = null;
					form.purchase_id = purchase.id;
					form.supplier_id = purchase.supplier_id;
					form.items = purchase.items.map((i) => {
						return calculate_item({
							...i,
							id: null,
							purchase_item_id: i.id,
							discount: i.discount,
							name: i.product.name,
							cost: Number(i.cost),
							product_id: i.product_id,
							quantity: Number(i.quantity),
							max_quantity: Number(i.quantity),
							taxes: i.taxes?.map((t) => t.id) || [],
							tax_included: i.product.tax_included == 1,
							variations: i.variations.map((v) => ({
								...v,
								discount: v.pivot.discount,
								cost: Number(v.pivot.cost),
								quantity: Number(v.pivot.quantity),
								max_quantity: Number(v.pivot.quantity),
								tax_included: i.product.tax_included == 1,
								taxes: v.pivot.taxes?.map((t) => Number(t)) || []
							}))
						}, "cost");
					});
					notify({
						group: "main",
						type: "success",
						title: t("Purchase items are loaded, please choose only return ones.")
					});
					saveForm();
				} else notify({
					group: "main",
					type: "error",
					title: t("Purchase not found with No./ref {x}.", { x: form.type_ref })
				});
			});
		}, 250);
		onMounted(() => {
			if (props.sale_id) {
				form.type = "Sale";
				form.calculate_on = "price";
				form.type_ref = props.sale_id;
				getSale();
			} else if (props.purchase_id) {
				form.type = "Purchase";
				form.calculate_on = "cost";
				form.type_ref = props.purchase_id;
				getPurchase();
			}
		});
		async function handleBarcodeScan(code) {
			scannerOpen.value = false;
			const results = await searchItems(code, "return_order", true);
			if (results && results.length) await addItem(results[0]);
		}
		function handleSubmit(e, listing = false) {
			form.errors = {};
			form.transform((data) => {
				const form = { ...data };
				form.items = form.items.map((i) => ({
					id: i.id,
					cost: i.cost,
					price: i.price,
					taxes: i.taxes,
					quantity: i.quantity,
					unit_id: i.unit_id,
					discount: i.discount,
					product_id: i.product_id,
					sale_item_id: i.sale_item_id,
					old_quantity: i.old_quantity,
					purchase_item_id: i.purchase_item_id,
					variations: i.variations && i.variations.length ? i.variations.map((v) => ({
						id: v.id,
						cost: v.cost,
						price: v.price,
						taxes: v.taxes,
						unit_id: v.unit_id,
						discount: v.discount,
						quantity: v.quantity,
						old_quantity: v.old_quantity
					})) : null
				}));
				try {
					form.date = form.date ? dayjs(form.date).format("YYYY-MM-DD") : null;
				} catch {}
				if (!form.return_payment_amount || Number(form.return_payment_amount) <= 0) {
					form.return_payment_amount = null;
					form.return_payment_method = null;
				}
				return form;
			}).post(props.current?.id ? B("return_orders.update", props.current.id) : B("return_orders.store"), {
				forceFormData: true,
				onSuccess: () => {
					resetForm();
					if (listing) router.get(B("return_orders.index"));
				}
			});
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			const _component_Link = resolveComponent("Link");
			_push(`<!--[-->`);
			_push(ssrRenderComponent(_component_Head, null, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`<title${_scopeId}>${ssrInterpolate(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Return Order") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Return Order") }))}</title>`);
					else return [createVNode("title", null, toDisplayString(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Return Order") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Return Order") })), 1)];
				}),
				_: 1
			}, _parent));
			_push(`<div class="px-0 pt-6 pb-0 sm:px-6 sm:py-8 lg:px-8">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), { onSubmitted: handleSubmit }, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Return Order") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Return Order") }))}`);
					else return [createTextVNode(toDisplayString(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Return Order") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Return Order") })), 1)];
				}),
				description: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="block w-full sm:flex sm:items-start sm:justify-between lg:block"${_scopeId}><div${_scopeId}>${ssrInterpolate(_ctx.$t("Please fill the form below to {action} {record}.", {
							record: _ctx.$t("return_order"),
							action: __props.current?.id ? _ctx.$t("edit") : _ctx.$t("add")
						}))}</div><div class="me-3 mt-6 sm:mt-0 lg:mt-6"${_scopeId}>`);
						_push(ssrRenderComponent(_component_Link, {
							class: "link",
							href: unref(B)("return_orders.index")
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("List {x}", { x: _ctx.$t("Return Orders") }))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Return Orders") })), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`</div></div>`);
					} else return [createVNode("div", { class: "block w-full sm:flex sm:items-start sm:justify-between lg:block" }, [createVNode("div", null, toDisplayString(_ctx.$t("Please fill the form below to {action} {record}.", {
						record: _ctx.$t("return_order"),
						action: __props.current?.id ? _ctx.$t("edit") : _ctx.$t("add")
					})), 1), createVNode("div", { class: "me-3 mt-6 sm:mt-0 lg:mt-6" }, [createVNode(_component_Link, {
						class: "link",
						href: unref(B)("return_orders.index")
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Return Orders") })), 1)]),
						_: 1
					}, 8, ["href"])])])];
				}),
				form: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$4), {
							id: "type",
							json: true,
							label: _ctx.$t("Type"),
							modelValue: unref(form).type,
							"onUpdate:modelValue": ($event) => unref(form).type = $event,
							onChange: () => {
								unref(form).calculate_on = unref(form).type == "Purchase" ? "cost" : "price";
								unref(saveForm)();
							},
							error: unref(form).errors.type,
							suggestions: [{
								value: "Sale",
								label: _ctx.$t("Return Order for Sale")
							}, {
								value: "Purchase",
								label: _ctx.$t("Return Order for Purchase")
							}]
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}></div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$5), {
							type: "date",
							id: "date",
							onChange: unref(saveForm),
							label: _ctx.$t("Date"),
							modelValue: unref(form).date,
							"onUpdate:modelValue": ($event) => unref(form).date = $event,
							error: unref(form).errors.date
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$6), {
							id: "reference",
							onChange: unref(saveForm),
							label: _ctx.$t("Reference"),
							modelValue: unref(form).reference,
							"onUpdate:modelValue": ($event) => unref(form).reference = $event,
							error: unref(form).errors.reference
						}, null, _parent, _scopeId));
						_push(`</div>`);
						if (unref(form).type == "Sale") {
							_push(`<!--[--><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								onChange: unref(getSale),
								modelValue: unref(form).type_ref,
								"onUpdate:modelValue": ($event) => unref(form).type_ref = $event,
								label: _ctx.$t("Sale No/Ref"),
								onKeyup: unref(getSale),
								error: _ctx.$page.props.errors.type_ref
							}, null, _parent, _scopeId));
							_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$4), {
								json: true,
								valueKey: "id",
								id: "customer_id",
								labelKey: "company",
								onChange: unref(saveForm),
								searchable: true,
								label: _ctx.$t("Customer"),
								modelValue: unref(form).customer_id,
								"onUpdate:modelValue": ($event) => unref(form).customer_id = $event,
								suggestions: unref(B)("search.customers"),
								error: _ctx.$page.props.errors.customer_id
							}, null, _parent, _scopeId));
							_push(`</div><!--]-->`);
						} else _push(`<!---->`);
						if (unref(form).type == "Purchase") {
							_push(`<!--[--><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								onChange: unref(getPurchase),
								modelValue: unref(form).type_ref,
								"onUpdate:modelValue": ($event) => unref(form).type_ref = $event,
								label: _ctx.$t("Purchase No/Ref"),
								onKeyup: unref(getPurchase),
								error: _ctx.$page.props.errors.type_ref
							}, null, _parent, _scopeId));
							_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$4), {
								json: true,
								valueKey: "id",
								id: "supplier_id",
								labelKey: "company",
								onChange: unref(saveForm),
								searchable: true,
								label: _ctx.$t("Supplier"),
								modelValue: unref(form).supplier_id,
								"onUpdate:modelValue": ($event) => unref(form).supplier_id = $event,
								suggestions: unref(B)("search.suppliers"),
								error: _ctx.$page.props.errors.supplier_id
							}, null, _parent, _scopeId));
							_push(`</div><!--]-->`);
						} else _push(`<!---->`);
						_push(`<div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$6), {
							type: "number",
							modelValue: unref(form).surcharge,
							"onUpdate:modelValue": ($event) => unref(form).surcharge = $event,
							error: _ctx.$page.props.errors.surcharge,
							label: _ctx.$t("Surcharge")
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$7), {
							multiple: "",
							id: "attachments",
							label: _ctx.$t("Attachments"),
							modelValue: unref(form).attachments,
							"onUpdate:modelValue": ($event) => unref(form).attachments = $event,
							error: unref(form).errors.attachments,
							accept: _ctx.$page.props.settings?.attachment_exts || ".jpg,.png,.pdf,.xlsx,.docx,.zip"
						}, null, _parent, _scopeId));
						_push(`</div>`);
						if (__props.current && __props.current.attachments && __props.current.attachments.length) {
							_push(`<div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$8), { attachments: __props.current.attachments || [] }, null, _parent, _scopeId));
							_push(`</div>`);
						} else _push(`<!---->`);
						_push(`<div class="col-span-full"${_scopeId}><div class="flex items-start gap-2"${_scopeId}><div class="flex-1"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$9), {
							model: "return_order",
							type: unref(form).type,
							onAddItem: addItem
						}, null, _parent, _scopeId));
						_push(`</div><button type="button"${ssrRenderAttr("title", _ctx.$t("Scan Barcode"))} class="mb-px inline-flex items-center rounded-md border border-gray-300 bg-gray-100 p-2.5 text-gray-600 hover:bg-gray-200 hover:text-gray-800 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-gray-200"${_scopeId}><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"${_scopeId}><path stroke-linecap="round" stroke-linejoin="round" d="M3 9V6a1 1 0 011-1h3M3 15v3a1 1 0 001 1h3m11-4v3a1 1 0 01-1 1h-3m4-11h-3a1 1 0 00-1 1v3M7 7h2v2H7zm0 4h2v2H7zm4-4h2v2h-2zm0 4h2v2h-2zm4-4h2v2h-2zm0 4h2v2h-2z"${_scopeId}></path></svg></button></div>`);
						if (unref(form).items && unref(form).items.length) {
							_push(`<div class="overflow-x-auto"${_scopeId}><h4 class="mt-6 pb-2 text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Return Order Items"))}</h4><table class="w-full min-w-[500px] divide-y divide-gray-200 dark:divide-gray-700"${_scopeId}><thead${_scopeId}><tr${_scopeId}><th class="text-mute"${_scopeId}>#</th><th class="text-mute text-start"${_scopeId}>${ssrInterpolate(_ctx.$t("Product"))}</th><th class="text-mute"${_scopeId}>${ssrInterpolate(unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price"))}</th><th class="text-mute"${_scopeId}>${ssrInterpolate(_ctx.$t("Quantity"))}</th>`);
							if (unref(page).props.settings.show_tax == 1) _push(`<th class="text-mute"${_scopeId}>${ssrInterpolate(_ctx.$t("Tax"))}</th>`);
							else _push(`<!---->`);
							_push(`<th class="text-mute"${_scopeId}>${ssrInterpolate(_ctx.$t("Total"))}</th></tr></thead><!--[-->`);
							ssrRenderList(unref(form).items, (item, index) => {
								_push(`<!--[-->`);
								if (item.product.has_variants == 1 && item.variations && item.variations.length) {
									_push(`<tbody${_scopeId}><tr${_scopeId}><td class="w-8 px-2 pt-4 pb-2"${_scopeId}>${ssrInterpolate(index + 1)}.</td><td class="p-2 font-bold"${_scopeId}><button type="button" class="link min-w-56 text-start"${_scopeId}>${ssrInterpolate(item.name)}</button></td><td class="p-2"${_scopeId}></td><td class="w-36 p-2"${_scopeId}></td>`);
									if (unref(page).props.settings.show_tax == 1) _push(`<th class="text-mute"${_scopeId}></th>`);
									else _push(`<!---->`);
									_push(`<th class="text-mute text-end"${_scopeId}></th></tr><!--[-->`);
									ssrRenderList(item.variations, (variation, vi) => {
										_push(`<!--[--><tr class="${ssrRenderClass(unref(form).errors && (unref(form).errors["items." + index + ".variations." + vi + ".id"] || unref(form).errors["items." + index + ".variations." + vi + ".quantity"]) ? "bg-red-100 dark:bg-red-900" : "")}"${_scopeId}><td class="w-8 p-2"${_scopeId}></td><td class="p-2"${_scopeId}>${ssrInterpolate(_ctx.$meta(variation.meta))}</td><td class="w-24 p-2 text-end"${_scopeId}>${ssrInterpolate(unref(form).type == "Purchase" ? _ctx.$number(unref(page).props.settings.show_tax == 1 ? variation.net_cost : variation.unit_cost) : _ctx.$number(unref(page).props.settings.show_tax == 1 ? variation.net_price : variation.unit_price))}</td><td class="w-36 p-2"${_scopeId}><div class="relative"${_scopeId}>`);
										_push(ssrRenderComponent(unref(_sfc_main$6), {
											min: 0,
											label: "",
											"del-on": 0,
											type: "number",
											onChange: () => {
												item.quantity = item.variations.reduce((a, v) => Number(v.quantity) + a, 0);
												unref(calculate_item)(item, unref(form).calculate_on);
												unref(saveForm)();
											},
											modelValue: variation.quantity,
											"onUpdate:modelValue": ($event) => variation.quantity = $event,
											placeholder: _ctx.$t("Quantity"),
											max: item.selected_store && item.selected_store[0] ? item.selected_store[0].pivot?.quantity : null
										}, null, _parent, _scopeId));
										if (variation.unit_id) {
											_push(`<!--[-->`);
											if (item.product?.unit?.id == variation.unit_id) _push(`<span class="text-mute absolute end-2 top-0 py-2"${_scopeId}>${ssrInterpolate(item.product.unit.code)}</span>`);
											else _push(`<span class="text-mute absolute end-2 top-0 py-2"${_scopeId}>${ssrInterpolate(item.product.unit?.subunits?.find((s) => s.id == variation.unit_id).code)}</span>`);
											_push(`<!--]-->`);
										} else _push(`<!---->`);
										_push(`</div></td>`);
										if (unref(page).props.settings.show_tax == 1) _push(`<td class="w-20 p-2 text-end"${_scopeId}>${ssrInterpolate(_ctx.$number(variation.tax_amount))}</td>`);
										else _push(`<!---->`);
										_push(`<td class="w-24 p-2 text-end"${_scopeId}>${ssrInterpolate(_ctx.$number(variation.total))}</td></tr>`);
										if (unref(form).errors && (unref(form).errors["items." + index + ".variations." + vi + ".id"] || unref(form).errors["items." + index + ".variations." + vi + ".quantity"])) {
											_push(`<tr class="bg-red-100 dark:bg-red-900"${_scopeId}><td colspan="100%"${_scopeId}><div class="px-4 py-1 text-sm text-red-500"${_scopeId}>`);
											if (unref(form).errors["items." + index + ".variations." + vi + ".id"]) _push(`<div${_scopeId}>${ssrInterpolate(unref(form).errors["items." + index + ".variations." + vi + ".id"].toString().replace("items." + index + ".variations." + vi + ".id", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variation") + " #" + (vi + 1)))}</div>`);
											else _push(`<!---->`);
											if (unref(form).errors["items." + index + ".variations." + vi + ".quantity"]) _push(`<div${_scopeId}>${ssrInterpolate(unref(form).errors["items." + index + ".variations." + vi + ".quantity"].toString().replace("items." + index + ".variations." + vi + ".quantity", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variation") + " #" + (vi + 1) + " " + _ctx.$t("quantity")).split("when")[0])}</div>`);
											else _push(`<!---->`);
											_push(`</div></td></tr>`);
										} else _push(`<!---->`);
										_push(`<!--]-->`);
									});
									_push(`<!--]--></tbody>`);
								} else {
									_push(`<tbody class="${ssrRenderClass(unref(form).errors && (unref(form).errors["items." + index + ".quantity"] || unref(form).errors["items." + index + ".variations"]) ? "bg-red-100 dark:bg-red-800" : "")}"${_scopeId}><tr${_scopeId}><td class="w-8 p-2"${_scopeId}>${ssrInterpolate(index + 1)}.</td><td class="p-2"${_scopeId}><button type="button" class="link min-w-56 text-start"${_scopeId}>${ssrInterpolate(item.name)}</button></td><td class="w-24 p-2 text-end"${_scopeId}>${ssrInterpolate(unref(form).type == "Purchase" ? _ctx.$number(unref(page).props.settings.show_tax == 1 ? item.net_cost : item.unit_cost) : _ctx.$number(unref(page).props.settings.show_tax == 1 ? item.net_price : item.unit_price))}</td><td class="w-36 p-2"${_scopeId}><div class="relative"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$6), {
										min: 0,
										label: "",
										"del-on": 0,
										type: "number",
										modelValue: item.quantity,
										"onUpdate:modelValue": ($event) => item.quantity = $event,
										placeholder: _ctx.$t("Quantity"),
										onChange: () => {
											selectedItem.value = item;
											unref(updateItem)();
										},
										max: item.selected_store && item.selected_store[0] ? item.selected_store[0].pivot?.quantity : null
									}, null, _parent, _scopeId));
									if (item.unit_id) {
										_push(`<!--[-->`);
										if (item.product?.unit?.id == item.unit_id) _push(`<span class="text-mute absolute end-2 top-0 py-2"${_scopeId}>${ssrInterpolate(item.product.unit.code)}</span>`);
										else _push(`<span class="text-mute absolute end-2 top-0 py-2"${_scopeId}>${ssrInterpolate(item.product.unit?.subunits?.find((s) => s.id == item.unit_id).code)}</span>`);
										_push(`<!--]-->`);
									} else _push(`<!---->`);
									_push(`</div></td>`);
									if (unref(page).props.settings.show_tax == 1) _push(`<td class="w-20 p-2 text-end"${_scopeId}>${ssrInterpolate(_ctx.$number(item.tax_amount))}</td>`);
									else _push(`<!---->`);
									_push(`<td class="w-24 p-2 text-end"${_scopeId}>${ssrInterpolate(_ctx.$number(item.total))}</td></tr>`);
									if (unref(form).errors && (unref(form).errors["items." + index + ".quantity"] || unref(form).errors["items." + index + ".variations"])) {
										_push(`<tr${_scopeId}><td colspan="100%"${_scopeId}><div class="px-4 py-1 text-sm text-red-500"${_scopeId}>`);
										if (unref(form).errors["items." + index + ".quantity"]) _push(`<div${_scopeId}>${ssrInterpolate(unref(form).errors["items." + index + ".quantity"].toString().replace("items." + index + ".quantity", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("quantity")))}</div>`);
										else _push(`<!---->`);
										if (unref(form).errors["items." + index + ".variations"]) _push(`<div${_scopeId}>${ssrInterpolate(unref(form).errors["items." + index + ".variations"].toString().replace("items." + index + ".variations", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variations")))}</div>`);
										else _push(`<!---->`);
										_push(`</div></td></tr>`);
									} else _push(`<!---->`);
									_push(`</tbody>`);
								}
								_push(`<!--]-->`);
							});
							_push(`<!--]--><tfoot class="divide-y divide-gray-200 dark:divide-gray-700"${_scopeId}>`);
							if (unref(page).props.settings.show_tax == 1) _push(`<tr${_scopeId}><th colspan="3" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Total"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal_qty(unref(form).items.reduce((a, i) => Number(i.quantity) + a, 0)))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0)))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total) + a, 0)))}</th><th${_scopeId}></th></tr>`);
							else {
								_push(`<!--[-->`);
								if (_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0), true) > 0) _push(`<!--[--><tr${_scopeId}><th colspan="4" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Subtotal"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.subtotal) + a, 0)))}</th></tr><tr${_scopeId}><th colspan="4" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Tax"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0)))}</th></tr><!--]-->`);
								else if (unref(page).props.settings.show_zero_taxes == 1) _push(`<tr${_scopeId}><th colspan="4" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Tax"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0)))}</th></tr>`);
								else _push(`<!---->`);
								_push(`<tr${_scopeId}><th colspan="4" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Total"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total) + a, 0)))}</th><th${_scopeId}></th></tr><!--]-->`);
							}
							_push(`</tfoot></table></div>`);
						} else _push(`<label for="product-search" class="mt-4 block w-full rounded-md bg-gray-100 px-4 py-2 text-primary-600 dark:bg-gray-800 dark:text-primary-400"${_scopeId}>${ssrInterpolate(_ctx.$t("Please add at least one product."))}</label>`);
						_push(`</div><div class="col-span-full flex flex-col gap-6"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$10), {
							errors: unref(form).errors,
							custom_fields: __props.custom_fields,
							extra_attributes: unref(form).extra_attributes,
							onUpdate: unref(saveForm)
						}, null, _parent, _scopeId));
						if (unref(form).type == "Sale" && unref(form).sale_id || unref(form).type == "Purchase" && unref(form).purchase_id) {
							_push(`<div class="rounded-md border border-gray-200 p-4 dark:border-gray-700"${_scopeId}><h4 class="mb-3 text-sm font-semibold"${_scopeId}>${ssrInterpolate(_ctx.$t("Return Payment"))}</h4><div class="grid grid-cols-1 gap-4 sm:grid-cols-2"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								type: "number",
								min: 0,
								label: _ctx.$t("Refund Amount"),
								modelValue: unref(form).return_payment_amount,
								"onUpdate:modelValue": ($event) => unref(form).return_payment_amount = $event,
								placeholder: _ctx.$t("Leave empty if no refund"),
								error: unref(form).errors.return_payment_amount
							}, null, _parent, _scopeId));
							_push(ssrRenderComponent(unref(_sfc_main$4), {
								json: true,
								label: _ctx.$t("Payment Method"),
								modelValue: unref(form).return_payment_method,
								"onUpdate:modelValue": ($event) => unref(form).return_payment_method = $event,
								error: unref(form).errors.return_payment_method,
								suggestions: [...[
									"Cash",
									"Credit Card",
									"Card Terminal",
									"Others"
								], ..._ctx.$page.props.settings?.payment?.static_payment_methods || []].map((m) => ({
									value: m,
									label: m
								}))
							}, null, _parent, _scopeId));
							_push(`</div></div>`);
						} else _push(`<!---->`);
						_push(ssrRenderComponent(unref(_sfc_main$11), {
							onChange: unref(saveForm),
							label: _ctx.$t("Details"),
							modelValue: unref(form).details,
							"onUpdate:modelValue": ($event) => unref(form).details = $event,
							error: _ctx.$page.props.errors.details
						}, null, _parent, _scopeId));
						_push(`</div>`);
					} else return [
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$4), {
							id: "type",
							json: true,
							label: _ctx.$t("Type"),
							modelValue: unref(form).type,
							"onUpdate:modelValue": ($event) => unref(form).type = $event,
							onChange: () => {
								unref(form).calculate_on = unref(form).type == "Purchase" ? "cost" : "price";
								unref(saveForm)();
							},
							error: unref(form).errors.type,
							suggestions: [{
								value: "Sale",
								label: _ctx.$t("Return Order for Sale")
							}, {
								value: "Purchase",
								label: _ctx.$t("Return Order for Purchase")
							}]
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"onChange",
							"error",
							"suggestions"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$5), {
							type: "date",
							id: "date",
							onChange: unref(saveForm),
							label: _ctx.$t("Date"),
							modelValue: unref(form).date,
							"onUpdate:modelValue": ($event) => unref(form).date = $event,
							error: unref(form).errors.date
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							id: "reference",
							onChange: unref(saveForm),
							label: _ctx.$t("Reference"),
							modelValue: unref(form).reference,
							"onUpdate:modelValue": ($event) => unref(form).reference = $event,
							error: unref(form).errors.reference
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])]),
						unref(form).type == "Sale" ? (openBlock(), createBlock(Fragment, { key: 0 }, [createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							onChange: unref(getSale),
							modelValue: unref(form).type_ref,
							"onUpdate:modelValue": ($event) => unref(form).type_ref = $event,
							label: _ctx.$t("Sale No/Ref"),
							onKeyup: withKeys(withModifiers(unref(getSale), ["prevent"]), ["enter"]),
							error: _ctx.$page.props.errors.type_ref
						}, null, 8, [
							"onChange",
							"modelValue",
							"onUpdate:modelValue",
							"label",
							"onKeyup",
							"error"
						])]), createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$4), {
							json: true,
							valueKey: "id",
							id: "customer_id",
							labelKey: "company",
							onChange: unref(saveForm),
							searchable: true,
							label: _ctx.$t("Customer"),
							modelValue: unref(form).customer_id,
							"onUpdate:modelValue": ($event) => unref(form).customer_id = $event,
							suggestions: unref(B)("search.customers"),
							error: _ctx.$page.props.errors.customer_id
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"suggestions",
							"error"
						])])], 64)) : createCommentVNode("", true),
						unref(form).type == "Purchase" ? (openBlock(), createBlock(Fragment, { key: 1 }, [createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							onChange: unref(getPurchase),
							modelValue: unref(form).type_ref,
							"onUpdate:modelValue": ($event) => unref(form).type_ref = $event,
							label: _ctx.$t("Purchase No/Ref"),
							onKeyup: withKeys(withModifiers(unref(getPurchase), ["prevent"]), ["enter"]),
							error: _ctx.$page.props.errors.type_ref
						}, null, 8, [
							"onChange",
							"modelValue",
							"onUpdate:modelValue",
							"label",
							"onKeyup",
							"error"
						])]), createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$4), {
							json: true,
							valueKey: "id",
							id: "supplier_id",
							labelKey: "company",
							onChange: unref(saveForm),
							searchable: true,
							label: _ctx.$t("Supplier"),
							modelValue: unref(form).supplier_id,
							"onUpdate:modelValue": ($event) => unref(form).supplier_id = $event,
							suggestions: unref(B)("search.suppliers"),
							error: _ctx.$page.props.errors.supplier_id
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"suggestions",
							"error"
						])])], 64)) : createCommentVNode("", true),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							type: "number",
							modelValue: unref(form).surcharge,
							"onUpdate:modelValue": ($event) => unref(form).surcharge = $event,
							error: _ctx.$page.props.errors.surcharge,
							label: _ctx.$t("Surcharge")
						}, null, 8, [
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"label"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$7), {
							multiple: "",
							id: "attachments",
							label: _ctx.$t("Attachments"),
							modelValue: unref(form).attachments,
							"onUpdate:modelValue": ($event) => unref(form).attachments = $event,
							error: unref(form).errors.attachments,
							accept: _ctx.$page.props.settings?.attachment_exts || ".jpg,.png,.pdf,.xlsx,.docx,.zip"
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"accept"
						])]),
						__props.current && __props.current.attachments && __props.current.attachments.length ? (openBlock(), createBlock("div", {
							key: 2,
							class: "col-span-full"
						}, [createVNode(unref(_sfc_main$8), { attachments: __props.current.attachments || [] }, null, 8, ["attachments"])])) : createCommentVNode("", true),
						createVNode("div", { class: "col-span-full" }, [createVNode("div", { class: "flex items-start gap-2" }, [createVNode("div", { class: "flex-1" }, [createVNode(unref(_sfc_main$9), {
							model: "return_order",
							type: unref(form).type,
							onAddItem: addItem
						}, null, 8, ["type"])]), createVNode("button", {
							type: "button",
							onClick: ($event) => scannerOpen.value = true,
							title: _ctx.$t("Scan Barcode"),
							class: "mb-px inline-flex items-center rounded-md border border-gray-300 bg-gray-100 p-2.5 text-gray-600 hover:bg-gray-200 hover:text-gray-800 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-gray-200"
						}, [(openBlock(), createBlock("svg", {
							xmlns: "http://www.w3.org/2000/svg",
							class: "h-5 w-5",
							fill: "none",
							viewBox: "0 0 24 24",
							stroke: "currentColor",
							"stroke-width": "1.5"
						}, [createVNode("path", {
							"stroke-linecap": "round",
							"stroke-linejoin": "round",
							d: "M3 9V6a1 1 0 011-1h3M3 15v3a1 1 0 001 1h3m11-4v3a1 1 0 01-1 1h-3m4-11h-3a1 1 0 00-1 1v3M7 7h2v2H7zm0 4h2v2H7zm4-4h2v2h-2zm0 4h2v2h-2zm4-4h2v2h-2zm0 4h2v2h-2z"
						})]))], 8, ["onClick", "title"])]), unref(form).items && unref(form).items.length ? (openBlock(), createBlock("div", {
							key: 0,
							class: "overflow-x-auto"
						}, [createVNode("h4", { class: "mt-6 pb-2 text-lg font-bold" }, toDisplayString(_ctx.$t("Return Order Items")), 1), createVNode("table", { class: "w-full min-w-[500px] divide-y divide-gray-200 dark:divide-gray-700" }, [
							createVNode("thead", null, [createVNode("tr", null, [
								createVNode("th", { class: "text-mute" }, "#"),
								createVNode("th", { class: "text-mute text-start" }, toDisplayString(_ctx.$t("Product")), 1),
								createVNode("th", { class: "text-mute" }, toDisplayString(unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price")), 1),
								createVNode("th", { class: "text-mute" }, toDisplayString(_ctx.$t("Quantity")), 1),
								unref(page).props.settings.show_tax == 1 ? (openBlock(), createBlock("th", {
									key: 0,
									class: "text-mute"
								}, toDisplayString(_ctx.$t("Tax")), 1)) : createCommentVNode("", true),
								createVNode("th", { class: "text-mute" }, toDisplayString(_ctx.$t("Total")), 1)
							])]),
							(openBlock(true), createBlock(Fragment, null, renderList(unref(form).items, (item, index) => {
								return openBlock(), createBlock(Fragment, { key: item.code }, [item.product.has_variants == 1 && item.variations && item.variations.length ? (openBlock(), createBlock("tbody", { key: 0 }, [createVNode("tr", null, [
									createVNode("td", { class: "w-8 px-2 pt-4 pb-2" }, toDisplayString(index + 1) + ".", 1),
									createVNode("td", { class: "p-2 font-bold" }, [createVNode("button", {
										type: "button",
										onClick: ($event) => unref(selectItem)(item),
										class: "link min-w-56 text-start"
									}, toDisplayString(item.name), 9, ["onClick"])]),
									createVNode("td", { class: "p-2" }),
									createVNode("td", { class: "w-36 p-2" }),
									unref(page).props.settings.show_tax == 1 ? (openBlock(), createBlock("th", {
										key: 0,
										class: "text-mute"
									})) : createCommentVNode("", true),
									createVNode("th", { class: "text-mute text-end" })
								]), (openBlock(true), createBlock(Fragment, null, renderList(item.variations, (variation, vi) => {
									return openBlock(), createBlock(Fragment, { key: variation.id }, [createVNode("tr", { class: unref(form).errors && (unref(form).errors["items." + index + ".variations." + vi + ".id"] || unref(form).errors["items." + index + ".variations." + vi + ".quantity"]) ? "bg-red-100 dark:bg-red-900" : "" }, [
										createVNode("td", { class: "w-8 p-2" }),
										createVNode("td", { class: "p-2" }, toDisplayString(_ctx.$meta(variation.meta)), 1),
										createVNode("td", { class: "w-24 p-2 text-end" }, toDisplayString(unref(form).type == "Purchase" ? _ctx.$number(unref(page).props.settings.show_tax == 1 ? variation.net_cost : variation.unit_cost) : _ctx.$number(unref(page).props.settings.show_tax == 1 ? variation.net_price : variation.unit_price)), 1),
										createVNode("td", { class: "w-36 p-2" }, [createVNode("div", { class: "relative" }, [createVNode(unref(_sfc_main$6), {
											min: 0,
											label: "",
											"del-on": 0,
											type: "number",
											onChange: () => {
												item.quantity = item.variations.reduce((a, v) => Number(v.quantity) + a, 0);
												unref(calculate_item)(item, unref(form).calculate_on);
												unref(saveForm)();
											},
											modelValue: variation.quantity,
											"onUpdate:modelValue": ($event) => variation.quantity = $event,
											placeholder: _ctx.$t("Quantity"),
											max: item.selected_store && item.selected_store[0] ? item.selected_store[0].pivot?.quantity : null
										}, null, 8, [
											"onChange",
											"modelValue",
											"onUpdate:modelValue",
											"placeholder",
											"max"
										]), variation.unit_id ? (openBlock(), createBlock(Fragment, { key: 0 }, [item.product?.unit?.id == variation.unit_id ? (openBlock(), createBlock("span", {
											key: 0,
											class: "text-mute absolute end-2 top-0 py-2"
										}, toDisplayString(item.product.unit.code), 1)) : (openBlock(), createBlock("span", {
											key: 1,
											class: "text-mute absolute end-2 top-0 py-2"
										}, toDisplayString(item.product.unit?.subunits?.find((s) => s.id == variation.unit_id).code), 1))], 64)) : createCommentVNode("", true)])]),
										unref(page).props.settings.show_tax == 1 ? (openBlock(), createBlock("td", {
											key: 0,
											class: "w-20 p-2 text-end"
										}, toDisplayString(_ctx.$number(variation.tax_amount)), 1)) : createCommentVNode("", true),
										createVNode("td", { class: "w-24 p-2 text-end" }, toDisplayString(_ctx.$number(variation.total)), 1)
									], 2), unref(form).errors && (unref(form).errors["items." + index + ".variations." + vi + ".id"] || unref(form).errors["items." + index + ".variations." + vi + ".quantity"]) ? (openBlock(), createBlock("tr", {
										key: 0,
										class: "bg-red-100 dark:bg-red-900"
									}, [createVNode("td", { colspan: "100%" }, [createVNode("div", { class: "px-4 py-1 text-sm text-red-500" }, [unref(form).errors["items." + index + ".variations." + vi + ".id"] ? (openBlock(), createBlock("div", { key: 0 }, toDisplayString(unref(form).errors["items." + index + ".variations." + vi + ".id"].toString().replace("items." + index + ".variations." + vi + ".id", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variation") + " #" + (vi + 1))), 1)) : createCommentVNode("", true), unref(form).errors["items." + index + ".variations." + vi + ".quantity"] ? (openBlock(), createBlock("div", { key: 1 }, toDisplayString(unref(form).errors["items." + index + ".variations." + vi + ".quantity"].toString().replace("items." + index + ".variations." + vi + ".quantity", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variation") + " #" + (vi + 1) + " " + _ctx.$t("quantity")).split("when")[0]), 1)) : createCommentVNode("", true)])])])) : createCommentVNode("", true)], 64);
								}), 128))])) : (openBlock(), createBlock("tbody", {
									key: 1,
									class: unref(form).errors && (unref(form).errors["items." + index + ".quantity"] || unref(form).errors["items." + index + ".variations"]) ? "bg-red-100 dark:bg-red-800" : ""
								}, [createVNode("tr", null, [
									createVNode("td", { class: "w-8 p-2" }, toDisplayString(index + 1) + ".", 1),
									createVNode("td", { class: "p-2" }, [createVNode("button", {
										type: "button",
										onClick: ($event) => unref(selectItem)(item),
										class: "link min-w-56 text-start"
									}, toDisplayString(item.name), 9, ["onClick"])]),
									createVNode("td", { class: "w-24 p-2 text-end" }, toDisplayString(unref(form).type == "Purchase" ? _ctx.$number(unref(page).props.settings.show_tax == 1 ? item.net_cost : item.unit_cost) : _ctx.$number(unref(page).props.settings.show_tax == 1 ? item.net_price : item.unit_price)), 1),
									createVNode("td", { class: "w-36 p-2" }, [createVNode("div", { class: "relative" }, [createVNode(unref(_sfc_main$6), {
										min: 0,
										label: "",
										"del-on": 0,
										type: "number",
										modelValue: item.quantity,
										"onUpdate:modelValue": ($event) => item.quantity = $event,
										placeholder: _ctx.$t("Quantity"),
										onChange: () => {
											selectedItem.value = item;
											unref(updateItem)();
										},
										max: item.selected_store && item.selected_store[0] ? item.selected_store[0].pivot?.quantity : null
									}, null, 8, [
										"modelValue",
										"onUpdate:modelValue",
										"placeholder",
										"onChange",
										"max"
									]), item.unit_id ? (openBlock(), createBlock(Fragment, { key: 0 }, [item.product?.unit?.id == item.unit_id ? (openBlock(), createBlock("span", {
										key: 0,
										class: "text-mute absolute end-2 top-0 py-2"
									}, toDisplayString(item.product.unit.code), 1)) : (openBlock(), createBlock("span", {
										key: 1,
										class: "text-mute absolute end-2 top-0 py-2"
									}, toDisplayString(item.product.unit?.subunits?.find((s) => s.id == item.unit_id).code), 1))], 64)) : createCommentVNode("", true)])]),
									unref(page).props.settings.show_tax == 1 ? (openBlock(), createBlock("td", {
										key: 0,
										class: "w-20 p-2 text-end"
									}, toDisplayString(_ctx.$number(item.tax_amount)), 1)) : createCommentVNode("", true),
									createVNode("td", { class: "w-24 p-2 text-end" }, toDisplayString(_ctx.$number(item.total)), 1)
								]), unref(form).errors && (unref(form).errors["items." + index + ".quantity"] || unref(form).errors["items." + index + ".variations"]) ? (openBlock(), createBlock("tr", { key: 0 }, [createVNode("td", { colspan: "100%" }, [createVNode("div", { class: "px-4 py-1 text-sm text-red-500" }, [unref(form).errors["items." + index + ".quantity"] ? (openBlock(), createBlock("div", { key: 0 }, toDisplayString(unref(form).errors["items." + index + ".quantity"].toString().replace("items." + index + ".quantity", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("quantity"))), 1)) : createCommentVNode("", true), unref(form).errors["items." + index + ".variations"] ? (openBlock(), createBlock("div", { key: 1 }, toDisplayString(unref(form).errors["items." + index + ".variations"].toString().replace("items." + index + ".variations", _ctx.$t("item") + " #" + (index + 1) + " " + _ctx.$t("variations"))), 1)) : createCommentVNode("", true)])])])) : createCommentVNode("", true)], 2))], 64);
							}), 128)),
							createVNode("tfoot", { class: "divide-y divide-gray-200 dark:divide-gray-700" }, [unref(page).props.settings.show_tax == 1 ? (openBlock(), createBlock("tr", { key: 0 }, [
								createVNode("th", {
									colspan: "3",
									class: "p-2 text-end text-lg font-bold"
								}, toDisplayString(_ctx.$t("Total")), 1),
								createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal_qty(unref(form).items.reduce((a, i) => Number(i.quantity) + a, 0))), 1),
								createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0))), 1),
								createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total) + a, 0))), 1),
								createVNode("th")
							])) : (openBlock(), createBlock(Fragment, { key: 1 }, [_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0), true) > 0 ? (openBlock(), createBlock(Fragment, { key: 0 }, [createVNode("tr", null, [createVNode("th", {
								colspan: "4",
								class: "p-2 text-end text-lg font-bold"
							}, toDisplayString(_ctx.$t("Subtotal")), 1), createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.subtotal) + a, 0))), 1)]), createVNode("tr", null, [createVNode("th", {
								colspan: "4",
								class: "p-2 text-end text-lg font-bold"
							}, toDisplayString(_ctx.$t("Tax")), 1), createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0))), 1)])], 64)) : unref(page).props.settings.show_zero_taxes == 1 ? (openBlock(), createBlock("tr", { key: 1 }, [createVNode("th", {
								colspan: "4",
								class: "p-2 text-end text-lg font-bold"
							}, toDisplayString(_ctx.$t("Tax")), 1), createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total_tax_amount) + a, 0))), 1)])) : createCommentVNode("", true), createVNode("tr", null, [
								createVNode("th", {
									colspan: "4",
									class: "p-2 text-end text-lg font-bold"
								}, toDisplayString(_ctx.$t("Total")), 1),
								createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.total) + a, 0))), 1),
								createVNode("th")
							])], 64))])
						])])) : (openBlock(), createBlock("label", {
							key: 1,
							for: "product-search",
							class: "mt-4 block w-full rounded-md bg-gray-100 px-4 py-2 text-primary-600 dark:bg-gray-800 dark:text-primary-400"
						}, toDisplayString(_ctx.$t("Please add at least one product.")), 1))]),
						createVNode("div", { class: "col-span-full flex flex-col gap-6" }, [
							createVNode(unref(_sfc_main$10), {
								errors: unref(form).errors,
								custom_fields: __props.custom_fields,
								extra_attributes: unref(form).extra_attributes,
								onUpdate: unref(saveForm)
							}, null, 8, [
								"errors",
								"custom_fields",
								"extra_attributes",
								"onUpdate"
							]),
							unref(form).type == "Sale" && unref(form).sale_id || unref(form).type == "Purchase" && unref(form).purchase_id ? (openBlock(), createBlock("div", {
								key: 0,
								class: "rounded-md border border-gray-200 p-4 dark:border-gray-700"
							}, [createVNode("h4", { class: "mb-3 text-sm font-semibold" }, toDisplayString(_ctx.$t("Return Payment")), 1), createVNode("div", { class: "grid grid-cols-1 gap-4 sm:grid-cols-2" }, [createVNode(unref(_sfc_main$6), {
								type: "number",
								min: 0,
								label: _ctx.$t("Refund Amount"),
								modelValue: unref(form).return_payment_amount,
								"onUpdate:modelValue": ($event) => unref(form).return_payment_amount = $event,
								placeholder: _ctx.$t("Leave empty if no refund"),
								error: unref(form).errors.return_payment_amount
							}, null, 8, [
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"placeholder",
								"error"
							]), createVNode(unref(_sfc_main$4), {
								json: true,
								label: _ctx.$t("Payment Method"),
								modelValue: unref(form).return_payment_method,
								"onUpdate:modelValue": ($event) => unref(form).return_payment_method = $event,
								error: unref(form).errors.return_payment_method,
								suggestions: [...[
									"Cash",
									"Credit Card",
									"Card Terminal",
									"Others"
								], ..._ctx.$page.props.settings?.payment?.static_payment_methods || []].map((m) => ({
									value: m,
									label: m
								}))
							}, null, 8, [
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"error",
								"suggestions"
							])])])) : createCommentVNode("", true),
							createVNode(unref(_sfc_main$11), {
								onChange: unref(saveForm),
								label: _ctx.$t("Details"),
								modelValue: unref(form).details,
								"onUpdate:modelValue": ($event) => unref(form).details = $event,
								error: _ctx.$page.props.errors.details
							}, null, 8, [
								"onChange",
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"error"
							])
						])
					];
				}),
				actions: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="w-full"${_scopeId}>`);
						if (unref(form).progress) _push(`<div class="-mx-6 -mt-6 pb-1.5"${_scopeId}><progress max="100"${ssrRenderAttr("value", unref(form).progress?.percentage)} class="h-0.5 w-full appearance-none rounded-md bg-gray-200 dark:bg-gray-700"${_scopeId}>${ssrInterpolate(unref(form).progress?.percentage)}% </progress></div>`);
						else _push(`<!---->`);
						_push(`<div class="flex w-full items-center justify-between"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$2), {
							type: "button",
							onClick: unref(resetForm),
							class: "me-3"
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Reset"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Reset")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`<div class="flex items-center justify-end"${_scopeId}>`);
						if (__props.current) _push(`<button type="button" class="btn-secondary"${ssrRenderAttr("loading", unref(form).processing)}${ssrIncludeBooleanAttr(unref(form).processing) ? " disabled" : ""}${_scopeId}>${ssrInterpolate(_ctx.$t("Save & go to listing"))}</button>`);
						else _push(`<!---->`);
						_push(ssrRenderComponent(unref(_sfc_main$1), {
							on: unref(form).recentlySuccessful,
							class: "ms-3 me-3"
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Saved."))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Saved.")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(ssrRenderComponent(unref(_sfc_main$12), {
							type: "button",
							onClick: handleSubmit,
							class: { "opacity-25": unref(form).processing },
							loading: unref(form).processing
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Save"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Save")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`</div></div></div>`);
					} else return [createVNode("div", { class: "w-full" }, [unref(form).progress ? (openBlock(), createBlock("div", {
						key: 0,
						class: "-mx-6 -mt-6 pb-1.5"
					}, [createVNode("progress", {
						max: "100",
						value: unref(form).progress?.percentage,
						class: "h-0.5 w-full appearance-none rounded-md bg-gray-200 dark:bg-gray-700"
					}, toDisplayString(unref(form).progress?.percentage) + "% ", 9, ["value"])])) : createCommentVNode("", true), createVNode("div", { class: "flex w-full items-center justify-between" }, [createVNode(unref(_sfc_main$2), {
						type: "button",
						onClick: unref(resetForm),
						class: "me-3"
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Reset")), 1)]),
						_: 1
					}, 8, ["onClick"]), createVNode("div", { class: "flex items-center justify-end" }, [
						__props.current ? (openBlock(), createBlock("button", {
							key: 0,
							type: "button",
							class: "btn-secondary",
							loading: unref(form).processing,
							disabled: unref(form).processing,
							onClick: (e) => handleSubmit(e, true)
						}, toDisplayString(_ctx.$t("Save & go to listing")), 9, [
							"loading",
							"disabled",
							"onClick"
						])) : createCommentVNode("", true),
						createVNode(unref(_sfc_main$1), {
							on: unref(form).recentlySuccessful,
							class: "ms-3 me-3"
						}, {
							default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Saved.")), 1)]),
							_: 1
						}, 8, ["on"]),
						createVNode(unref(_sfc_main$12), {
							type: "button",
							onClick: handleSubmit,
							class: { "opacity-25": unref(form).processing },
							loading: unref(form).processing
						}, {
							default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Save")), 1)]),
							_: 1
						}, 8, ["class", "loading"])
					])])])];
				}),
				_: 1
			}, _parent));
			if (unref(variantModal)) _push(ssrRenderComponent(unref(SelectVariant), {
				item: unref(currentItem),
				show: unref(variantModal),
				onClose: () => {
					unref(currentItem).variations = unref(currentItem).variations.filter((v) => v.id);
					unref(form).items = unref(form).items.map((i) => i.product_id == unref(currentItem).product_id ? unref(calculate_item)(unref(currentItem), unref(form).calculate_on) : i);
					variantModal.value = false;
				},
				onUpdate: (item) => {
					item.variations = item.variations.filter((v) => v.id);
					unref(form).items = unref(form).items.map((i) => i.product_id == item.product_id ? unref(calculate_item)(item, unref(form).calculate_on) : i);
					unref(saveForm)();
					variantModal.value = false;
				}
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</div>`);
			_push(ssrRenderComponent(unref(_sfc_main$13), {
				show: unref(openItemModal),
				"max-width": "xl",
				onClose: ($event) => openItemModal.value = false,
				overflow: true,
				backdrop: false
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) if (unref(selectedItem)) {
						_push(`<div${_scopeId}><div class="border-b border-gray-200 px-4 py-4 sm:px-6 dark:border-gray-700"${_scopeId}><div class="sm:flex sm:items-baseline sm:justify-between"${_scopeId}><div class="sm:w-0 sm:flex-1"${_scopeId}><h1 class="text-focus text-base font-semibold"${_scopeId}>${ssrInterpolate(_ctx.$t("Edit {x}", { x: unref(selectedItem).name }))}</h1><p class="text-mute mt-1 truncate text-sm"${_scopeId}>${ssrInterpolate(_ctx.$t("Please update the details below"))}</p></div></div></div><div${_scopeId}>`);
						if (unref(selectedItem).product.has_variants == 1 && unref(selectedItem).variations && unref(selectedItem).variations.length) {
							_push(`<div class="divide-y divide-gray-200 dark:divide-gray-700"${_scopeId}><!--[-->`);
							ssrRenderList(unref(selectedItem).variations, (v, vi) => {
								_push(`<div class="grid grid-cols-6 gap-6 p-6"${_scopeId}>`);
								if (v.code) {
									_push(`<!--[--><div class="text-mute col-span-full font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Code"))}: <span class="text-focus"${_scopeId}>${ssrInterpolate(v.code)}</span> (${ssrInterpolate(_ctx.$meta(v.meta))}) </div><div class="col-span-6 sm:col-span-2"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$6), {
										type: "number",
										id: "item-quantity-v" + vi,
										label: _ctx.$t("Quantity"),
										modelValue: unref(selectedItem).variations[vi].quantity,
										"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].quantity = $event
									}, null, _parent, _scopeId));
									_push(`</div>`);
									if (unref(selectedItem).product.unit?.subunits?.length) {
										_push(`<div class="col-span-6 sm:col-span-4"${_scopeId}>`);
										_push(ssrRenderComponent(unref(_sfc_main$4), {
											json: true,
											"value-key": "id",
											id: "item-unit",
											"label-key": "name",
											searchable: false,
											label: _ctx.$t("Unit"),
											modelValue: unref(selectedItem).variations[vi].unit_id,
											"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].unit_id = $event,
											suggestions: [{
												...unref(selectedItem).product.unit,
												subunits: null
											}, ...unref(selectedItem).product.unit.subunits],
											onChange: () => {
												if (unref(selectedItem).variations[vi].unit_id == unref(selectedItem).product.unit.id) unref(selectedItem).variations[vi].price = Number(unref(selectedItem).product.price);
												else unref(selectedItem).variations[vi].price = Number(unref(selectedItem).product.unit_prices?.find((p) => p.unit_id == unref(selectedItem).variations[vi].unit_id)?.price || unref(convert_to_base_unit)(unref(selectedItem), unref(selectedItem).variations[vi].unit_id, unref(selectedItem).variations[vi].price || unref(selectedItem).price));
											}
										}, null, _parent, _scopeId));
										_push(`</div>`);
									} else _push(`<!---->`);
									_push(`<div class="col-span-6 sm:col-span-4"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$6), {
										type: "number",
										id: "item-cost-v" + vi,
										modelValue: unref(selectedItem).variations[vi].cost,
										"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].cost = $event,
										readonly: !unref(selectedItem).product.can_edit_price,
										label: unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price")
									}, null, _parent, _scopeId));
									_push(`</div><div class="col-span-6 sm:col-span-2"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$6), {
										label: _ctx.$t("Discount"),
										id: "item-discount-v" + vi,
										onKeypress: unref(discount_keypress),
										modelValue: unref(selectedItem).variations[vi].discount,
										"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].discount = $event,
										onChange: (e) => {
											let max_discount = unref(usePage)().props.settings?.max_discount || null;
											if (unref(selectedItem).variations[vi].discount.includes("%")) {
												if (Number(unref(selectedItem).variations[vi].discount.replace("%", "")) > Number(unref(selectedItem).product.max_discount)) {
													unref(selectedItem).variations[vi].discount = Number(unref(selectedItem).product.max_discount) + "%";
													unref(notify)({
														group: "main",
														type: "error",
														title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(unref(selectedItem).product.max_discount) })
													});
												} else if (Number(unref(selectedItem).variations[vi].discount.replace("%", "")) > Number(max_discount)) {
													unref(selectedItem).variations[vi].discount = Number(max_discount) + "%";
													unref(notify)({
														group: "main",
														type: "error",
														title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(max_discount) })
													});
												}
											}
										}
									}, null, _parent, _scopeId));
									_push(`</div><div class="${ssrRenderClass(unref(selectedItem).product.unit?.subunits?.length ? "col-span-full" : "col-span-6 sm:col-span-4")}"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$4), {
										json: true,
										"value-key": "id",
										multiple: true,
										"label-key": "name",
										searchable: false,
										suggestions: __props.taxes,
										label: _ctx.$t("Taxes"),
										id: "item-taxes-v" + vi,
										modelValue: unref(selectedItem).variations[vi].taxes,
										"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].taxes = $event,
										disabled: !unref(selectedItem).product.can_edit_taxes
									}, null, _parent, _scopeId));
									_push(`</div><!--]-->`);
								} else {
									_push(`<div class="col-span-full"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$2), {
										type: "button",
										onClick: () => {
											currentItem.value = unref(selectedItem);
											variantModal.value = true;
										}
									}, {
										default: withCtx((_, _push, _parent, _scopeId) => {
											if (_push) _push(`${ssrInterpolate(_ctx.$t("Select {x}", { x: _ctx.$t("Variation") }))}`);
											else return [createTextVNode(toDisplayString(_ctx.$t("Select {x}", { x: _ctx.$t("Variation") })), 1)];
										}),
										_: 2
									}, _parent, _scopeId));
									_push(`</div>`);
								}
								_push(`</div>`);
							});
							_push(`<!--]--></div>`);
						} else {
							_push(`<div class="grid grid-cols-6 gap-6 p-6"${_scopeId}><div class="col-span-6 sm:col-span-2"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								type: "number",
								id: "item-quantity",
								label: _ctx.$t("Quantity"),
								modelValue: unref(selectedItem).quantity,
								"onUpdate:modelValue": ($event) => unref(selectedItem).quantity = $event
							}, null, _parent, _scopeId));
							_push(`</div>`);
							if (unref(selectedItem).product.unit?.subunits?.length) {
								_push(`<div class="col-span-6 sm:col-span-4"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$4), {
									json: true,
									"value-key": "id",
									id: "item-unit",
									"label-key": "name",
									searchable: false,
									label: _ctx.$t("Unit"),
									modelValue: unref(selectedItem).unit_id,
									"onUpdate:modelValue": ($event) => unref(selectedItem).unit_id = $event,
									suggestions: [{
										...unref(selectedItem).product.unit,
										subunits: null
									}, ...unref(selectedItem).product.unit.subunits],
									onChange: () => {
										if (unref(selectedItem).unit_id == unref(selectedItem).product.unit.id) unref(selectedItem).price = Number(unref(selectedItem).product.price);
										else unref(selectedItem).price = Number(unref(selectedItem).product.unit_prices?.find((p) => p.unit_id == unref(selectedItem).unit_id)?.price || unref(convert_to_base_unit)(unref(selectedItem), unref(selectedItem).unit_id, unref(selectedItem).price));
									}
								}, null, _parent, _scopeId));
								_push(`</div>`);
							} else _push(`<!---->`);
							_push(`<div class="col-span-6 sm:col-span-4"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								type: "number",
								id: "item-cost",
								modelValue: unref(selectedItem).cost,
								"onUpdate:modelValue": ($event) => unref(selectedItem).cost = $event,
								readonly: !unref(selectedItem).product.can_edit_price,
								label: unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price")
							}, null, _parent, _scopeId));
							_push(`</div><div class="col-span-6 sm:col-span-2"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								id: "item-discount",
								label: _ctx.$t("Discount"),
								modelValue: unref(selectedItem).discount,
								"onUpdate:modelValue": ($event) => unref(selectedItem).discount = $event,
								onKeypress: unref(discount_keypress),
								onChange: (e) => {
									let max_discount = unref(usePage)().props.settings?.max_discount || null;
									if (unref(selectedItem).discount.includes("%")) {
										if (Number(unref(selectedItem).discount.replace("%", "")) > Number(unref(selectedItem).product.max_discount)) {
											unref(selectedItem).discount = Number(unref(selectedItem).product.max_discount) + "%";
											unref(notify)({
												group: "main",
												type: "error",
												title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(unref(selectedItem).product.max_discount) })
											});
										} else if (Number(unref(selectedItem).discount.replace("%", "")) > Number(max_discount)) {
											unref(selectedItem).discount = Number(max_discount) + "%";
											unref(notify)({
												group: "main",
												type: "error",
												title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(max_discount) })
											});
										}
									}
								}
							}, null, _parent, _scopeId));
							_push(`</div><div class="${ssrRenderClass(unref(selectedItem).product.unit?.subunits?.length ? "col-span-full" : "col-span-6 sm:col-span-4")}"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$4), {
								json: true,
								"value-key": "id",
								id: "item-taxes",
								multiple: true,
								"label-key": "name",
								searchable: false,
								suggestions: __props.taxes,
								label: _ctx.$t("Taxes"),
								modelValue: unref(selectedItem).taxes,
								"onUpdate:modelValue": ($event) => unref(selectedItem).taxes = $event,
								disabled: !unref(selectedItem).product.can_edit_taxes
							}, null, _parent, _scopeId));
							_push(`</div></div>`);
						}
						_push(`<div class="col-span-full flex items-center justify-between border-t border-gray-200 px-6 py-4 dark:border-gray-700"${_scopeId}><button type="button" class="focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"${_scopeId}>${ssrInterpolate(_ctx.$t("Remove"))}</button><button class="btn-primary"${_scopeId}>${ssrInterpolate(_ctx.$t("Update"))}</button></div></div></div>`);
					} else _push(`<!---->`);
					else return [unref(selectedItem) ? (openBlock(), createBlock("div", { key: 0 }, [createVNode("div", { class: "border-b border-gray-200 px-4 py-4 sm:px-6 dark:border-gray-700" }, [createVNode("div", { class: "sm:flex sm:items-baseline sm:justify-between" }, [createVNode("div", { class: "sm:w-0 sm:flex-1" }, [createVNode("h1", { class: "text-focus text-base font-semibold" }, toDisplayString(_ctx.$t("Edit {x}", { x: unref(selectedItem).name })), 1), createVNode("p", { class: "text-mute mt-1 truncate text-sm" }, toDisplayString(_ctx.$t("Please update the details below")), 1)])])]), createVNode("div", null, [unref(selectedItem).product.has_variants == 1 && unref(selectedItem).variations && unref(selectedItem).variations.length ? (openBlock(), createBlock("div", {
						key: 0,
						class: "divide-y divide-gray-200 dark:divide-gray-700"
					}, [(openBlock(true), createBlock(Fragment, null, renderList(unref(selectedItem).variations, (v, vi) => {
						return openBlock(), createBlock("div", {
							key: v.id,
							class: "grid grid-cols-6 gap-6 p-6"
						}, [v.code ? (openBlock(), createBlock(Fragment, { key: 0 }, [
							createVNode("div", { class: "text-mute col-span-full font-bold" }, [
								createTextVNode(toDisplayString(_ctx.$t("Code")) + ": ", 1),
								createVNode("span", { class: "text-focus" }, toDisplayString(v.code), 1),
								createTextVNode(" (" + toDisplayString(_ctx.$meta(v.meta)) + ") ", 1)
							]),
							createVNode("div", { class: "col-span-6 sm:col-span-2" }, [createVNode(unref(_sfc_main$6), {
								type: "number",
								id: "item-quantity-v" + vi,
								label: _ctx.$t("Quantity"),
								modelValue: unref(selectedItem).variations[vi].quantity,
								"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].quantity = $event
							}, null, 8, [
								"id",
								"label",
								"modelValue",
								"onUpdate:modelValue"
							])]),
							unref(selectedItem).product.unit?.subunits?.length ? (openBlock(), createBlock("div", {
								key: 0,
								class: "col-span-6 sm:col-span-4"
							}, [createVNode(unref(_sfc_main$4), {
								json: true,
								"value-key": "id",
								id: "item-unit",
								"label-key": "name",
								searchable: false,
								label: _ctx.$t("Unit"),
								modelValue: unref(selectedItem).variations[vi].unit_id,
								"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].unit_id = $event,
								suggestions: [{
									...unref(selectedItem).product.unit,
									subunits: null
								}, ...unref(selectedItem).product.unit.subunits],
								onChange: () => {
									if (unref(selectedItem).variations[vi].unit_id == unref(selectedItem).product.unit.id) unref(selectedItem).variations[vi].price = Number(unref(selectedItem).product.price);
									else unref(selectedItem).variations[vi].price = Number(unref(selectedItem).product.unit_prices?.find((p) => p.unit_id == unref(selectedItem).variations[vi].unit_id)?.price || unref(convert_to_base_unit)(unref(selectedItem), unref(selectedItem).variations[vi].unit_id, unref(selectedItem).variations[vi].price || unref(selectedItem).price));
								}
							}, null, 8, [
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"suggestions",
								"onChange"
							])])) : createCommentVNode("", true),
							createVNode("div", { class: "col-span-6 sm:col-span-4" }, [createVNode(unref(_sfc_main$6), {
								type: "number",
								id: "item-cost-v" + vi,
								modelValue: unref(selectedItem).variations[vi].cost,
								"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].cost = $event,
								readonly: !unref(selectedItem).product.can_edit_price,
								label: unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price")
							}, null, 8, [
								"id",
								"modelValue",
								"onUpdate:modelValue",
								"readonly",
								"label"
							])]),
							createVNode("div", { class: "col-span-6 sm:col-span-2" }, [createVNode(unref(_sfc_main$6), {
								label: _ctx.$t("Discount"),
								id: "item-discount-v" + vi,
								onKeypress: unref(discount_keypress),
								modelValue: unref(selectedItem).variations[vi].discount,
								"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].discount = $event,
								onChange: (e) => {
									let max_discount = unref(usePage)().props.settings?.max_discount || null;
									if (unref(selectedItem).variations[vi].discount.includes("%")) {
										if (Number(unref(selectedItem).variations[vi].discount.replace("%", "")) > Number(unref(selectedItem).product.max_discount)) {
											unref(selectedItem).variations[vi].discount = Number(unref(selectedItem).product.max_discount) + "%";
											unref(notify)({
												group: "main",
												type: "error",
												title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(unref(selectedItem).product.max_discount) })
											});
										} else if (Number(unref(selectedItem).variations[vi].discount.replace("%", "")) > Number(max_discount)) {
											unref(selectedItem).variations[vi].discount = Number(max_discount) + "%";
											unref(notify)({
												group: "main",
												type: "error",
												title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(max_discount) })
											});
										}
									}
								}
							}, null, 8, [
								"label",
								"id",
								"onKeypress",
								"modelValue",
								"onUpdate:modelValue",
								"onChange"
							])]),
							createVNode("div", { class: unref(selectedItem).product.unit?.subunits?.length ? "col-span-full" : "col-span-6 sm:col-span-4" }, [createVNode(unref(_sfc_main$4), {
								json: true,
								"value-key": "id",
								multiple: true,
								"label-key": "name",
								searchable: false,
								suggestions: __props.taxes,
								label: _ctx.$t("Taxes"),
								id: "item-taxes-v" + vi,
								modelValue: unref(selectedItem).variations[vi].taxes,
								"onUpdate:modelValue": ($event) => unref(selectedItem).variations[vi].taxes = $event,
								disabled: !unref(selectedItem).product.can_edit_taxes
							}, null, 8, [
								"suggestions",
								"label",
								"id",
								"modelValue",
								"onUpdate:modelValue",
								"disabled"
							])], 2)
						], 64)) : (openBlock(), createBlock("div", {
							key: 1,
							class: "col-span-full"
						}, [createVNode(unref(_sfc_main$2), {
							type: "button",
							onClick: () => {
								currentItem.value = unref(selectedItem);
								variantModal.value = true;
							}
						}, {
							default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Select {x}", { x: _ctx.$t("Variation") })), 1)]),
							_: 1
						}, 8, ["onClick"])]))]);
					}), 128))])) : (openBlock(), createBlock("div", {
						key: 1,
						class: "grid grid-cols-6 gap-6 p-6"
					}, [
						createVNode("div", { class: "col-span-6 sm:col-span-2" }, [createVNode(unref(_sfc_main$6), {
							type: "number",
							id: "item-quantity",
							label: _ctx.$t("Quantity"),
							modelValue: unref(selectedItem).quantity,
							"onUpdate:modelValue": ($event) => unref(selectedItem).quantity = $event
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue"
						])]),
						unref(selectedItem).product.unit?.subunits?.length ? (openBlock(), createBlock("div", {
							key: 0,
							class: "col-span-6 sm:col-span-4"
						}, [createVNode(unref(_sfc_main$4), {
							json: true,
							"value-key": "id",
							id: "item-unit",
							"label-key": "name",
							searchable: false,
							label: _ctx.$t("Unit"),
							modelValue: unref(selectedItem).unit_id,
							"onUpdate:modelValue": ($event) => unref(selectedItem).unit_id = $event,
							suggestions: [{
								...unref(selectedItem).product.unit,
								subunits: null
							}, ...unref(selectedItem).product.unit.subunits],
							onChange: () => {
								if (unref(selectedItem).unit_id == unref(selectedItem).product.unit.id) unref(selectedItem).price = Number(unref(selectedItem).product.price);
								else unref(selectedItem).price = Number(unref(selectedItem).product.unit_prices?.find((p) => p.unit_id == unref(selectedItem).unit_id)?.price || unref(convert_to_base_unit)(unref(selectedItem), unref(selectedItem).unit_id, unref(selectedItem).price));
							}
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"suggestions",
							"onChange"
						])])) : createCommentVNode("", true),
						createVNode("div", { class: "col-span-6 sm:col-span-4" }, [createVNode(unref(_sfc_main$6), {
							type: "number",
							id: "item-cost",
							modelValue: unref(selectedItem).cost,
							"onUpdate:modelValue": ($event) => unref(selectedItem).cost = $event,
							readonly: !unref(selectedItem).product.can_edit_price,
							label: unref(form).type == "Purchase" ? _ctx.$t("Cost") : _ctx.$t("Price")
						}, null, 8, [
							"modelValue",
							"onUpdate:modelValue",
							"readonly",
							"label"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-2" }, [createVNode(unref(_sfc_main$6), {
							id: "item-discount",
							label: _ctx.$t("Discount"),
							modelValue: unref(selectedItem).discount,
							"onUpdate:modelValue": ($event) => unref(selectedItem).discount = $event,
							onKeypress: unref(discount_keypress),
							onChange: (e) => {
								let max_discount = unref(usePage)().props.settings?.max_discount || null;
								if (unref(selectedItem).discount.includes("%")) {
									if (Number(unref(selectedItem).discount.replace("%", "")) > Number(unref(selectedItem).product.max_discount)) {
										unref(selectedItem).discount = Number(unref(selectedItem).product.max_discount) + "%";
										unref(notify)({
											group: "main",
											type: "error",
											title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(unref(selectedItem).product.max_discount) })
										});
									} else if (Number(unref(selectedItem).discount.replace("%", "")) > Number(max_discount)) {
										unref(selectedItem).discount = Number(max_discount) + "%";
										unref(notify)({
											group: "main",
											type: "error",
											title: _ctx.$t("You cannot apply discount more than {x}%", { x: Number(max_discount) })
										});
									}
								}
							}
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"onKeypress",
							"onChange"
						])]),
						createVNode("div", { class: unref(selectedItem).product.unit?.subunits?.length ? "col-span-full" : "col-span-6 sm:col-span-4" }, [createVNode(unref(_sfc_main$4), {
							json: true,
							"value-key": "id",
							id: "item-taxes",
							multiple: true,
							"label-key": "name",
							searchable: false,
							suggestions: __props.taxes,
							label: _ctx.$t("Taxes"),
							modelValue: unref(selectedItem).taxes,
							"onUpdate:modelValue": ($event) => unref(selectedItem).taxes = $event,
							disabled: !unref(selectedItem).product.can_edit_taxes
						}, null, 8, [
							"suggestions",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"disabled"
						])], 2)
					])), createVNode("div", { class: "col-span-full flex items-center justify-between border-t border-gray-200 px-6 py-4 dark:border-gray-700" }, [createVNode("button", {
						type: "button",
						onClick: ($event) => unref(removeItem)(unref(selectedItem)),
						class: "focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"
					}, toDisplayString(_ctx.$t("Remove")), 9, ["onClick"]), createVNode("button", {
						onClick: unref(updateItem),
						class: "btn-primary"
					}, toDisplayString(_ctx.$t("Update")), 9, ["onClick"])])])])) : createCommentVNode("", true)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$14), {
				show: scannerOpen.value,
				onScanned: handleBarcodeScan,
				onClose: ($event) => scannerOpen.value = false
			}, null, _parent));
			_push(`<!--]-->`);
		};
	}
});
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/Order/ReturnOrder/Form.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
