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$6, S as _sfc_main$5, T as _sfc_main$9, U as FormHelper, Z as $extras, dt as _sfc_main$3, f as _sfc_main$10, u as _sfc_main$11, w as _sfc_main$4 } from "../ssr.js";
import { t as _sfc_main$13 } from "./AdminLayout-eZgRfDMK.js";
import { router, useForm } from "@inertiajs/vue3";
import { notify } from "notiwind";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, onMounted, openBlock, ref, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { useI18n } from "vue-i18n";
import { ssrInterpolate, ssrRenderComponent } from "vue/server-renderer";
import dayjs from "dayjs";
//#region resources/js/Pages/Sma/Product/StockCount/Form.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$13 }, {
	__name: "Form",
	__ssrInlineRender: true,
	props: [
		"current",
		"brands",
		"categories",
		"custom_fields"
	],
	setup(__props) {
		const { t } = useI18n();
		const props = __props;
		const finalize = ref(false);
		const form = useForm({
			_method: props.current?.id ? "put" : "post",
			file: null,
			date: dayjs(props.current?.date).format("YYYY-MM-DD"),
			reference: props.current?.reference,
			type: props.current?.type,
			details: props.current?.details,
			brands: props.current?.brands,
			categories: props.current?.categories,
			extra_attributes: props.current ? $extras(props.custom_fields, props.current.extra_attributes) : $extras(props.custom_fields)
		});
		const { resetForm, saveForm } = FormHelper(form);
		const { currentItem, variantModal, SelectVariant } = VariationSelection();
		onMounted(() => {
			if (props.current?.id && props.current?.completed_at) {
				notify({
					group: "main",
					type: "error",
					title: t("Stock count has already completed.")
				});
				router.get(B("stock_counts.index"));
			}
		});
		function handleSubmit() {
			form.errors = {};
			form.transform((data) => {
				const form = { ...data };
				try {
					form.date = form.date.toString().includes("T") ? form.date.toString().split("T")[0] : form.date;
				} catch {}
				return form;
			}).post(props.current?.id ? B("stock_counts.update", props.current.id) : B("stock_counts.store"), {
				forceFormData: true,
				onSuccess: () => {
					resetForm();
				}
			});
		}
		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("Complete Stock Count") : _ctx.$t("Start Stock Count"))}</title>`);
					else return [createVNode("title", null, toDisplayString(__props.current?.id ? _ctx.$t("Complete Stock Count") : _ctx.$t("Start Stock Count")), 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("Complete Stock Count") : _ctx.$t("Start Stock Count"))}`);
					else return [createTextVNode(toDisplayString(__props.current?.id ? _ctx.$t("Complete Stock Count") : _ctx.$t("Start Stock Count")), 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("stock count"),
							action: __props.current?.id ? _ctx.$t("complete") : _ctx.$t("start")
						}))}</div><div class="me-3 mt-6 sm:mt-0 lg:mt-6"${_scopeId}>`);
						_push(ssrRenderComponent(_component_Link, {
							class: "link",
							href: unref(B)("stock_counts.index")
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("List {x}", { x: _ctx.$t("Stock Counts") }))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Stock Counts") })), 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("stock count"),
						action: __props.current?.id ? _ctx.$t("complete") : _ctx.$t("start")
					})), 1), createVNode("div", { class: "me-3 mt-6 sm:mt-0 lg:mt-6" }, [createVNode(_component_Link, {
						class: "link",
						href: unref(B)("stock_counts.index")
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("List {x}", { x: _ctx.$t("Stock Counts") })), 1)]),
						_: 1
					}, 8, ["href"])])])];
				}),
				form: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						if (!__props.current?.id || !finalize.value) {
							_push(`<!--[--><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$4), {
								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$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-6 sm:col-span-3"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$6), {
								id: "type",
								json: true,
								onChange: unref(saveForm),
								label: _ctx.$t("Type"),
								modelValue: unref(form).type,
								"onUpdate:modelValue": ($event) => unref(form).type = $event,
								error: unref(form).errors.type,
								suggestions: [{
									value: "full",
									label: _ctx.$t("Full Stock Count")
								}, {
									value: "partial",
									label: _ctx.$t("Partial Stock Count")
								}]
							}, 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(`<!---->`);
							if (unref(form).type == "partial") {
								_push(`<!--[--><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$6), {
									json: "",
									multiple: "",
									id: "brands",
									valueKey: "id",
									labelKey: "name",
									searchable: false,
									label: _ctx.$t("Brands"),
									suggestions: __props.brands,
									modelValue: unref(form).brands,
									"onUpdate:modelValue": ($event) => unref(form).brands = $event,
									error: unref(form).errors.brands
								}, null, _parent, _scopeId));
								_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$6), {
									json: "",
									multiple: "",
									valueKey: "id",
									labelKey: "name",
									id: "categories",
									searchable: false,
									label: _ctx.$t("Categories"),
									suggestions: __props.categories,
									modelValue: unref(form).categories,
									"onUpdate:modelValue": ($event) => unref(form).categories = $event,
									error: unref(form).errors.categories
								}, null, _parent, _scopeId));
								_push(`</div><!--]-->`);
							} else _push(`<!---->`);
							_push(`<div class="col-span-full flex flex-col gap-6"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$9), {
								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$10), {
								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 if (__props.current?.id && finalize.value) {
							_push(`<!--[-->`);
							if (__props.current?.id) {
								_push(`<div class="col-span-full"${_scopeId}>`);
								_push(ssrRenderComponent(unref(_sfc_main$7), {
									id: "file",
									accept: ".xlsx",
									modelValue: unref(form).file,
									"onUpdate:modelValue": ($event) => unref(form).file = $event,
									label: _ctx.$t("Final File"),
									error: unref(form).errors.file
								}, null, _parent, _scopeId));
								_push(`</div>`);
							} else _push(`<!---->`);
							_push(`<!--]-->`);
						} else _push(`<!---->`);
						if (__props.current?.id) {
							_push(`<div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$11), {
								id: "finalize",
								label: _ctx.$t("Finalize"),
								modelValue: finalize.value,
								"onUpdate:modelValue": ($event) => finalize.value = $event
							}, null, _parent, _scopeId));
							_push(`</div>`);
						} else _push(`<!---->`);
					} else return [!__props.current?.id || !finalize.value ? (openBlock(), createBlock(Fragment, { key: 0 }, [
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$4), {
							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$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-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							id: "type",
							json: true,
							onChange: unref(saveForm),
							label: _ctx.$t("Type"),
							modelValue: unref(form).type,
							"onUpdate:modelValue": ($event) => unref(form).type = $event,
							error: unref(form).errors.type,
							suggestions: [{
								value: "full",
								label: _ctx.$t("Full Stock Count")
							}, {
								value: "partial",
								label: _ctx.$t("Partial Stock Count")
							}]
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"suggestions"
						])]),
						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: 0,
							class: "col-span-full"
						}, [createVNode(unref(_sfc_main$8), { attachments: __props.current.attachments || [] }, null, 8, ["attachments"])])) : createCommentVNode("", true),
						unref(form).type == "partial" ? (openBlock(), createBlock(Fragment, { key: 1 }, [createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							json: "",
							multiple: "",
							id: "brands",
							valueKey: "id",
							labelKey: "name",
							searchable: false,
							label: _ctx.$t("Brands"),
							suggestions: __props.brands,
							modelValue: unref(form).brands,
							"onUpdate:modelValue": ($event) => unref(form).brands = $event,
							error: unref(form).errors.brands
						}, null, 8, [
							"label",
							"suggestions",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])]), createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							json: "",
							multiple: "",
							valueKey: "id",
							labelKey: "name",
							id: "categories",
							searchable: false,
							label: _ctx.$t("Categories"),
							suggestions: __props.categories,
							modelValue: unref(form).categories,
							"onUpdate:modelValue": ($event) => unref(form).categories = $event,
							error: unref(form).errors.categories
						}, null, 8, [
							"label",
							"suggestions",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])])], 64)) : createCommentVNode("", true),
						createVNode("div", { class: "col-span-full flex flex-col gap-6" }, [createVNode(unref(_sfc_main$9), {
							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$10), {
							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"
						])])
					], 64)) : __props.current?.id && finalize.value ? (openBlock(), createBlock(Fragment, { key: 1 }, [__props.current?.id ? (openBlock(), createBlock("div", {
						key: 0,
						class: "col-span-full"
					}, [createVNode(unref(_sfc_main$7), {
						id: "file",
						accept: ".xlsx",
						modelValue: unref(form).file,
						"onUpdate:modelValue": ($event) => unref(form).file = $event,
						label: _ctx.$t("Final File"),
						error: unref(form).errors.file
					}, null, 8, [
						"modelValue",
						"onUpdate:modelValue",
						"label",
						"error"
					])])) : createCommentVNode("", true)], 64)) : createCommentVNode("", true), __props.current?.id ? (openBlock(), createBlock("div", {
						key: 2,
						class: "col-span-full"
					}, [createVNode(unref(_sfc_main$11), {
						id: "finalize",
						label: _ctx.$t("Finalize"),
						modelValue: finalize.value,
						"onUpdate:modelValue": ($event) => finalize.value = $event
					}, null, 8, [
						"label",
						"modelValue",
						"onUpdate:modelValue"
					])])) : createCommentVNode("", true)];
				}),
				actions: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="flex w-full items-center justify-between"${_scopeId}><div${_scopeId}>`);
						if (!__props.current?.id) _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));
						else _push(`<!---->`);
						_push(`</div><div class="flex items-center justify-end"${_scopeId}>`);
						_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>`);
					} else return [createVNode("div", { class: "flex w-full items-center justify-between" }, [createVNode("div", null, [!__props.current?.id ? (openBlock(), createBlock(unref(_sfc_main$2), {
						key: 0,
						type: "button",
						onClick: unref(resetForm),
						class: "me-3"
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Reset")), 1)]),
						_: 1
					}, 8, ["onClick"])) : createCommentVNode("", true)]), createVNode("div", { class: "flex items-center justify-end" }, [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(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><!--]-->`);
		};
	}
});
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/StockCount/Form.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
