import { H as PageSearch, M as _sfc_main$3, k as _sfc_main$1, pt as _sfc_main$2, st as _sfc_main$5, v as _sfc_main$6, vt as _sfc_main$7, x as _sfc_main$4 } from "../ssr.js";
import { t as _sfc_main$8 } from "./AdminLayout-eZgRfDMK.js";
import _sfc_main$9 from "./Form-3dyZUi_r.js";
import _sfc_main$10 from "./QuickView-DkbILDu8.js";
import { router } from "@inertiajs/vue3";
import { createBlock, createCommentVNode, createTextVNode, createVNode, onMounted, openBlock, ref, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderAttr, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/Sma/Order/Purchase/Index.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$8 }, {
	__name: "Index",
	__ssrInlineRender: true,
	props: [
		"pagination",
		"custom_fields",
		"payment_fields"
	],
	setup(__props) {
		const view = ref(false);
		const current = ref(null);
		const payment = ref(false);
		const deleted = ref(false);
		const deleting = ref(false);
		const { filters, searching, searchNow, sortBy } = PageSearch();
		onMounted(() => {
			if (route().params?.id) viewRow({ id: route().params.id });
		});
		function viewRow(row) {
			current.value = row;
			view.value = true;
		}
		function editRow(row) {
			router.visit(route("purchases.edit", { purchase: row.id }));
		}
		function deleteRow(row) {
			deleting.value = true;
			router.delete(route("purchases.destroy", row.id), {
				preserveScroll: true,
				onSuccess: () => deleted.value = row.id,
				onFinish: () => deleting.value = false
			});
		}
		return (_ctx, _push, _parent, _attrs) => {
			const _component_Head = resolveComponent("Head");
			const _component_Header = resolveComponent("Header");
			const _component_Icon = resolveComponent("Icon");
			_push(`<!--[-->`);
			_push(ssrRenderComponent(_component_Head, null, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`<title${_scopeId}>${ssrInterpolate(_ctx.$t("Purchases"))}</title>`);
					else return [createVNode("title", null, toDisplayString(_ctx.$t("Purchases")), 1)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(_component_Header, null, {
				subheading: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Please review the data below"))}`);
					else return [createTextVNode(toDisplayString(_ctx.$t("Please review the data below")), 1)];
				}),
				menu: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="flex items-center justify-center gap-4"${_scopeId}>`);
						if (_ctx.$can("create-purchases")) _push(ssrRenderComponent(unref(_sfc_main$1), { href: _ctx.route("purchases.create") }, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Add {x}", { x: _ctx.$t("Purchase") }))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Add {x}", { x: _ctx.$t("Purchase") })), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						else _push(`<!---->`);
						_push(ssrRenderComponent(unref(_sfc_main$2), {
							align: "right",
							width: "56",
							"auto-close": false
						}, {
							trigger: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) {
									_push(`<button class="-m-2 flex items-center rounded-md p-2.5 transition duration-150 ease-in-out"${_scopeId}>`);
									_push(ssrRenderComponent(_component_Icon, {
										name: "funnel-o",
										size: "size-5"
									}, null, _parent, _scopeId));
									_push(`<span class="sr-only"${_scopeId}>${ssrInterpolate(_ctx.$t("Show Filters"))}</span></button>`);
								} else return [createVNode("button", { class: "-m-2 flex items-center rounded-md p-2.5 transition duration-150 ease-in-out" }, [createVNode(_component_Icon, {
									name: "funnel-o",
									size: "size-5"
								}), createVNode("span", { class: "sr-only" }, toDisplayString(_ctx.$t("Show Filters")), 1)])];
							}),
							content: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) {
									_push(`<div class="px-4 py-2"${_scopeId}><div${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Trashed"),
										modelValue: unref(filters).trashed,
										"onUpdate:modelValue": ($event) => unref(filters).trashed = $event,
										placeholder: _ctx.$t("With Trashed"),
										suggestions: [
											{
												value: "not",
												label: _ctx.$t("Not Trashed")
											},
											{
												value: "with",
												label: _ctx.$t("With Trashed")
											},
											{
												value: "only",
												label: _ctx.$t("Only Trashed")
											}
										]
									}, null, _parent, _scopeId));
									_push(`</div></div>`);
								} else return [createVNode("div", { class: "px-4 py-2" }, [createVNode("div", null, [createVNode(unref(_sfc_main$3), {
									json: true,
									onChange: unref(searchNow),
									label: _ctx.$t("Trashed"),
									modelValue: unref(filters).trashed,
									"onUpdate:modelValue": ($event) => unref(filters).trashed = $event,
									placeholder: _ctx.$t("With Trashed"),
									suggestions: [
										{
											value: "not",
											label: _ctx.$t("Not Trashed")
										},
										{
											value: "with",
											label: _ctx.$t("With Trashed")
										},
										{
											value: "only",
											label: _ctx.$t("Only Trashed")
										}
									]
								}, null, 8, [
									"onChange",
									"label",
									"modelValue",
									"onUpdate:modelValue",
									"placeholder",
									"suggestions"
								])])])];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`</div>`);
					} else return [createVNode("div", { class: "flex items-center justify-center gap-4" }, [_ctx.$can("create-purchases") ? (openBlock(), createBlock(unref(_sfc_main$1), {
						key: 0,
						href: _ctx.route("purchases.create")
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Add {x}", { x: _ctx.$t("Purchase") })), 1)]),
						_: 1
					}, 8, ["href"])) : createCommentVNode("", true), createVNode(unref(_sfc_main$2), {
						align: "right",
						width: "56",
						"auto-close": false
					}, {
						trigger: withCtx(() => [createVNode("button", { class: "-m-2 flex items-center rounded-md p-2.5 transition duration-150 ease-in-out" }, [createVNode(_component_Icon, {
							name: "funnel-o",
							size: "size-5"
						}), createVNode("span", { class: "sr-only" }, toDisplayString(_ctx.$t("Show Filters")), 1)])]),
						content: withCtx(() => [createVNode("div", { class: "px-4 py-2" }, [createVNode("div", null, [createVNode(unref(_sfc_main$3), {
							json: true,
							onChange: unref(searchNow),
							label: _ctx.$t("Trashed"),
							modelValue: unref(filters).trashed,
							"onUpdate:modelValue": ($event) => unref(filters).trashed = $event,
							placeholder: _ctx.$t("With Trashed"),
							suggestions: [
								{
									value: "not",
									label: _ctx.$t("Not Trashed")
								},
								{
									value: "with",
									label: _ctx.$t("With Trashed")
								},
								{
									value: "only",
									label: _ctx.$t("Only Trashed")
								}
							]
						}, null, 8, [
							"onChange",
							"label",
							"modelValue",
							"onUpdate:modelValue",
							"placeholder",
							"suggestions"
						])])])]),
						_: 1
					})])];
				}),
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Purchases"))} `);
					else return [createTextVNode(toDisplayString(_ctx.$t("Purchases")) + " ", 1)];
				}),
				_: 1
			}, _parent));
			_push(`<div class="relative flex grow flex-col items-stretch justify-stretch self-stretch bg-white px-4 sm:px-6 lg:px-8 dark:bg-gray-800">`);
			if (unref(searching)) _push(ssrRenderComponent(unref(_sfc_main$4), { "circle-size": "w-10 h-10" }, null, _parent));
			else _push(`<!---->`);
			_push(`<div class="flow-root grow"><div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"><div class="my-2 inline-block min-w-full border-b border-gray-200 align-middle dark:border-gray-700"><table class="fixed-actions min-w-full divide-y divide-gray-200 dark:divide-gray-700"><thead><tr><th scope="col" class="text-focus w-16 py-3.5 ps-4 pe-3 text-center text-sm font-semibold sm:ps-6 lg:ps-8"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Date"))} `);
			if (unref(filters)?.sort?.startsWith("date:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "date:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-start text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Reference"))} `);
			if (unref(filters)?.sort?.startsWith("reference:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "reference:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-start text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Supplier"))} `);
			if (unref(filters)?.sort?.startsWith("supplier.company:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "supplier.company:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold">${ssrInterpolate(_ctx.$t("Items"))}</th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Tax"))} `);
			if (unref(filters)?.sort?.startsWith("total_tax_amount:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "total_tax_amount:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Total"))} `);
			if (unref(filters)?.sort?.startsWith("grand_total:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "grand_total:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Paid"))} `);
			if (unref(filters)?.sort?.startsWith("paid:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "paid:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold"><span class="whitespace-nowrap">${ssrInterpolate(_ctx.$t("Due Amount"))}</span></th><th scope="col" class="text-focus px-3 py-3.5 text-start text-sm font-semibold"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Created by"))} `);
			if (unref(filters)?.sort?.startsWith("user.name:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "user.name:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="text-focus w-16 py-3.5 ps-4 pe-3 text-center text-sm font-semibold sm:ps-6 lg:ps-8"><button type="button" class="flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Created at"))} `);
			if (unref(filters)?.sort?.startsWith("created_at:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "created_at:desc" ? "c-up" : "c-down"
			}, null, _parent));
			else _push(`<!---->`);
			_push(`</button></th><th scope="col" class="relative w-16 py-3.5 ps-3 pe-4 sm:pe-6 lg:pe-8"><span class="sr-only">${ssrInterpolate(_ctx.$t("Actions"))}</span></th></tr></thead><tbody class="divide-y divide-gray-200 bg-white dark:divide-gray-700 dark:bg-gray-900">`);
			if (__props.pagination && __props.pagination.data && __props.pagination.data.length) {
				_push(`<!--[-->`);
				ssrRenderList(__props.pagination.data, (row) => {
					_push(`<tr class="${ssrRenderClass({
						"bg-red-50 dark:bg-red-800/40": row.deleted_at || row.return_orders_count > 0,
						"bg-green-50 dark:bg-green-800/40": !row.return_orders_count && row.paid >= row.grand_total,
						"bg-yellow-50 dark:bg-yellow-800/40": !row.return_orders_count && row.paid < row.grand_total
					})}"><td class="text-focus w-14 cursor-pointer py-4 ps-4 pe-3 text-sm font-medium whitespace-nowrap sm:ps-6 lg:ps-8">${ssrInterpolate(_ctx.$date(row.date))}</td><td class="cursor-pointer px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(row.reference)}</td><td class="cursor-pointer px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(row.supplier.company || row.supplier.name)}</td><td class="cursor-pointer px-3 py-4 text-center text-sm whitespace-nowrap">${ssrInterpolate(row.total_items)} (${ssrInterpolate(_ctx.$number_qty(row.total_quantity))}) </td><td class="cursor-pointer px-3 py-4 text-end text-sm whitespace-nowrap">${ssrInterpolate(_ctx.$currency(row.total_tax_amount))}</td><td class="cursor-pointer px-3 py-4 text-end text-sm whitespace-nowrap">${ssrInterpolate(_ctx.$currency(row.grand_total))}</td><td class="cursor-pointer px-3 py-4 text-end text-sm whitespace-nowrap">${ssrInterpolate(_ctx.$currency(row.paid))}</td><td class="text-focus cursor-pointer py-1 text-end text-sm font-medium whitespace-nowrap">`);
					if (Number(row.paid) < Number(row.grand_total) && _ctx.$can("create-payments")) {
						_push(`<button type="button" class="group relative rounded px-3 py-3 hover:bg-gray-100 dark:hover:bg-gray-700/50">${ssrInterpolate(_ctx.$currency(Number(row.grand_total) - Number(row.paid)))} `);
						_push(ssrRenderComponent(_component_Icon, {
							name: "plus",
							size: "size-5",
							class: "absolute top-0 -left-4 my-3 text-green-500 opacity-0 transition group-hover:opacity-100"
						}, null, _parent));
						_push(`</button>`);
					} else _push(`<button type="button" class="px-3 py-4">${ssrInterpolate(_ctx.$currency(Number(row.grand_total) - Number(row.paid)))}</button>`);
					_push(`</td><td class="cursor-pointer px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(row.user?.name || "")}</td><td class="text-focus w-14 cursor-pointer py-4 ps-4 pe-3 text-sm font-medium whitespace-nowrap sm:ps-6 lg:ps-8">${ssrInterpolate(_ctx.$datetime(row.created_at))}</td><td class="${ssrRenderClass([{
						"bg-red-100! dark:bg-red-950!": row.deleted_at || row.return_orders_count > 0,
						"bg-green-100! dark:bg-green-950!": !row.return_orders_count && row.paid >= row.grand_total,
						"bg-yellow-100! dark:bg-yellow-950!": !row.return_orders_count && row.paid < row.grand_total
					}, "relative w-16 py-4 ps-3 pe-4 text-end text-sm font-medium whitespace-nowrap sm:pe-6 lg:pe-8"])}"><div class="text-mute flex items-center justify-end gap-4">`);
					if (_ctx.$can("email-purchases")) {
						_push(`<button type="button" class="link">`);
						_push(ssrRenderComponent(_component_Icon, {
							name: "envelope",
							size: "size-5"
						}, null, _parent));
						_push(`</button>`);
					} else _push(`<!---->`);
					if (_ctx.$can("create-return-orders")) {
						_push(`<button class="link" type="button"${ssrRenderAttr("title", _ctx.$t("Add Return"))}>`);
						_push(ssrRenderComponent(_component_Icon, {
							name: "return",
							size: "size-5"
						}, null, _parent));
						_push(`</button>`);
					} else _push(`<!---->`);
					_push(ssrRenderComponent(unref(_sfc_main$5), {
						row,
						editRow,
						deleted: deleted.value,
						deleting: deleting.value,
						deleteRow,
						permission: "purchases",
						record: _ctx.$t("Purchase")
					}, null, _parent));
					_push(`</div></td></tr>`);
				});
				_push(`<!--]-->`);
			} else _push(`<tr><td colspan="100%"><div class="text-mute py-3.5 ps-4 pe-3 text-sm font-light whitespace-nowrap sm:ps-2 lg:ps-4">${ssrInterpolate(_ctx.$t("There is no data to display!"))}</div></td></tr>`);
			_push(`</tbody></table></div></div></div><div class="-mx-4 sm:-mx-6 lg:-mx-8">`);
			_push(ssrRenderComponent(unref(_sfc_main$6), {
				class: "mx-4 mt-auto py-2 text-sm sm:mx-6",
				meta: __props.pagination.meta,
				links: __props.pagination.links
			}, null, _parent));
			_push(`</div>`);
			_push(ssrRenderComponent(unref(_sfc_main$7), {
				show: view.value,
				"max-width": "3xl",
				onClose: ($event) => view.value = false
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$10, {
						current: current.value,
						fields: __props.custom_fields,
						onClose: ($event) => view.value = false,
						editRow
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$10, {
						current: current.value,
						fields: __props.custom_fields,
						onClose: ($event) => view.value = false,
						editRow
					}, null, 8, [
						"current",
						"fields",
						"onClose"
					])];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$7), {
				show: payment.value,
				"max-width": "2xl",
				onClose: ($event) => payment.value = false
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$9, {
						purchase: current.value,
						customer: current.value?.supplier,
						custom_fields: __props.payment_fields,
						onClose: ($event) => payment.value = false
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$9, {
						purchase: current.value,
						customer: current.value?.supplier,
						custom_fields: __props.payment_fields,
						onClose: ($event) => payment.value = false
					}, null, 8, [
						"purchase",
						"customer",
						"custom_fields",
						"onClose"
					])];
				}),
				_: 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/Order/Purchase/Index.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
