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$4, O as _sfc_main$6, S as _sfc_main$2, f as _sfc_main$5, tt as $random, vt as _sfc_main$8, w as _sfc_main$3 } from "../ssr.js";
import { n as _sfc_main$9 } from "./Form-BuxG2AwZ.js";
import { useForm } from "@inertiajs/vue3";
import { createTextVNode, createVNode, ref, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderComponent } from "vue/server-renderer";
import dayjs from "dayjs";
//#region resources/js/Pages/Sma/Order/GiftCard/Form.vue
var _sfc_main = {
	__name: "Form",
	__ssrInlineRender: true,
	props: [
		"current",
		"countries",
		"customer_fields"
	],
	emits: ["close", "done"],
	setup(__props, { emit: __emit }) {
		const emits = __emit;
		const props = __props;
		const customer = ref(null);
		const add_customer = ref(false);
		const form = useForm({
			_method: props.current?.id ? "put" : "post",
			number: props.current?.number,
			details: props.current?.details,
			customer_id: props.current?.customer_id,
			award_points: props.current?.award_points,
			use_award_points: props.current?.use_award_points == 1,
			amount: props.current ? Number(props.current.amount) : null,
			expiry_date: props.current ? props.current.expiry_date : dayjs().add(2, "year").format("YYYY-MM-DD")
		});
		if (props.current?.customer) customer.value = props.current.customer;
		const close = () => {
			form.reset();
			emits("close");
		};
		function generate() {
			form.number = $random(1e11, 0x2386f26fc10000);
		}
		return (_ctx, _push, _parent, _attrs) => {
			_push(`<!--[--><form><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("Gift Card") }) : _ctx.$t("Add {x}", { x: _ctx.$t("Gift Card") }))}</h1><p class="text-mute mt-1 truncate text-sm">${ssrInterpolate(_ctx.$t("Please fill the form below to {action} {record}.", {
				record: _ctx.$t("gift card"),
				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), {
				autofocus: "",
				action: generate,
				actionText: "Generate",
				label: _ctx.$t("Number"),
				modelValue: unref(form).number,
				"onUpdate:modelValue": ($event) => unref(form).number = $event,
				error: _ctx.$page.props.errors.number
			}, null, _parent));
			_push(`</div><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$2), {
				id: "amount",
				type: "number",
				label: _ctx.$t("Amount"),
				modelValue: unref(form).amount,
				"onUpdate:modelValue": ($event) => unref(form).amount = $event,
				readonly: __props.current?.id,
				error: unref(form).errors.amount
			}, null, _parent));
			_push(`</div><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$3), {
				type: "date",
				id: "expiry_date",
				label: _ctx.$t("Expiry Date"),
				modelValue: unref(form).expiry_date,
				"onUpdate:modelValue": ($event) => unref(form).expiry_date = $event,
				error: unref(form).errors.expiry_date
			}, null, _parent));
			_push(`</div><div class="col-span-6 sm:col-span-3">`);
			_push(ssrRenderComponent(unref(_sfc_main$4), {
				json: true,
				valueKey: "id",
				id: "customer_id",
				labelKey: "company",
				searchable: true,
				label: _ctx.$t("Customer"),
				modelValue: unref(form).customer_id,
				"onUpdate:modelValue": ($event) => unref(form).customer_id = $event,
				onChange: (e) => customer.value = e,
				action: () => add_customer.value = true,
				error: _ctx.$page.props.errors.customer_id,
				suggestions: unref(B)("search.customers"),
				"action-text": _ctx.$t("Add {x}", { x: _ctx.$t("Customer") })
			}, null, _parent));
			_push(`</div><div class="col-span-full">`);
			_push(ssrRenderComponent(unref(_sfc_main$5), {
				label: _ctx.$t("Details"),
				modelValue: unref(form).details,
				"onUpdate:modelValue": ($event) => unref(form).details = $event,
				error: _ctx.$page.props.errors.details
			}, null, _parent));
			_push(`</div>`);
			if (_ctx.$page.props.settings.loyalty?.customer?.spent && _ctx.$page.props.settings.loyalty?.customer?.points && customer.value && customer.value.points > 0) {
				_push(`<div class="col-span-full">`);
				_push(ssrRenderComponent(unref(_sfc_main$6), {
					disabled: __props.current?.id,
					label: _ctx.$t("Use Award Points"),
					checked: unref(form).use_award_points,
					"onUpdate:checked": ($event) => unref(form).use_award_points = $event,
					error: _ctx.$page.props.errors.use_award_points
				}, null, _parent));
				if (unref(form).use_award_points) {
					_push(`<div class="mt-6">`);
					_push(ssrRenderComponent(unref(_sfc_main$2), {
						min: 1,
						type: "number",
						id: "award_points",
						max: customer.value.points,
						readonly: __props.current?.id,
						label: _ctx.$t("Award Points"),
						modelValue: unref(form).award_points,
						"onUpdate:modelValue": ($event) => unref(form).award_points = $event,
						error: unref(form).errors.award_points
					}, null, _parent));
					_push(`<div class="mt-1 text-sm font-bold">${ssrInterpolate(_ctx.$t("Available Points"))}: ${ssrInterpolate(customer.value.points)}</div></div>`);
				} else _push(`<!---->`);
				_push(`</div>`);
			} else _push(`<!---->`);
			_push(`</div><div class="flex flex-row justify-end rounded-b-lg bg-gray-100 px-6 py-4 text-end dark:bg-gray-950">`);
			_push(ssrRenderComponent(unref(_sfc_main$1), { onClick: 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>`);
			_push(ssrRenderComponent(unref(_sfc_main$8), {
				show: add_customer.value,
				backdrop: false,
				overflow: true,
				"max-width": "2xl",
				closeable: true,
				onClose: ($event) => add_customer.value = false
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$9, {
						countries: __props.countries,
						custom_fields: __props.customer_fields,
						onClose: ($event) => add_customer.value = false,
						onDone: (e) => {
							unref(form).customer_id = e?.id;
							add_customer.value = false;
						}
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$9, {
						countries: __props.countries,
						custom_fields: __props.customer_fields,
						onClose: ($event) => add_customer.value = false,
						onDone: (e) => {
							unref(form).customer_id = e?.id;
							add_customer.value = false;
						}
					}, null, 8, [
						"countries",
						"custom_fields",
						"onClose",
						"onDone"
					])];
				}),
				_: 1
			}, _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/GiftCard/Form.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
