import { t as B } from "./index.esm-0G7eAEV5.js";
import { t as _sfc_main$1 } from "./SecondaryButton-ub85RH3e.js";
import { A as _sfc_main$7, M as _sfc_main$3, O as _sfc_main$6, S as _sfc_main$2, Y as $decimal, f as _sfc_main$5, ut as _sfc_main$4 } from "../ssr.js";
import { useForm } from "@inertiajs/vue3";
import { createTextVNode, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { useI18n } from "vue-i18n";
import { ssrIncludeBooleanAttr, ssrInterpolate, ssrLooseContain, ssrLooseEqual, ssrRenderAttr, ssrRenderAttrs, ssrRenderComponent } from "vue/server-renderer";
import dayjs from "dayjs";
//#region resources/js/Pages/Sma/Product/Promotion/Form.vue
var _sfc_main = {
	__name: "Form",
	__ssrInlineRender: true,
	props: [
		"current",
		"types",
		"stores"
	],
	emits: ["close", "done"],
	setup(__props, { emit: __emit }) {
		const { t } = useI18n();
		const emits = __emit;
		const props = __props;
		const promo_types = [
			{
				value: "simple",
				label: t("Simple")
			},
			{
				value: "advance",
				label: t("Advance")
			},
			{
				value: "BXGY",
				label: t("Buy X get Y (BXGY)")
			},
			{
				value: "SXGD",
				label: t("Spend X Get Discount (SXGD)")
			}
		];
		const form = useForm({
			_method: props.current?.id ? "put" : "post",
			name: props.current?.name,
			type: props.current?.type,
			discount: props.current?.discount ? $decimal(props.current?.discount) : null,
			discount_method: props.current?.discount_method || "percentage",
			details: props.current?.details,
			products: props.current?.products?.length ? props.current?.products?.map((product) => product.id) : null,
			categories: props.current?.categories?.length ? props.current?.categories?.map((category) => category.id) : null,
			stores: props.current?.stores?.length ? props.current?.stores?.map((store) => store.id) : null,
			amount_to_spend: props.current?.amount_to_spend,
			start_date: props.current?.start_date ? dayjs(props.current.start_date).format("YYYY-MM-DD") : null,
			end_date: props.current?.end_date ? dayjs(props.current.end_date).add(1, "year").format("YYYY-MM-DD") : null,
			product_id_to_buy: props.current?.product_id_to_buy,
			product_id_to_get: props.current?.product_id_to_get,
			quantity_to_buy: props.current?.quantity_to_buy ? $decimal(props.current?.quantity_to_buy) : null,
			quantity_to_get: props.current?.quantity_to_get ? $decimal(props.current?.quantity_to_get) : null,
			active: props.current?.id ? props.current?.active == 1 : true
		});
		return (_ctx, _push, _parent, _attrs) => {
			_push(`<form${ssrRenderAttrs(_attrs)}><div class="border-b border-gray-200 px-6 py-4 dark:border-gray-700"><div class="sm:flex sm:items-baseline sm:justify-between"><div class="sm:w-0 sm:flex-1"><h1 class="text-focus text-base font-semibold">${ssrInterpolate(__props.current?.id ? _ctx.$t("Edit {x}", { x: _ctx.$t("Promotion") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Promotion") }))}</h1><p class="text-mute mt-1 truncate text-sm">${ssrInterpolate(_ctx.$t("Please fill the form below to {action} {record}.", {
				record: _ctx.$t("tax"),
				action: __props.current?.id ? _ctx.$t("edit") : _ctx.$t("add")
			}))}</p></div></div></div><div class="grid grid-cols-6 gap-6 p-6"><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$2), {
				id: "name",
				label: _ctx.$t("Name"),
				modelValue: unref(form).name,
				"onUpdate:modelValue": ($event) => unref(form).name = $event,
				error: unref(form).errors.name
			}, null, _parent));
			_push(`</div><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), {
				id: "type",
				json: true,
				label: _ctx.$t("Type"),
				searchable: false,
				modelValue: unref(form).type,
				"onUpdate:modelValue": ($event) => unref(form).type = $event,
				error: unref(form).errors.type,
				suggestions: promo_types
			}, null, _parent));
			_push(`</div><span class="sr-only">${ssrInterpolate(_ctx.$t("Simple"))} ${ssrInterpolate(_ctx.$t("Advance"))} ${ssrInterpolate(_ctx.$t("BXGY"))} ${ssrInterpolate(_ctx.$t("SXGD"))} ${ssrInterpolate(_ctx.$t("Buy X get Y (BXGY)"))} ${ssrInterpolate(_ctx.$t("Spend X Get Discount (SXGD)"))}</span>`);
			if (unref(form).type != "BXGY") {
				_push(`<div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$4), {
					value: _ctx.$t("Discount"),
					class: "mb-1"
				}, null, _parent));
				_push(`<div class="flex items-center rounded-md bg-white pt-0.5 outline outline-1 -outline-offset-1 outline-gray-300 has-[input:focus-within]:outline-2 has-[input:focus-within]:-outline-offset-2 has-[input:focus-within]:outline-primary-600 dark:bg-gray-900 dark:outline-gray-700"><input type="number" id="discount" pattern="[0-9]"${ssrRenderAttr("placeholder", _ctx.$t("Discount"))}${ssrRenderAttr("value", unref(form).discount)} class="grow rounded-md border-0 py-2 shadow-xs focus:ring-0 focus:outline-hidden dark:bg-gray-900 dark:text-gray-300"><div class="grid shrink-0 grid-cols-1 focus-within:relative"><select id="discount_method" class="col-start-1 row-start-1 w-full appearance-none rounded-md border-0 bg-white bg-none px-3 py-1.5 text-end text-base placeholder:text-gray-400 focus:ring-0 focus:outline-hidden sm:text-sm/6 dark:bg-gray-900"><option value="fixed"${ssrIncludeBooleanAttr(Array.isArray(unref(form).discount_method) ? ssrLooseContain(unref(form).discount_method, "fixed") : ssrLooseEqual(unref(form).discount_method, "fixed")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("Fixed"))}</option><option value="percentage"${ssrIncludeBooleanAttr(Array.isArray(unref(form).discount_method) ? ssrLooseContain(unref(form).discount_method, "percentage") : ssrLooseEqual(unref(form).discount_method, "percentage")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("Percentage"))}</option></select></div></div></div>`);
			} else _push(`<!---->`);
			if (unref(form).type == "advance") {
				_push(`<div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$2), {
					type: "number",
					id: "quantity_to_buy",
					label: _ctx.$t("Quantity to buy"),
					modelValue: unref(form).quantity_to_buy,
					"onUpdate:modelValue": ($event) => unref(form).quantity_to_buy = $event,
					error: unref(form).errors.quantity_to_buy
				}, null, _parent));
				_push(`</div>`);
			} else if (unref(form).type == "SXGD") {
				_push(`<div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$2), {
					type: "number",
					id: "amount_to_spend",
					label: _ctx.$t("Amount to spend"),
					modelValue: unref(form).amount_to_spend,
					"onUpdate:modelValue": ($event) => unref(form).amount_to_spend = $event,
					error: unref(form).errors.amount_to_spend
				}, null, _parent));
				_push(`</div>`);
			} else if (unref(form).type == "BXGY") {
				_push(`<!--[--><div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$3), {
					json: true,
					valueKey: "id",
					labelKey: "name",
					searchable: true,
					id: "product_id_to_buy",
					label: _ctx.$t("Product to buy"),
					modelValue: unref(form).product_id_to_buy,
					"onUpdate:modelValue": ($event) => unref(form).product_id_to_buy = $event,
					error: unref(form).errors.product_id_to_buy,
					suggestions: unref(B)("search.products")
				}, null, _parent));
				_push(`</div><div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$2), {
					type: "number",
					id: "quantity_to_buy",
					label: _ctx.$t("Quantity to buy"),
					modelValue: unref(form).quantity_to_buy,
					"onUpdate:modelValue": ($event) => unref(form).quantity_to_buy = $event,
					error: unref(form).errors.quantity_to_buy
				}, null, _parent));
				_push(`</div><div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$3), {
					json: true,
					valueKey: "id",
					labelKey: "name",
					searchable: true,
					id: "product_id_to_get",
					label: _ctx.$t("Product to get"),
					modelValue: unref(form).product_id_to_get,
					"onUpdate:modelValue": ($event) => unref(form).product_id_to_get = $event,
					error: unref(form).errors.product_id_to_get,
					suggestions: unref(B)("search.products")
				}, null, _parent));
				_push(`</div><div class="col-span-6 sm:col-span-3">`);
				_push(ssrRenderComponent(unref(_sfc_main$2), {
					type: "number",
					id: "quantity_to_get",
					label: _ctx.$t("Quantity to get"),
					modelValue: unref(form).quantity_to_get,
					"onUpdate:modelValue": ($event) => unref(form).quantity_to_get = $event,
					error: unref(form).errors.quantity_to_get
				}, null, _parent));
				_push(`</div><!--]-->`);
			} else _push(`<!---->`);
			_push(`<div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$2), {
				type: "date",
				id: "start_date",
				label: _ctx.$t("Start Date"),
				modelValue: unref(form).start_date,
				"onUpdate:modelValue": ($event) => unref(form).start_date = $event,
				error: unref(form).errors.start_date
			}, null, _parent));
			_push(`</div><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$2), {
				type: "date",
				id: "end_date",
				label: _ctx.$t("End Date"),
				modelValue: unref(form).end_date,
				"onUpdate:modelValue": ($event) => unref(form).end_date = $event,
				error: unref(form).errors.end_date
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), {
				json: true,
				id: "products",
				valueKey: "id",
				labelKey: "name",
				multiple: true,
				searchable: true,
				modelValue: unref(form).products,
				"onUpdate:modelValue": ($event) => unref(form).products = $event,
				label: _ctx.$t("Products"),
				error: unref(form).errors.products,
				suggestions: unref(B)("search.products")
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), {
				json: true,
				valueKey: "id",
				labelKey: "name",
				id: "categories",
				multiple: true,
				searchable: true,
				modelValue: unref(form).categories,
				"onUpdate:modelValue": ($event) => unref(form).categories = $event,
				label: _ctx.$t("Categories"),
				error: unref(form).errors.categories,
				suggestions: unref(B)("search.categories")
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), {
				json: true,
				id: "stores",
				valueKey: "id",
				labelKey: "name",
				multiple: true,
				searchable: true,
				modelValue: unref(form).stores,
				"onUpdate:modelValue": ($event) => unref(form).stores = $event,
				label: _ctx.$t("Stores"),
				suggestions: __props.stores,
				error: unref(form).errors.stores
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$5), {
				id: "details",
				label: _ctx.$t("Details"),
				modelValue: unref(form).details,
				"onUpdate:modelValue": ($event) => unref(form).details = $event,
				error: unref(form).errors.details
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$6), {
				id: "active",
				error: unref(form).errors.active,
				checked: unref(form).active,
				"onUpdate:checked": ($event) => unref(form).active = $event,
				label: _ctx.$t("Active")
			}, null, _parent));
			_push(`</div></div><div class="flex flex-row justify-end bg-gray-100 px-6 py-4 text-end dark:bg-gray-950">`);
			_push(ssrRenderComponent(unref(_sfc_main$1), { onClick: ($event) => emits("close") }, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Cancel"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Cancel")), 1)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$7), {
				class: "ms-3",
				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));
			_push(`</div></form>`);
		};
	}
};
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/Promotion/Form.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
