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$9, B as VariationSelection, M as _sfc_main$4, S as _sfc_main$5, T as _sfc_main$7, U as FormHelper, V as searchItems, Z as $extras, _ as _sfc_main$6, dt as _sfc_main$3, f as _sfc_main$8, j as _sfc_main$10 } from "../ssr.js";
import { t as _sfc_main$11 } from "./AdminLayout-eZgRfDMK.js";
import { router, useForm } from "@inertiajs/vue3";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, openBlock, ref, renderList, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrIncludeBooleanAttr, ssrInterpolate, ssrRenderAttr, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/Sma/Product/Transfer/Form.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$11 }, {
	__name: "Form",
	__ssrInlineRender: true,
	props: [
		"current",
		"custom_fields",
		"stores"
	],
	setup(__props) {
		const props = __props;
		const form = useForm({
			_method: props.current?.id ? "put" : "post",
			to_store_id: props.current?.to_store_id,
			reference: props.current?.reference,
			details: props.current?.details,
			items: props.current && props.current.items ? props.current.items.map((i) => ({
				...i,
				id: i.id,
				name: i.product.name,
				product_id: i.product_id,
				quantity: Number(i.quantity),
				old_quantity: Number(i.quantity),
				variations: i.variations.map((v) => ({
					...v,
					quantity: Number(v.pivot.quantity),
					old_quantity: Number(v.pivot.quantity)
				}))
			})) : [],
			extra_attributes: props.current ? $extras(props.custom_fields, props.current.extra_attributes) : $extras(props.custom_fields)
		});
		const { removeItem, resetForm, saveForm } = FormHelper(form);
		const { currentItem, deleteVariation, emptyVariation, variantModal, SelectVariant } = VariationSelection();
		const scannerOpen = ref(false);
		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 axios.get(B("products.show", item.id)).then((r) => r.data);
				currentItem.value = {
					...item,
					id: null,
					quantity: 1,
					product_id: item.id,
					product
				};
				if (product.has_variants == 1) {
					currentItem.value.variations = [emptyVariation(product)];
					variantModal.value = true;
				}
				form.items = [...form.items, { ...currentItem.value }];
			}
			saveForm();
		}
		async function handleBarcodeScan(code) {
			scannerOpen.value = false;
			const results = await searchItems(code, "transfer", 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,
					quantity: i.quantity,
					product_id: i.product_id,
					old_quantity: i.old_quantity,
					variations: i.variations && i.variations.length ? i.variations.map((v) => ({
						id: v.id,
						quantity: Number(v.quantity),
						old_quantity: v.old_quantity
					})) : null
				}));
				return form;
			}).post(props.current?.id ? B("transfers.update", props.current.id) : B("transfers.store"), { onSuccess: () => {
				resetForm();
				if (listing) router.get(B("transfers.index"));
			} });
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			const _component_Link = resolveComponent("Link");
			const _component_Icon = resolveComponent("Icon");
			_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("Transfer") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Transfer") }))}</title>`);
					else return [createVNode("title", null, toDisplayString(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Transfer") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Transfer") })), 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("Transfer") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Transfer") }))}`);
					else return [createTextVNode(toDisplayString(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Transfer") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Transfer") })), 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("transfer"),
							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)("transfers.index")
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("List {x}", { x: _ctx.$t("Transfers") }))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Transfers") })), 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("transfer"),
						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)("transfers.index")
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Transfers") })), 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), {
							json: true,
							"value-key": "id",
							"label-key": "name",
							id: "to_store_id",
							label: _ctx.$t("To"),
							onChange: unref(saveForm),
							modelValue: unref(form).to_store_id,
							"onUpdate:modelValue": ($event) => unref(form).to_store_id = $event,
							error: unref(form).errors.to_store_id,
							suggestions: __props.stores.filter((s) => s.id != _ctx.$page.props.selected_store)
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$5), {
							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><div class="col-span-full"${_scopeId}><div class="flex items-start gap-2"${_scopeId}><div class="flex-1"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$6), {
							model: "transfer",
							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="border-b border-gray-200 dark:border-gray-700"${_scopeId}><h4 class="mt-6 border-b border-gray-200 pb-1 text-lg font-bold dark:border-gray-700"${_scopeId}>${ssrInterpolate(_ctx.$t("Transfer Items"))}</h4><table class="w-full divide-y divide-gray-200 dark:divide-gray-700"${_scopeId}><!--[-->`);
							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}>${ssrInterpolate(item.name)}</td><td class="w-36 p-2"${_scopeId}></td><td class="w-6 p-2 text-end"${_scopeId}></td></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-36 p-2"${_scopeId}>`);
										_push(ssrRenderComponent(unref(_sfc_main$5), {
											min: 0,
											label: "",
											"del-on": 0,
											type: "number",
											onChange: () => {
												item.quantity = item.variations.reduce((a, v) => Number(v.quantity) + a, 0);
												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));
										_push(`</td><td class="w-6 p-2 text-end"${_scopeId}><button type="button" class="focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"${_scopeId}>`);
										_push(ssrRenderComponent(_component_Icon, {
											name: "trash-o",
											size: "size-5"
										}, null, _parent, _scopeId));
										_push(`</button></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}>${ssrInterpolate(item.name)}</td><td class="w-36 p-2"${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$5), {
										min: 0,
										label: "",
										"del-on": 0,
										type: "number",
										onChange: unref(saveForm),
										modelValue: item.quantity,
										"onUpdate:modelValue": ($event) => item.quantity = $event,
										placeholder: _ctx.$t("Quantity"),
										max: item.selected_store && item.selected_store[0] ? item.selected_store[0].pivot?.quantity : null
									}, null, _parent, _scopeId));
									_push(`</td><td class="w-6 p-2 text-end"${_scopeId}><button type="button" class="focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"${_scopeId}>`);
									_push(ssrRenderComponent(_component_Icon, {
										name: "trash-o",
										size: "size-5"
									}, null, _parent, _scopeId));
									_push(`</button></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${_scopeId}><tr${_scopeId}><th colspan="2" class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$t("Total quantity"))}</th><th class="p-2 text-end text-lg font-bold"${_scopeId}>${ssrInterpolate(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.quantity) + a, 0)))}</th><th${_scopeId}></th></tr></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$7), {
							errors: unref(form).errors,
							custom_fields: __props.custom_fields,
							extra_attributes: unref(form).extra_attributes,
							onUpdate: unref(saveForm)
						}, null, _parent, _scopeId));
						_push(ssrRenderComponent(unref(_sfc_main$8), {
							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), {
							json: true,
							"value-key": "id",
							"label-key": "name",
							id: "to_store_id",
							label: _ctx.$t("To"),
							onChange: unref(saveForm),
							modelValue: unref(form).to_store_id,
							"onUpdate:modelValue": ($event) => unref(form).to_store_id = $event,
							error: unref(form).errors.to_store_id,
							suggestions: __props.stores.filter((s) => s.id != _ctx.$page.props.selected_store)
						}, null, 8, [
							"label",
							"onChange",
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"suggestions"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$5), {
							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"
						])]),
						createVNode("div", { class: "col-span-full" }, [createVNode("div", { class: "flex items-start gap-2" }, [createVNode("div", { class: "flex-1" }, [createVNode(unref(_sfc_main$6), {
							model: "transfer",
							onAddItem: addItem
						})]), 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: "border-b border-gray-200 dark:border-gray-700"
						}, [createVNode("h4", { class: "mt-6 border-b border-gray-200 pb-1 text-lg font-bold dark:border-gray-700" }, toDisplayString(_ctx.$t("Transfer Items")), 1), createVNode("table", { class: "w-full divide-y divide-gray-200 dark:divide-gray-700" }, [(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" }, toDisplayString(item.name), 1),
								createVNode("td", { class: "w-36 p-2" }),
								createVNode("td", { class: "w-6 p-2 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-36 p-2" }, [createVNode(unref(_sfc_main$5), {
										min: 0,
										label: "",
										"del-on": 0,
										type: "number",
										onChange: () => {
											item.quantity = item.variations.reduce((a, v) => Number(v.quantity) + a, 0);
											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"
									])]),
									createVNode("td", { class: "w-6 p-2 text-end" }, [createVNode("button", {
										type: "button",
										onClick: ($event) => unref(deleteVariation)(variation, item),
										class: "focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"
									}, [createVNode(_component_Icon, {
										name: "trash-o",
										size: "size-5"
									})], 8, ["onClick"])])
								], 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" }, toDisplayString(item.name), 1),
								createVNode("td", { class: "w-36 p-2" }, [createVNode(unref(_sfc_main$5), {
									min: 0,
									label: "",
									"del-on": 0,
									type: "number",
									onChange: unref(saveForm),
									modelValue: item.quantity,
									"onUpdate:modelValue": ($event) => item.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"
								])]),
								createVNode("td", { class: "w-6 p-2 text-end" }, [createVNode("button", {
									type: "button",
									onClick: ($event) => unref(removeItem)(item),
									class: "focus rounded-md px-1 py-2.5 text-red-600 hover:text-red-500"
								}, [createVNode(_component_Icon, {
									name: "trash-o",
									size: "size-5"
								})], 8, ["onClick"])])
							]), 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", null, [createVNode("tr", null, [
							createVNode("th", {
								colspan: "2",
								class: "p-2 text-end text-lg font-bold"
							}, toDisplayString(_ctx.$t("Total quantity")), 1),
							createVNode("th", { class: "p-2 text-end text-lg font-bold" }, toDisplayString(_ctx.$decimal(unref(form).items.reduce((a, i) => Number(i.quantity) + a, 0))), 1),
							createVNode("th")
						])])])])) : (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$7), {
							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"
						]), createVNode(unref(_sfc_main$8), {
							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="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$9), {
							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>`);
					} else return [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$9), {
							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(currentItem) : 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 ? item : i);
					unref(saveForm)();
					variantModal.value = false;
				}
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</div>`);
			_push(ssrRenderComponent(unref(_sfc_main$10), {
				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/Product/Transfer/Form.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
