import { _ as __nuxt_component_0 } from './nuxt-link-Ci8vU-Yt.mjs'; import { defineComponent, computed, ref, watch, withCtx, createTextVNode, toDisplayString, useSSRContext } from 'vue'; import { ssrRenderAttrs, ssrInterpolate, ssrRenderAttr, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual, ssrRenderList, ssrRenderComponent, ssrRenderClass } from 'vue/server-renderer'; import { useRouter } from 'vue-router'; import { c as useAuthStore, d as useCookie } from './server.mjs'; import '../nitro/nitro.mjs'; import 'node:http'; import 'node:https'; import 'node:events'; import 'node:buffer'; import 'node:fs'; import 'node:path'; import 'node:crypto'; import 'node:url'; import 'pinia'; import '../routes/renderer.mjs'; import 'vue-bundle-renderer/runtime'; import 'unhead/server'; import 'devalue'; import 'unhead/utils'; import 'unhead/plugins'; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "index", __ssrInlineRender: true, setup(__props) { const router = useRouter(); const auth = useAuthStore(); const canViewPersons = computed(() => { var _a, _b; if (auth.isAdmin) return true; return !!((_b = (_a = auth.user) == null ? void 0 : _a.system_capabilities) == null ? void 0 : _b["persons:view"]); }); computed(() => { var _a, _b; if (auth.isAdmin) return true; return !!((_b = (_a = auth.user) == null ? void 0 : _a.system_capabilities) == null ? void 0 : _b["persons:edit"]); }); computed(() => { var _a, _b; if (auth.isAdmin) return true; return !!((_b = (_a = auth.user) == null ? void 0 : _a.system_capabilities) == null ? void 0 : _b["persons:merge"]); }); if (!canViewPersons.value && !auth.isAdmin) { router.push("/"); } const loading = ref(true); const error = ref(null); const persons = ref([]); const totalCount = ref(0); const skip = ref(0); const limit = ref(50); const searchQuery = ref(""); const ghostFilter = ref("all"); const activeFilter = ref("all"); const hasUserFilter = ref("all"); const mergedFilter = ref("all"); const notification = ref(null); const activeCount = computed(() => persons.value.filter((p) => p.is_active).length); const ghostCount = computed(() => persons.value.filter((p) => p.is_ghost).length); const mergedCount = computed(() => persons.value.filter((p) => p.merged_into_id).length); let searchDebounceTimer = null; function debouncedFetchPersons() { if (searchDebounceTimer) { clearTimeout(searchDebounceTimer); } searchDebounceTimer = setTimeout(() => { skip.value = 0; fetchPersons(); }, 400); } watch(searchQuery, () => { debouncedFetchPersons(); }); watch([ghostFilter, activeFilter, hasUserFilter, mergedFilter], () => { skip.value = 0; fetchPersons(); }); const isFilterActive = computed(() => { return searchQuery.value !== "" || ghostFilter.value !== "all" || activeFilter.value !== "all" || hasUserFilter.value !== "all" || mergedFilter.value !== "all"; }); function getAuthHeaders() { const tokenCookie = useCookie("access_token"); const token = tokenCookie.value; return token ? { Authorization: `Bearer ${token}` } : {}; } async function fetchPersons() { var _a; loading.value = true; error.value = null; try { const params = { skip: skip.value, limit: limit.value }; if (searchQuery.value) { params.search = searchQuery.value; } if (ghostFilter.value !== "all") { params.is_ghost = ghostFilter.value === "yes"; } if (activeFilter.value !== "all") { params.is_active = activeFilter.value === "active"; } if (hasUserFilter.value !== "all") { params.has_user = hasUserFilter.value === "yes"; } if (mergedFilter.value !== "all") { params.is_merged = mergedFilter.value === "yes"; } const response = await $fetch("/api/v1/admin/persons", { params, headers: getAuthHeaders() }); persons.value = response.items; totalCount.value = response.total; } catch (err) { console.error("[Persons] Failed to fetch persons:", err); error.value = ((_a = err == null ? void 0 : err.data) == null ? void 0 : _a.detail) || (err == null ? void 0 : err.message) || "Failed to load persons"; } finally { loading.value = false; } } function roleBadgeClass(role) { const r = (role || "").toLowerCase(); if (r === "superadmin") return "bg-purple-500/20 text-purple-300"; if (r === "admin") return "bg-indigo-500/20 text-indigo-300"; if (r === "staff") return "bg-cyan-500/20 text-cyan-300"; return "bg-slate-500/20 text-slate-300"; } function formatDate(dateStr) { if (!dateStr) return "\u2014"; try { const d = new Date(dateStr); return d.toLocaleDateString("hu-HU", { year: "numeric", month: "short", day: "numeric" }); } catch { return dateStr; } } return (_ctx, _push, _parent, _attrs) => { const _component_NuxtLink = __nuxt_component_0; _push(`

${ssrInterpolate(_ctx.$t("persons.title"))}

${ssrInterpolate(_ctx.$t("persons.subtitle"))}

`); if (loading.value) { _push(`

${ssrInterpolate(_ctx.$t("persons.loading"))}

`); } else if (error.value) { _push(`

${ssrInterpolate(error.value)}

`); } else { _push(`

${ssrInterpolate(_ctx.$t("persons.total_persons"))}

${ssrInterpolate(totalCount.value)}

${ssrInterpolate(_ctx.$t("persons.active_persons"))}

${ssrInterpolate(activeCount.value)}

${ssrInterpolate(_ctx.$t("persons.ghost_persons"))}

${ssrInterpolate(ghostCount.value)}

${ssrInterpolate(_ctx.$t("persons.merged_persons"))}

${ssrInterpolate(mergedCount.value)}

`); if (isFilterActive.value) { _push(`
${ssrInterpolate(_ctx.$t("persons.filtered_results"))}: ${ssrInterpolate(persons.value.length)} / ${ssrInterpolate(totalCount.value)} db
`); } else { _push(``); } _push(`
`); ssrRenderList(persons.value, (person) => { _push(``); }); _push(`
ID${ssrInterpolate(_ctx.$t("persons.name"))}${ssrInterpolate(_ctx.$t("persons.phone"))}${ssrInterpolate(_ctx.$t("persons.birth_date"))}${ssrInterpolate(_ctx.$t("persons.status"))}${ssrInterpolate(_ctx.$t("persons.users_count"))}${ssrInterpolate(_ctx.$t("persons.active_user"))}${ssrInterpolate(_ctx.$t("persons.address"))}${ssrInterpolate(_ctx.$t("persons.actions"))}
${ssrInterpolate(person.id)}`); _push(ssrRenderComponent(_component_NuxtLink, { to: "/persons/" + person.id, class: "text-sm font-medium text-white hover:underline cursor-pointer hover:text-indigo-400 transition-colors" }, { default: withCtx((_, _push2, _parent2, _scopeId) => { if (_push2) { _push2(`${ssrInterpolate(person.last_name)} ${ssrInterpolate(person.first_name)}`); } else { return [ createTextVNode(toDisplayString(person.last_name) + " " + toDisplayString(person.first_name), 1) ]; } }), _: 2 }, _parent)); _push(`${ssrInterpolate(person.phone || "\u2014")}${ssrInterpolate(formatDate(person.birth_date))}
${ssrInterpolate(person.is_active ? _ctx.$t("persons.active") : _ctx.$t("persons.inactive"))}`); if (person.is_ghost) { _push(`${ssrInterpolate(_ctx.$t("persons.ghost"))}`); } else { _push(``); } if (person.merged_into_id) { _push(`${ssrInterpolate(_ctx.$t("persons.merged"))}`); } else { _push(``); } _push(`
${ssrInterpolate(person.users_count)}`); if (person.active_user) { _push(`

${ssrInterpolate(person.active_user.email)}

${ssrInterpolate(person.active_user.role)}
`); } else { _push(`\u2014`); } _push(`
`); if (person.address) { _push(`${ssrInterpolate(person.address.full_address_text || person.address.address_city + ", " + person.address.address_street_name + " " + (person.address.address_house_number || ""))}`); } else { _push(`\u2014`); } _push(`
`); _push(ssrRenderComponent(_component_NuxtLink, { to: "/persons/" + person.id, class: "px-3 py-1.5 text-xs font-medium bg-slate-600/20 text-slate-300 hover:bg-slate-600/30 rounded-lg transition" }, { default: withCtx((_, _push2, _parent2, _scopeId) => { if (_push2) { _push2(`${ssrInterpolate(_ctx.$t("persons.view"))}`); } else { return [ createTextVNode(toDisplayString(_ctx.$t("persons.view")), 1) ]; } }), _: 2 }, _parent)); _push(`
`); if (persons.value.length === 0 && !loading.value) { _push(`

${ssrInterpolate(_ctx.$t("persons.no_results"))}

`); } else { _push(``); } _push(`
`); if (totalCount.value > limit.value) { _push(`

${ssrInterpolate(_ctx.$t("persons.showing"))} ${ssrInterpolate(skip.value + 1)}\u2013${ssrInterpolate(Math.min(skip.value + limit.value, totalCount.value))} / ${ssrInterpolate(totalCount.value)}

${ssrInterpolate(_ctx.$t("persons.prev"))}= totalCount.value) ? " disabled" : ""} class="${ssrRenderClass([skip.value + limit.value < totalCount.value ? "bg-slate-700 text-slate-300 hover:bg-slate-600" : "bg-slate-800 text-slate-600", "px-3 py-1.5 text-xs font-medium rounded-lg transition disabled:opacity-30 disabled:cursor-not-allowed"])}">${ssrInterpolate(_ctx.$t("persons.next"))}
`); } else { _push(``); } _push(``); } if (notification.value) { _push(`
${ssrInterpolate(notification.value.message)}
`); } else { _push(``); } _push(``); }; } }); const _sfc_setup = _sfc_main.setup; _sfc_main.setup = (props, ctx) => { const ssrContext = useSSRContext(); (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/persons/index.vue"); return _sfc_setup ? _sfc_setup(props, ctx) : void 0; }; export { _sfc_main as default }; //# sourceMappingURL=index-Ci9UUd4C.mjs.map