import { A as _sfc_main$9, H as PageSearch, M as _sfc_main$3, f as _sfc_main$8, 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$10 } from "./AdminLayout-eZgRfDMK.js";
import _sfc_main$11 from "./Form-C3nt3R3Z.js";
import { router, useForm } from "@inertiajs/vue3";
import { createBlock, createCommentVNode, createTextVNode, createVNode, openBlock, ref, resolveComponent, toDisplayString, unref, useSSRContext, withCtx } from "vue";
import { ssrInterpolate, ssrRenderClass, ssrRenderComponent, ssrRenderList } from "vue/server-renderer";
//#region resources/js/Pages/Sma/Hr/Leave/Index.vue
var _sfc_main = /* @__PURE__ */ Object.assign({ layout: _sfc_main$10 }, {
	__name: "Index",
	__ssrInlineRender: true,
	props: [
		"pagination",
		"employees",
		"leave_types"
	],
	setup(__props) {
		const add = ref(false);
		const current = ref(null);
		const deleting = ref(false);
		const deleted = ref(false);
		const approving = ref(null);
		const { filters, searching, searchNow, sortBy } = PageSearch();
		const statusClasses = {
			pending: "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300",
			approved: "bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300",
			rejected: "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300"
		};
		const approveForm = useForm({
			status: "",
			notes: ""
		});
		const editRow = (row) => {
			current.value = row;
			add.value = true;
		};
		const hideForm = () => {
			current.value = null;
			add.value = false;
		};
		const deleteRow = (row) => {
			deleting.value = true;
			router.delete(route("leaves.destroy", row.id), {
				preserveScroll: true,
				onSuccess: () => deleted.value = row.id,
				onFinish: () => deleting.value = false
			});
		};
		const handleApprove = (status) => {
			approveForm.status = status;
			approveForm.post(route("leaves.approve", approving.value.id), {
				preserveScroll: true,
				onSuccess: () => approving.value = null
			});
		};
		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("Leaves"))}</title>`);
					else return [createVNode("title", null, toDisplayString(_ctx.$t("Leaves")), 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-leaves")) _push(ssrRenderComponent(unref(_sfc_main$1), { onClick: ($event) => add.value = true }, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Add {x}", { x: _ctx.$t("Leave") }))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Add {x}", { x: _ctx.$t("Leave") })), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						else _push(`<!---->`);
						_push(ssrRenderComponent(unref(_sfc_main$2), {
							align: "right",
							width: "64",
							"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="space-y-3 px-4 py-2"${_scopeId}><div${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Status"),
										modelValue: unref(filters).status,
										"onUpdate:modelValue": ($event) => unref(filters).status = $event,
										placeholder: _ctx.$t("All Statuses"),
										suggestions: [
											{
												value: "pending",
												label: _ctx.$t("Pending")
											},
											{
												value: "approved",
												label: _ctx.$t("Approved")
											},
											{
												value: "rejected",
												label: _ctx.$t("Rejected")
											}
										]
									}, null, _parent, _scopeId));
									_push(`</div><div${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Employee"),
										modelValue: unref(filters).employee_id,
										"onUpdate:modelValue": ($event) => unref(filters).employee_id = $event,
										placeholder: _ctx.$t("All Employees"),
										suggestions: __props.employees.map((e) => ({
											value: e.id,
											label: e.user?.name
										}))
									}, null, _parent, _scopeId));
									_push(`</div><div${_scopeId}>`);
									_push(ssrRenderComponent(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Leave Type"),
										modelValue: unref(filters).leave_type_id,
										"onUpdate:modelValue": ($event) => unref(filters).leave_type_id = $event,
										placeholder: _ctx.$t("All Types"),
										suggestions: __props.leave_types.map((t) => ({
											value: t.id,
											label: t.name
										}))
									}, null, _parent, _scopeId));
									_push(`</div></div>`);
								} else return [createVNode("div", { class: "space-y-3 px-4 py-2" }, [
									createVNode("div", null, [createVNode(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Status"),
										modelValue: unref(filters).status,
										"onUpdate:modelValue": ($event) => unref(filters).status = $event,
										placeholder: _ctx.$t("All Statuses"),
										suggestions: [
											{
												value: "pending",
												label: _ctx.$t("Pending")
											},
											{
												value: "approved",
												label: _ctx.$t("Approved")
											},
											{
												value: "rejected",
												label: _ctx.$t("Rejected")
											}
										]
									}, null, 8, [
										"onChange",
										"label",
										"modelValue",
										"onUpdate:modelValue",
										"placeholder",
										"suggestions"
									])]),
									createVNode("div", null, [createVNode(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Employee"),
										modelValue: unref(filters).employee_id,
										"onUpdate:modelValue": ($event) => unref(filters).employee_id = $event,
										placeholder: _ctx.$t("All Employees"),
										suggestions: __props.employees.map((e) => ({
											value: e.id,
											label: e.user?.name
										}))
									}, null, 8, [
										"onChange",
										"label",
										"modelValue",
										"onUpdate:modelValue",
										"placeholder",
										"suggestions"
									])]),
									createVNode("div", null, [createVNode(unref(_sfc_main$3), {
										json: true,
										onChange: unref(searchNow),
										label: _ctx.$t("Leave Type"),
										modelValue: unref(filters).leave_type_id,
										"onUpdate:modelValue": ($event) => unref(filters).leave_type_id = $event,
										placeholder: _ctx.$t("All Types"),
										suggestions: __props.leave_types.map((t) => ({
											value: t.id,
											label: t.name
										}))
									}, 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-leaves") ? (openBlock(), createBlock(unref(_sfc_main$1), {
						key: 0,
						onClick: ($event) => add.value = true
					}, {
						default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Add {x}", { x: _ctx.$t("Leave") })), 1)]),
						_: 1
					}, 8, ["onClick"])) : createCommentVNode("", true), createVNode(unref(_sfc_main$2), {
						align: "right",
						width: "64",
						"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: "space-y-3 px-4 py-2" }, [
							createVNode("div", null, [createVNode(unref(_sfc_main$3), {
								json: true,
								onChange: unref(searchNow),
								label: _ctx.$t("Status"),
								modelValue: unref(filters).status,
								"onUpdate:modelValue": ($event) => unref(filters).status = $event,
								placeholder: _ctx.$t("All Statuses"),
								suggestions: [
									{
										value: "pending",
										label: _ctx.$t("Pending")
									},
									{
										value: "approved",
										label: _ctx.$t("Approved")
									},
									{
										value: "rejected",
										label: _ctx.$t("Rejected")
									}
								]
							}, null, 8, [
								"onChange",
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"placeholder",
								"suggestions"
							])]),
							createVNode("div", null, [createVNode(unref(_sfc_main$3), {
								json: true,
								onChange: unref(searchNow),
								label: _ctx.$t("Employee"),
								modelValue: unref(filters).employee_id,
								"onUpdate:modelValue": ($event) => unref(filters).employee_id = $event,
								placeholder: _ctx.$t("All Employees"),
								suggestions: __props.employees.map((e) => ({
									value: e.id,
									label: e.user?.name
								}))
							}, null, 8, [
								"onChange",
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"placeholder",
								"suggestions"
							])]),
							createVNode("div", null, [createVNode(unref(_sfc_main$3), {
								json: true,
								onChange: unref(searchNow),
								label: _ctx.$t("Leave Type"),
								modelValue: unref(filters).leave_type_id,
								"onUpdate:modelValue": ($event) => unref(filters).leave_type_id = $event,
								placeholder: _ctx.$t("All Types"),
								suggestions: __props.leave_types.map((t) => ({
									value: t.id,
									label: t.name
								}))
							}, null, 8, [
								"onChange",
								"label",
								"modelValue",
								"onUpdate:modelValue",
								"placeholder",
								"suggestions"
							])])
						])]),
						_: 1
					})])];
				}),
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(`${ssrInterpolate(_ctx.$t("Leaves"))} `);
					else return [createTextVNode(toDisplayString(_ctx.$t("Leaves")) + " ", 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 py-3.5 ps-4 pe-3 text-start text-sm font-semibold sm:ps-6 lg:ps-8">${ssrInterpolate(_ctx.$t("Employee"))}</th><th scope="col" class="text-focus px-3 py-3.5 text-start text-sm font-semibold">${ssrInterpolate(_ctx.$t("Leave Type"))}</th><th scope="col" class="text-focus px-3 py-3.5 text-start text-sm font-semibold">${ssrInterpolate(_ctx.$t("Period"))}</th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold">${ssrInterpolate(_ctx.$t("Days"))}</th><th scope="col" class="text-focus px-3 py-3.5 text-center text-sm font-semibold">${ssrInterpolate(_ctx.$t("Status"))}</th><th scope="col" class="relative w-32 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?.data?.length) {
				_push(`<!--[-->`);
				ssrRenderList(__props.pagination.data, (row) => {
					_push(`<tr><td class="text-focus py-4 ps-4 pe-3 text-sm font-medium whitespace-nowrap sm:ps-6 lg:ps-8">${ssrInterpolate(row.employee?.user?.name)}</td><td class="px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(row.leave_type?.name)} `);
					if (row.leave_type && !row.leave_type.is_paid) _push(`<span class="ms-1 text-xs text-red-500">(${ssrInterpolate(_ctx.$t("Unpaid"))})</span>`);
					else _push(`<!---->`);
					_push(`</td><td class="px-3 py-4 text-sm whitespace-nowrap">${ssrInterpolate(_ctx.$date(row.start_date))} → ${ssrInterpolate(_ctx.$date(row.end_date))}</td><td class="px-3 py-4 text-center text-sm whitespace-nowrap">${ssrInterpolate(row.days)}</td><td class="px-3 py-4 text-center text-sm whitespace-nowrap"><span class="${ssrRenderClass([statusClasses[row.status], "rounded-full px-2.5 py-0.5 text-xs font-medium"])}">${ssrInterpolate(_ctx.$t(row.status.charAt(0).toUpperCase() + row.status.slice(1)))}</span></td><td class="${ssrRenderClass([row.deleted_at ? "deleted" : "", "relative w-32 py-4 ps-3 pe-4 text-end text-sm font-medium whitespace-nowrap sm:pe-6 lg:pe-8"])}"><div class="flex items-center justify-end gap-3">`);
					if (row.status === "pending" && _ctx.$can("update-leaves")) _push(`<button type="button" class="link text-xs"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="size-5"><path d="M8 21s-4-3-4-9 4-9 4-9"></path><path d="M16 3s4 3 4 9-4 9-4 9"></path><line x1="15" x2="9" y1="9" y2="15"></line><line x1="9" x2="15" y1="9" y2="15"></line></svg></button>`);
					else _push(`<!---->`);
					_push(ssrRenderComponent(unref(_sfc_main$5), {
						row,
						editRow,
						deleted: deleted.value,
						deleting: deleting.value,
						deleteRow,
						permission: "leaves",
						record: _ctx.$t("Leave")
					}, null, _parent));
					_push(`</div></td></tr>`);
				});
				_push(`<!--]-->`);
			} else _push(`<tr><td colspan="100%"><div class="text-mute py-3.5 ps-4 text-sm font-light">${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: add.value,
				"max-width": "2xl",
				onClose: hideForm
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) _push(ssrRenderComponent(_sfc_main$11, {
						current: current.value,
						employees: __props.employees,
						leave_types: __props.leave_types,
						onClose: hideForm
					}, null, _parent, _scopeId));
					else return [createVNode(_sfc_main$11, {
						current: current.value,
						employees: __props.employees,
						leave_types: __props.leave_types,
						onClose: hideForm
					}, null, 8, [
						"current",
						"employees",
						"leave_types"
					])];
				}),
				_: 1
			}, _parent));
			_push(ssrRenderComponent(unref(_sfc_main$7), {
				show: !!approving.value,
				"max-width": "md",
				onClose: ($event) => approving.value = null
			}, {
				default: withCtx((_, _push, _parent, _scopeId) => {
					if (_push) if (approving.value) {
						_push(`<div class="p-6"${_scopeId}><h2 class="text-focus text-base font-semibold"${_scopeId}>${ssrInterpolate(_ctx.$t("Review Leave Request"))}</h2><p class="text-mute mt-1 text-sm"${_scopeId}>${ssrInterpolate(approving.value.employee?.user?.name)} — ${ssrInterpolate(approving.value.leave_type?.name)} (${ssrInterpolate(approving.value.days)} ${ssrInterpolate(_ctx.$t("days"))}) </p><div class="mt-4"${_scopeId}>`);
						_push(ssrRenderComponent(unref(_sfc_main$8), {
							rows: "2",
							label: _ctx.$t("Notes (optional)"),
							modelValue: unref(approveForm).notes,
							"onUpdate:modelValue": ($event) => unref(approveForm).notes = $event
						}, null, _parent, _scopeId));
						_push(`</div><div class="mt-4 flex justify-end gap-3"${_scopeId}><button type="button" class="btn-secondary"${_scopeId}>${ssrInterpolate(_ctx.$t("Cancel"))}</button>`);
						_push(ssrRenderComponent(unref(_sfc_main$9), {
							type: "button",
							variant: "danger",
							loading: unref(approveForm).processing,
							onClick: ($event) => handleApprove("rejected")
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Reject"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Reject")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(ssrRenderComponent(unref(_sfc_main$9), {
							type: "button",
							loading: unref(approveForm).processing,
							onClick: ($event) => handleApprove("approved")
						}, {
							default: withCtx((_, _push, _parent, _scopeId) => {
								if (_push) _push(`${ssrInterpolate(_ctx.$t("Approve"))}`);
								else return [createTextVNode(toDisplayString(_ctx.$t("Approve")), 1)];
							}),
							_: 1
						}, _parent, _scopeId));
						_push(`</div></div>`);
					} else _push(`<!---->`);
					else return [approving.value ? (openBlock(), createBlock("div", {
						key: 0,
						class: "p-6"
					}, [
						createVNode("h2", { class: "text-focus text-base font-semibold" }, toDisplayString(_ctx.$t("Review Leave Request")), 1),
						createVNode("p", { class: "text-mute mt-1 text-sm" }, toDisplayString(approving.value.employee?.user?.name) + " — " + toDisplayString(approving.value.leave_type?.name) + " (" + toDisplayString(approving.value.days) + " " + toDisplayString(_ctx.$t("days")) + ") ", 1),
						createVNode("div", { class: "mt-4" }, [createVNode(unref(_sfc_main$8), {
							rows: "2",
							label: _ctx.$t("Notes (optional)"),
							modelValue: unref(approveForm).notes,
							"onUpdate:modelValue": ($event) => unref(approveForm).notes = $event
						}, null, 8, [
							"label",
							"modelValue",
							"onUpdate:modelValue"
						])]),
						createVNode("div", { class: "mt-4 flex justify-end gap-3" }, [
							createVNode("button", {
								type: "button",
								class: "btn-secondary",
								onClick: ($event) => approving.value = null
							}, toDisplayString(_ctx.$t("Cancel")), 9, ["onClick"]),
							createVNode(unref(_sfc_main$9), {
								type: "button",
								variant: "danger",
								loading: unref(approveForm).processing,
								onClick: ($event) => handleApprove("rejected")
							}, {
								default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Reject")), 1)]),
								_: 1
							}, 8, ["loading", "onClick"]),
							createVNode(unref(_sfc_main$9), {
								type: "button",
								loading: unref(approveForm).processing,
								onClick: ($event) => handleApprove("approved")
							}, {
								default: withCtx(() => [createTextVNode(toDisplayString(_ctx.$t("Approve")), 1)]),
								_: 1
							}, 8, ["loading", "onClick"])
						])
					])) : createCommentVNode("", true)];
				}),
				_: 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/Hr/Leave/Index.vue");
	return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
//#endregion
export { _sfc_main as default };
