import { H as PageSearch, k as _sfc_main$1, v as _sfc_main$3, vt as _sfc_main$4, x as _sfc_main$2 } from "../ssr.js";
import { t as _sfc_main$5 } from "./AdminLayout-eZgRfDMK.js";
import _sfc_main$6 from "./QuickView-DkbILDu8.js";
import _sfc_main$7 from "./Form-0tf-fvoj.js";
import { createBlock, createCommentVNode, createTextVNode, createVNode, openBlock, ref, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
import dayjs from "dayjs";
//#region resources/js/Pages/Sma/Report/Purchase.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$5 }, {
	__name: "Purchase",
	__ssrInlineRender: true,
	props: [
		"pagination",
		"totals",
		"stores",
		"users"
	],
	setup(__props) {
		const form = ref(false);
		const view = ref(false);
		const current = ref(null);
		const { filters, searching, sortBy } = PageSearch();
		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("{x} Report", { x: _ctx.$t("Purchases") }))}</title>`);
					else return [createVNode("title", null, toDisplayString(_ctx.$t("{x} Report", { x: _ctx.$t("Purchases") })), 1)];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(_component_Header, null, {
				subheading: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div${_scopeId}>${ssrInterpolate(_ctx.$t("Please review the data below"))}</div>`);
						if (unref(filters) && Object.keys(unref(filters)).filter((k) => unref(filters)[k] && k !== "sort").length > 0) {
							_push(`<div class="mt-1 flex flex-wrap items-center gap-x-6 gap-y-1 text-sm font-bold text-primary-700 dark:text-primary-400"${_scopeId}>${ssrInterpolate(_ctx.$t("Filters Applied"))}: `);
							if (unref(filters).start_date) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("From"))}: ${ssrInterpolate(_ctx.$date(unref(filters).start_date.toString(), null, null, true))}</span>`);
							else _push(`<!---->`);
							if (unref(filters).end_date) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("To"))}: ${ssrInterpolate(_ctx.$date(unref(filters).end_date.toString(), null, null, true))}</span>`);
							else _push(`<!---->`);
							if (unref(filters).supplier_id && __props.pagination.data[0]?.supplier) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("Supplier"))}: ${ssrInterpolate(__props.pagination.data[0]?.supplier?.company)}</span>`);
							else _push(`<!---->`);
							if (unref(filters).store_id && __props.pagination.data[0]?.store) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("Store"))}: ${ssrInterpolate(__props.pagination.data[0]?.store?.name)}</span>`);
							else _push(`<!---->`);
							if (unref(filters).user_id && __props.pagination.data[0]?.user) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("User"))}: ${ssrInterpolate(__props.pagination.data[0]?.user?.name)}</span>`);
							else _push(`<!---->`);
							if (unref(filters).products && unref(filters).products.length > 0) _push(`<span${_scopeId}>${ssrInterpolate(_ctx.$t("Products Count"))}: ${ssrInterpolate(unref(filters).products.length)}, ${ssrInterpolate(_ctx.$t("Products Ids"))}: ${ssrInterpolate(unref(filters).products.join(", "))}</span>`);
							else _push(`<!---->`);
							_push(`</div>`);
						} else _push(`<!---->`);
					} else return [createVNode("div", null, toDisplayString(_ctx.$t("Please review the data below")), 1), unref(filters) && Object.keys(unref(filters)).filter((k) => unref(filters)[k] && k !== "sort").length > 0 ? (openBlock(), createBlock("div", {
						key: 0,
						class: "mt-1 flex flex-wrap items-center gap-x-6 gap-y-1 text-sm font-bold text-primary-700 dark:text-primary-400"
					}, [
						createTextVNode(toDisplayString(_ctx.$t("Filters Applied")) + ": ", 1),
						unref(filters).start_date ? (openBlock(), createBlock("span", { key: 0 }, toDisplayString(_ctx.$t("From")) + ": " + toDisplayString(_ctx.$date(unref(filters).start_date.toString(), null, null, true)), 1)) : createCommentVNode("", true),
						unref(filters).end_date ? (openBlock(), createBlock("span", { key: 1 }, toDisplayString(_ctx.$t("To")) + ": " + toDisplayString(_ctx.$date(unref(filters).end_date.toString(), null, null, true)), 1)) : createCommentVNode("", true),
						unref(filters).supplier_id && __props.pagination.data[0]?.supplier ? (openBlock(), createBlock("span", { key: 2 }, toDisplayString(_ctx.$t("Supplier")) + ": " + toDisplayString(__props.pagination.data[0]?.supplier?.company), 1)) : createCommentVNode("", true),
						unref(filters).store_id && __props.pagination.data[0]?.store ? (openBlock(), createBlock("span", { key: 3 }, toDisplayString(_ctx.$t("Store")) + ": " + toDisplayString(__props.pagination.data[0]?.store?.name), 1)) : createCommentVNode("", true),
						unref(filters).user_id && __props.pagination.data[0]?.user ? (openBlock(), createBlock("span", { key: 4 }, toDisplayString(_ctx.$t("User")) + ": " + toDisplayString(__props.pagination.data[0]?.user?.name), 1)) : createCommentVNode("", true),
						unref(filters).products && unref(filters).products.length > 0 ? (openBlock(), createBlock("span", { key: 5 }, toDisplayString(_ctx.$t("Products Count")) + ": " + toDisplayString(unref(filters).products.length) + ", " + toDisplayString(_ctx.$t("Products Ids")) + ": " + toDisplayString(unref(filters).products.join(", ")), 1)) : createCommentVNode("", true)
					])) : createCommentVNode("", true)];
				}),
				menu: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) {
						_push(`<div class="flex items-center justify-center gap-4"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$1), {
							type: "button",
							onClick: ($event) => form.value = true
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Customize"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Customize")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`</div>`);
					} else return [createVNode("div", { class: "flex items-center justify-center gap-4" }, [createVNode(unref(_sfc_main$1), {
						type: "button",
						onClick: ($event) => form.value = true
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Customize")), 1)]),
						_: 1
					}, 8, ["onClick"])])];
				}),
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("{x} Report", { x: _ctx.$t("Purchases") }))} `);
					else return [createTextVNode(toDisplayString(_ctx.$t("{x} Report", { x: _ctx.$t("Purchases") })) + " ", 1)];
				}),
				_: 1
			}, _parent));
			if (__props.totals) _push(`<dl class="grid grid-cols-1 gap-px border-b border-gray-200 bg-gray-200 sm:grid-cols-2 lg:grid-cols-4 dark:border-gray-700 dark:bg-gray-700"><div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2 bg-white px-4 py-6 sm:px-6 xl:px-8 dark:bg-gray-900"><dt class="text-mute text-sm leading-6 font-medium">${ssrInterpolate(_ctx.$t("Purchases"))}</dt><dd class="text-focus w-full flex-none text-3xl leading-10 font-medium tracking-tight">${ssrInterpolate(_ctx.$number(__props.totals?.count || 0, null, { maximumFractionDigits: 0 }))}</dd></div><div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2 bg-white px-4 py-6 sm:px-6 xl:px-8 dark:bg-gray-900"><dt class="text-mute text-sm leading-6 font-medium">${ssrInterpolate(_ctx.$t("Amount"))}</dt><dd class="text-focus w-full flex-none text-3xl leading-10 font-medium tracking-tight">${ssrInterpolate(_ctx.$currency(__props.totals?.total || 0))}</dd></div><div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2 bg-white px-4 py-6 sm:px-6 xl:px-8 dark:bg-gray-900"><dt class="text-mute text-sm leading-6 font-medium">${ssrInterpolate(_ctx.$t("Amount Paid"))}</dt><dd class="text-focus w-full flex-none text-3xl leading-10 font-medium tracking-tight">${ssrInterpolate(_ctx.$currency(__props.totals?.paid || 0))}</dd></div><div class="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-2 bg-white px-4 py-6 sm:px-6 xl:px-8 dark:bg-gray-900"><dt class="text-mute text-sm leading-6 font-medium">${ssrInterpolate(_ctx.$t("Tax"))}</dt><dd class="text-focus w-full flex-none text-3xl leading-10 font-medium tracking-tight">${ssrInterpolate(_ctx.$currency(__props.totals?.tax || 0))}</dd></div></dl>`);
			else _push(`<!---->`);
			_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$2), { "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="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("toStore.name:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "toStore.name: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="mx-auto flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Items"))} `);
			if (unref(filters)?.sort?.startsWith("total_items:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "total_items: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="mx-auto flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Tax"))} `);
			if (unref(filters)?.sort?.startsWith("total_tax_amount_count:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "total_tax_amount_count: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="mx-auto flex items-center gap-2 whitespace-nowrap">${ssrInterpolate(_ctx.$t("Total"))} `);
			if (unref(filters)?.sort?.startsWith("grand_total_count:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "grand_total_count: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("Store"))} `);
			if (unref(filters)?.sort?.startsWith("store.name:")) _push(ssrRenderComponent(_component_Icon, {
				size: "size-3 text-mute",
				name: unref(filters).sort == "store.name: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("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></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-950": row.deleted_at || row.return_orders_count > 0,
						"bg-green-50 dark:bg-green-950": row.paid >= row.grand_total,
						"bg-yellow-50 dark:bg-yellow-950": (row.due_date && unref(dayjs)(row.due_date).isBefore(unref(dayjs)()) || !row.due_date) && 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 font-bold 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="cursor-pointer px-3 py-4 text-end text-sm whitespace-nowrap">${ssrInterpolate(_ctx.$currency(Number(row.grand_total) - Number(row.paid)))}</td><td class="cursor-pointer px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(row.store?.name || "")}</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></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$3), {
				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$4), {
				show: form.value,
				"max-width": "2xl",
				onClose: ($event) => form.value = false,
				overflow: true
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$7, {
						filters: unref(filters),
						stores: __props.stores,
						users: __props.users,
						onClose: ($event) => form.value = false,
						fields: [
							"products",
							"supplier",
							"store",
							"user"
						]
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$7, {
						filters: unref(filters),
						stores: __props.stores,
						users: __props.users,
						onClose: ($event) => form.value = false,
						fields: [
							"products",
							"supplier",
							"store",
							"user"
						]
					}, null, 8, [
						"filters",
						"stores",
						"users",
						"onClose"
					])];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$4), {
				show: view.value,
				"max-width": "3xl",
				onClose: ($event) => view.value = false
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$6, {
						force: true,
						current: current.value,
						fields: [],
						onClose: ($event) => view.value = false
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$6, {
						force: true,
						current: current.value,
						fields: [],
						onClose: ($event) => view.value = false
					}, null, 8, ["current", "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/Report/Purchase.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
