import { t as B } from "./index.esm-0G7eAEV5.js";
import { t as _sfc_main$1 } from "./ActionMessage-DRAWBZho.js";
import { A as _sfc_main$8, M as _sfc_main$6, O as _sfc_main$4, S as _sfc_main$5, dt as _sfc_main$3, f as _sfc_main$7, p as _sfc_main$2 } from "../ssr.js";
import { t as _sfc_main$9 } from "./AdminLayout-eZgRfDMK.js";
import { useForm } from "@inertiajs/vue3";
import { Fragment, createBlock, createCommentVNode, createTextVNode, createVNode, onMounted, openBlock, ref, renderList, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { useI18n } from "vue-i18n";
import { ssrInterpolate, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/Sma/Setting/Payment.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$9 }, {
	__name: "Payment",
	__ssrInlineRender: true,
	props: {
		current: Object,
		payment_methods: Array
	},
	setup(__props) {
		const { t } = useI18n({});
		const props = __props;
		const tab_links = ref([
			{
				label: t("General Settings"),
				route: "settings.index",
				icon: "settings"
			},
			{
				label: t("Mail Settings"),
				route: "settings.mail",
				icon: "envelope"
			},
			{
				label: t("Payment Settings"),
				route: "settings.payment",
				icon: "dollar"
			},
			{
				label: t("Scale Barcode Settings"),
				route: "settings.barcode",
				icon: "scale"
			}
		]);
		if (B().has("settings.pos")) tab_links.value.push({
			label: t("POS Settings"),
			route: "settings.pos",
			icon: "pos"
		});
		if (B().has("shop.settings")) tab_links.value.push({
			label: t("Shop Settings"),
			route: "shop.settings",
			icon: "shop",
			external: true
		});
		const form = useForm({
			gateway: props.current?.gateway || null,
			default_currency: props.current?.default_currency || "USD",
			stripe_terminal: props.current?.stripe_terminal == 1 || false,
			static_payment_methods: props.current?.static_payment_methods ? props.current.static_payment_methods.join("\n") : "",
			services: {
				...props.current?.services,
				paypal: {
					enabled: props.current?.services?.paypal?.enabled == true,
					client_id: props.current?.services?.paypal?.client_id || null,
					secret: props.current?.services?.paypal?.secret || null,
					fixed: props.current?.services?.paypal?.fixed || null,
					same_country: props.current?.services?.paypal?.same_country || null,
					other_countries: props.current?.services?.paypal?.other_countries || null
				},
				stripe: {
					key: props.current?.services?.stripe?.key || null,
					secret: props.current?.services?.stripe?.secret || null,
					fixed: props.current?.services?.stripe?.fixed || null,
					same_country: props.current?.services?.stripe?.same_country || null,
					other_countries: props.current?.services?.stripe?.other_countries || null
				},
				paymes: {
					public_key: props.current?.services?.paymes?.public_key || null,
					secret_key: props.current?.services?.paymes?.secret_key || null
				},
				authorize: {
					login: props.current?.services?.authorize?.login || null,
					transaction_key: props.current?.services?.authorize?.transaction_key || null
				}
			}
		});
		onMounted(() => {
			Object.keys(props.payment_methods).forEach((key) => {
				Object.keys(props.payment_methods[key].fields).map((field) => {
					setDeepValue(form, props.payment_methods[key].fields[field].config, getDeepValue(props.current, props.payment_methods[key].fields[field].config) || null);
				});
			});
		});
		function getDeepValue(object, path) {
			return path.split(".").reduce((obj, key) => {
				return obj && obj[key] !== "undefined" ? obj[key] : void 0;
			}, object);
		}
		function setDeepValue(object, path, value) {
			const keys = path.split(".");
			let current = object;
			for (let i = 0; i < keys.length - 1; i++) {
				const key = keys[i];
				if (!current[key] || typeof current[key] !== "object") current[key] = {};
				current = current[key];
			}
			current[keys[keys.length - 1]] = value;
			object[path] = value;
		}
		const staticMethodsText = ref(form.static_payment_methods || "");
		function save() {
			form.transform((data) => ({
				...data,
				static_payment_methods: staticMethodsText.value.split("\n").map((m) => m.trim()).filter(Boolean)
			})).post(B("settings.payment.store"));
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			_push(`<!--[-->`);
			_push(ssrRenderComponent(_component_Head, null, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`<title${_scopeId}>${ssrInterpolate(_ctx.$t("Payment Settings"))}</title>`);
					else return [createVNode("title", null, toDisplayString(_ctx.$t("Payment Settings")), 1)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$2), { links: tab_links.value }, null, _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: save }, {
				title: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Payment Settings"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Payment Settings")), 1)];
				}),
				description: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Please configure the payment settings."))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Please configure the payment settings.")), 1)];
				}),
				form: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="col-span-full flex gap-x-8 gap-y-4"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$4), {
							id: "paypal-enabled",
							label: _ctx.$t("Enable PayPal Payments"),
							checked: unref(form).services.paypal.enabled,
							"onUpdate:checked": ($event) => unref(form).services.paypal.enabled = $event,
							error: unref(form).errors.services?.paypal?.enabled
						}, null, _parent, _scopeId));
						_push(ssrRenderComponent(unref(_sfc_main$4), {
							id: "stripe-terminal",
							label: _ctx.$t("Enable Stripe Terminal"),
							checked: unref(form).stripe_terminal,
							"onUpdate:checked": ($event) => unref(form).stripe_terminal = $event,
							error: unref(form).errors.stripe_terminal
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$5), {
							modelValue: unref(form).default_currency,
							"onUpdate:modelValue": ($event) => unref(form).default_currency = $event,
							error: unref(form).errors.default_currency,
							label: _ctx.$t("Default Currency")
						}, null, _parent, _scopeId));
						_push(`</div><div class="col-span-6 sm:col-span-3"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$6), {
							json: true,
							id: "gateway",
							searchable: false,
							label: _ctx.$t("Credit Card Gateway"),
							modelValue: unref(form).gateway,
							"onUpdate:modelValue": ($event) => unref(form).gateway = $event,
							error: unref(form).errors.gateway,
							suggestions: [
								{
									value: null,
									label: _ctx.$t("Disabled")
								},
								{
									value: "PayPal Rest",
									label: "PayPal Rest"
								},
								{
									value: "Stripe",
									label: "Stripe"
								},
								...Object.keys(__props.payment_methods)?.map((key) => {
									return {
										value: key,
										label: __props.payment_methods[key].name
									};
								})
							]
						}, null, _parent, _scopeId));
						_push(`</div>`);
						if (__props.payment_methods[unref(form).gateway]) {
							_push(`<div class="col-span-full flex flex-col gap-4 rounded-md bg-gray-100 p-4 dark:bg-gray-800"${_scopeId}><!--[-->`);
							ssrRenderList(__props.payment_methods[unref(form).gateway].fields, (field, key) => {
								_push(`<div${_scopeId}>`);
								if (field.type == "checkbox") _push(ssrRenderComponent(unref(_sfc_main$4), {
									id: field.config,
									checked: unref(form)[field.config] == 1,
									"onUpdate:checked": (e) => setDeepValue(unref(form), field.config, e ? 1 : 0),
									label: field.label || key.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
									error: unref(form).errors[field.config] ? unref(form).errors[field.config].replace("services.", "").replaceAll(".", " ") : null
								}, null, _parent, _scopeId));
								else _push(ssrRenderComponent(unref(_sfc_main$5), {
									modelValue: unref(form)[field.config],
									"onUpdate:modelValue": ($event) => unref(form)[field.config] = $event,
									onChange: (e) => setDeepValue(unref(form), field.config, e.target.value),
									label: field.label || key.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
									error: unref(form).errors[field.config] ? unref(form).errors[field.config].replace("services.", "").replaceAll(".", " ") : null
								}, null, _parent, _scopeId));
								_push(`</div>`);
							});
							_push(`<!--]--></div>`);
						} else _push(`<!---->`);
						if (unref(form).services.paypal.enabled || unref(form).gateway == "PayPal Rest") {
							_push(`<!--[--><div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$5), {
								label: _ctx.$t("PayPal Client Id"),
								modelValue: unref(form).services.paypal.client_id,
								"onUpdate:modelValue": ($event) => unref(form).services.paypal.client_id = $event,
								error: unref(form).errors["services.paypal.client_id"] ? unref(form).errors["services.paypal.client_id"].replace("services.", "").replaceAll(".", " ") : null
							}, null, _parent, _scopeId));
							_push(`</div><div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$5), {
								label: _ctx.$t("PayPal Secret"),
								modelValue: unref(form).services.paypal.secret,
								"onUpdate:modelValue": ($event) => unref(form).services.paypal.secret = $event,
								error: unref(form).errors["services.paypal.secret"] ? unref(form).errors["services.paypal.secret"].replace("services.", "").replaceAll(".", " ") : null
							}, null, _parent, _scopeId));
							_push(`</div><!--]-->`);
						} else _push(`<!---->`);
						if (unref(form).stripe_terminal || unref(form).gateway == "Stripe") {
							_push(`<!--[--><div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$5), {
								label: _ctx.$t("Stripe Publishable Key"),
								modelValue: unref(form).services.stripe.key,
								"onUpdate:modelValue": ($event) => unref(form).services.stripe.key = $event,
								error: unref(form).errors["services.stripe.key"] ? unref(form).errors["services.stripe.key"].replace("services.", "").replaceAll(".", " ") : null
							}, null, _parent, _scopeId));
							_push(`</div><div class="col-span-full"${_scopeId}>`);
							_push(ssrRenderComponent(unref(_sfc_main$5), {
								label: _ctx.$t("Stripe Secret Key"),
								modelValue: unref(form).services.stripe.secret,
								"onUpdate:modelValue": ($event) => unref(form).services.stripe.secret = $event,
								error: unref(form).errors["services.stripe.secret"] ? unref(form).errors["services.stripe.secret"].replace("services.", "").replaceAll(".", " ") : null
							}, null, _parent, _scopeId));
							_push(`</div><!--]-->`);
						} else _push(`<!---->`);
						_push(`<div class="col-span-full"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$7), {
							rows: "3",
							modelValue: staticMethodsText.value,
							"onUpdate:modelValue": ($event) => staticMethodsText.value = $event,
							label: _ctx.$t("Payment Methods"),
							error: unref(form).errors.static_payment_methods,
							placeholder: _ctx.$t("Enter payment methods, one per line")
						}, null, _parent, _scopeId));
						_push(`<p class="text-mute mt-1 text-xs"${_scopeId}>${ssrInterpolate(_ctx.$t("Enter one method per line. These will appear in the payment method dropdown."))}</p></div>`);
					} else return [
						createVNode("div", { class: "col-span-full flex gap-x-8 gap-y-4" }, [createVNode(unref(_sfc_main$4), {
							id: "paypal-enabled",
							label: _ctx.$t("Enable PayPal Payments"),
							checked: unref(form).services.paypal.enabled,
							"onUpdate:checked": ($event) => unref(form).services.paypal.enabled = $event,
							error: unref(form).errors.services?.paypal?.enabled
						}, null, 8, [
							"label",
							"checked",
							"onUpdate:checked",
							"error"
						]), createVNode(unref(_sfc_main$4), {
							id: "stripe-terminal",
							label: _ctx.$t("Enable Stripe Terminal"),
							checked: unref(form).stripe_terminal,
							"onUpdate:checked": ($event) => unref(form).stripe_terminal = $event,
							error: unref(form).errors.stripe_terminal
						}, null, 8, [
							"label",
							"checked",
							"onUpdate:checked",
							"error"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$5), {
							modelValue: unref(form).default_currency,
							"onUpdate:modelValue": ($event) => unref(form).default_currency = $event,
							error: unref(form).errors.default_currency,
							label: _ctx.$t("Default Currency")
						}, null, 8, [
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"label"
						])]),
						createVNode("div", { class: "col-span-6 sm:col-span-3" }, [createVNode(unref(_sfc_main$6), {
							json: true,
							id: "gateway",
							searchable: false,
							label: _ctx.$t("Credit Card Gateway"),
							modelValue: unref(form).gateway,
							"onUpdate:modelValue": ($event) => unref(form).gateway = $event,
							error: unref(form).errors.gateway,
							suggestions: [
								{
									value: null,
									label: _ctx.$t("Disabled")
								},
								{
									value: "PayPal Rest",
									label: "PayPal Rest"
								},
								{
									value: "Stripe",
									label: "Stripe"
								},
								...Object.keys(__props.payment_methods)?.map((key) => {
									return {
										value: key,
										label: __props.payment_methods[key].name
									};
								})
							]
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error",
							"suggestions"
						])]),
						__props.payment_methods[unref(form).gateway] ? (openBlock(), createBlock("div", {
							key: 0,
							class: "col-span-full flex flex-col gap-4 rounded-md bg-gray-100 p-4 dark:bg-gray-800"
						}, [(openBlock(true), createBlock(Fragment, null, renderList(__props.payment_methods[unref(form).gateway].fields, (field, key) => {
							return openBlock(), createBlock("div", { key }, [field.type == "checkbox" ? (openBlock(), createBlock(unref(_sfc_main$4), {
								key: 0,
								id: field.config,
								checked: unref(form)[field.config] == 1,
								"onUpdate:checked": (e) => setDeepValue(unref(form), field.config, e ? 1 : 0),
								label: field.label || key.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
								error: unref(form).errors[field.config] ? unref(form).errors[field.config].replace("services.", "").replaceAll(".", " ") : null
							}, null, 8, [
								"id",
								"checked",
								"onUpdate:checked",
								"label",
								"error"
							])) : (openBlock(), createBlock(unref(_sfc_main$5), {
								key: 1,
								modelValue: unref(form)[field.config],
								"onUpdate:modelValue": ($event) => unref(form)[field.config] = $event,
								onChange: (e) => setDeepValue(unref(form), field.config, e.target.value),
								label: field.label || key.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
								error: unref(form).errors[field.config] ? unref(form).errors[field.config].replace("services.", "").replaceAll(".", " ") : null
							}, null, 8, [
								"modelValue",
								"onUpdate:modelValue",
								"onChange",
								"label",
								"error"
							]))]);
						}), 128))])) : createCommentVNode("", true),
						unref(form).services.paypal.enabled || unref(form).gateway == "PayPal Rest" ? (openBlock(), createBlock(Fragment, { key: 1 }, [createVNode("div", { class: "col-span-full" }, [createVNode(unref(_sfc_main$5), {
							label: _ctx.$t("PayPal Client Id"),
							modelValue: unref(form).services.paypal.client_id,
							"onUpdate:modelValue": ($event) => unref(form).services.paypal.client_id = $event,
							error: unref(form).errors["services.paypal.client_id"] ? unref(form).errors["services.paypal.client_id"].replace("services.", "").replaceAll(".", " ") : null
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])]), createVNode("div", { class: "col-span-full" }, [createVNode(unref(_sfc_main$5), {
							label: _ctx.$t("PayPal Secret"),
							modelValue: unref(form).services.paypal.secret,
							"onUpdate:modelValue": ($event) => unref(form).services.paypal.secret = $event,
							error: unref(form).errors["services.paypal.secret"] ? unref(form).errors["services.paypal.secret"].replace("services.", "").replaceAll(".", " ") : null
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])])], 64)) : createCommentVNode("", true),
						unref(form).stripe_terminal || unref(form).gateway == "Stripe" ? (openBlock(), createBlock(Fragment, { key: 2 }, [createVNode("div", { class: "col-span-full" }, [createVNode(unref(_sfc_main$5), {
							label: _ctx.$t("Stripe Publishable Key"),
							modelValue: unref(form).services.stripe.key,
							"onUpdate:modelValue": ($event) => unref(form).services.stripe.key = $event,
							error: unref(form).errors["services.stripe.key"] ? unref(form).errors["services.stripe.key"].replace("services.", "").replaceAll(".", " ") : null
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])]), createVNode("div", { class: "col-span-full" }, [createVNode(unref(_sfc_main$5), {
							label: _ctx.$t("Stripe Secret Key"),
							modelValue: unref(form).services.stripe.secret,
							"onUpdate:modelValue": ($event) => unref(form).services.stripe.secret = $event,
							error: unref(form).errors["services.stripe.secret"] ? unref(form).errors["services.stripe.secret"].replace("services.", "").replaceAll(".", " ") : null
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"error"
						])])], 64)) : createCommentVNode("", true),
						createVNode("div", { class: "col-span-full" }, [createVNode(unref(_sfc_main$7), {
							rows: "3",
							modelValue: staticMethodsText.value,
							"onUpdate:modelValue": ($event) => staticMethodsText.value = $event,
							label: _ctx.$t("Payment Methods"),
							error: unref(form).errors.static_payment_methods,
							placeholder: _ctx.$t("Enter payment methods, one per line")
						}, null, 8, [
							"modelValue",
							"onUpdate:modelValue",
							"label",
							"error",
							"placeholder"
						]), createVNode("p", { class: "text-mute mt-1 text-xs" }, toDisplayString(_ctx.$t("Enter one method per line. These will appear in the payment method dropdown.")), 1)])
					];
				}),
				actions: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(ssrRenderComponent(unref(_sfc_main$1), {
							on: unref(form).recentlySuccessful,
							class: "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$8), {
							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));
					} else return [createVNode(unref(_sfc_main$1), {
						on: unref(form).recentlySuccessful,
						class: "me-3"
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Saved.")), 1)]),
						_: 1
					}, 8, ["on"]), createVNode(unref(_sfc_main$8), {
						class: { "opacity-25": unref(form).processing },
						loading: unref(form).processing
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Save")), 1)]),
						_: 1
					}, 8, ["class", "loading"])];
				}),
				_: 1
			}, _parent));
			_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/Setting/Payment.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
