import { defineComponent, ref, computed, watch, unref, mergeProps, reactive, useSSRContext } from 'vue'; import { ssrRenderAttrs, ssrInterpolate, ssrRenderList, ssrRenderClass, ssrRenderComponent, ssrRenderStyle, ssrRenderAttr, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual } from 'vue/server-renderer'; import { c as useAuthStore, d as useCookie } from './server.mjs'; import { _ as _sfc_main$4 } from './SharedAddressForm-rsg7wrlQ.mjs'; import { useRoute, useRouter } from 'vue-router'; 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'; import './_plugin-vue_export-helper-1tPrXgE0.mjs'; const _sfc_main$3 = /* @__PURE__ */ defineComponent({ __name: "GarageGeneralTab", __ssrInlineRender: true, props: { garage: {} }, setup(__props) { const props = __props; function orgTypeLabel(type) { const map = { dealership: "Dealership", service: "Service Center", rental: "Rental Agency", fleet: "Fleet Operator", individual: "Individual", workshop: "Workshop", garage: "Garage", other: "Other" }; return map[type == null ? void 0 : type.toLowerCase()] || type || "-"; } function formatDate(dateStr) { if (!dateStr) return "-"; try { return new Intl.DateTimeFormat("hu-HU", { year: "numeric", month: "2-digit", day: "2-digit" }).format(new Date(dateStr)); } catch { return dateStr; } } function formatAddress(addr, flatPrefix = "address") { if (!props.garage) return "-"; if (addr && typeof addr === "object") { const parts = [ addr.zip, addr.city, addr.street_name, addr.street_type, addr.house_number ].filter(Boolean); if (parts.length > 0) return parts.join(" "); if (addr.full_address_text) return addr.full_address_text; } const flatParts = [ props.garage[`${flatPrefix}_zip`], props.garage[`${flatPrefix}_city`], props.garage[`${flatPrefix}_street_name`], props.garage[`${flatPrefix}_street_type`], props.garage[`${flatPrefix}_house_number`] ].filter(Boolean); return flatParts.join(" ") || "-"; } const formattedAddress = computed(() => { var _a; return formatAddress((_a = props.garage) == null ? void 0 : _a.address_detail, "address"); }); const formattedBillingAddress = computed(() => { var _a; return formatAddress((_a = props.garage) == null ? void 0 : _a.billing_address_detail, "billing"); }); const formattedNotificationAddress = computed(() => { var _a; return formatAddress((_a = props.garage) == null ? void 0 : _a.notification_address_detail, "notification"); }); return (_ctx, _push, _parent, _attrs) => { var _a, _b, _c, _d, _e, _f, _g, _h; _push(`

${ssrInterpolate(_ctx.$t("garages.details.company_info"))}

${ssrInterpolate(_ctx.$t("garages.details.company_name"))}

${ssrInterpolate(__props.garage.full_name)}

${ssrInterpolate(_ctx.$t("garages.details.display_name"))}

${ssrInterpolate(__props.garage.display_name || "\u2014")}

${ssrInterpolate(_ctx.$t("garages.details.org_type"))}

${ssrInterpolate(orgTypeLabel(__props.garage.org_type))}

${ssrInterpolate(_ctx.$t("garages.details.tax_number"))}

${ssrInterpolate(__props.garage.tax_number || "\u2014")}

${ssrInterpolate(_ctx.$t("garages.details.reg_number"))}

${ssrInterpolate(__props.garage.reg_number || "\u2014")}

${ssrInterpolate(_ctx.$t("garages.details.created_at"))}

${ssrInterpolate(formatDate(__props.garage.created_at))}

${ssrInterpolate(_ctx.$t("garages.details.address"))}

${ssrInterpolate(formattedAddress.value)}

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

${ssrInterpolate(_ctx.$t("garages.details.billing_address"))}

${ssrInterpolate(formattedBillingAddress.value)}

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

${ssrInterpolate(_ctx.$t("garages.details.notification_address"))}

${ssrInterpolate(formattedNotificationAddress.value)}

`); } else { _push(``); } _push(`

Rendszer Azonos\xEDt\xF3k

Gar\xE1zs ID: ${ssrInterpolate(__props.garage.id)}User ID: ${ssrInterpolate((_a = __props.garage.owner_user_id) != null ? _a : "N/A")}Person ID: ${ssrInterpolate((_b = __props.garage.owner_person_id) != null ? _b : "N/A")}

${ssrInterpolate(_ctx.$t("garages.details.contact_info"))}

`); if (__props.garage.contact_person_name || __props.garage.contact_email || __props.garage.contact_phone || __props.garage.primary_contact) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.contact_name"))}

${ssrInterpolate(__props.garage.contact_person_name || ((_c = __props.garage.primary_contact) == null ? void 0 : _c.full_name) || "\u2014")}

${ssrInterpolate(_ctx.$t("garages.details.contact_email"))}

${ssrInterpolate(__props.garage.contact_email || ((_d = __props.garage.primary_contact) == null ? void 0 : _d.email) || "\u2014")}

${ssrInterpolate(_ctx.$t("garages.details.contact_phone"))}

${ssrInterpolate(__props.garage.contact_phone || ((_e = __props.garage.primary_contact) == null ? void 0 : _e.phone) || "\u2014")}

`); if (((_f = __props.garage.primary_contact) == null ? void 0 : _f.role) || ((_g = __props.garage.primary_contact) == null ? void 0 : _g.department)) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.contact_role"))}

${ssrInterpolate(__props.garage.primary_contact.role || "\u2014")}`); if ((_h = __props.garage.primary_contact) == null ? void 0 : _h.department) { _push(` \xB7 ${ssrInterpolate(__props.garage.primary_contact.department)}`); } else { _push(``); } _push(`

`); } else { _push(``); } _push(`
`); } else { _push(`

${ssrInterpolate(_ctx.$t("garages.details.no_contact"))}

`); } _push(`
`); }; } }); const _sfc_setup$3 = _sfc_main$3.setup; _sfc_main$3.setup = (props, ctx) => { const ssrContext = useSSRContext(); (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("components/garages/GarageGeneralTab.vue"); return _sfc_setup$3 ? _sfc_setup$3(props, ctx) : void 0; }; const _sfc_main$2 = /* @__PURE__ */ defineComponent({ __name: "GarageFleetTab", __ssrInlineRender: true, props: { garage: {}, orgId: {}, fleetVehicles: {}, fleetLoading: { type: Boolean } }, setup(__props) { const props = __props; const auth = useAuthStore(); function hasOrgPermission(perm) { var _a, _b, _c, _d, _e; if (auth.isAdmin) return true; if ((_b = (_a = auth.user) == null ? void 0 : _a.system_capabilities) == null ? void 0 : _b[perm]) return true; if ((_e = (_d = (_c = auth.user) == null ? void 0 : _c.org_capabilities) == null ? void 0 : _d[props.orgId]) == null ? void 0 : _e[perm]) return true; return false; } function fleetStatusLabel(status) { const map = { active: "Active", inactive: "Inactive", sold: "Sold", scrapped: "Scrapped", pending: "Pending", draft: "Draft" }; return map[status == null ? void 0 : status.toLowerCase()] || status || "Unknown"; } function fleetStatusBadgeClass(status) { const map = { active: "bg-green-500/10 text-green-400", inactive: "bg-gray-500/10 text-gray-400", sold: "bg-red-500/10 text-red-400", scrapped: "bg-red-500/10 text-red-400", pending: "bg-yellow-500/10 text-yellow-400", draft: "bg-gray-500/10 text-gray-400" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-500/10 text-gray-400"; } function fleetStatusDotClass(status) { const map = { active: "bg-green-400", inactive: "bg-gray-400", sold: "bg-red-400", scrapped: "bg-red-400", pending: "bg-yellow-400", draft: "bg-gray-400" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-400"; } return (_ctx, _push, _parent, _attrs) => { _push(``); if (hasOrgPermission("fleet:view")) { _push(`

${ssrInterpolate(_ctx.$t("garages.fleet.title"))}

${ssrInterpolate(_ctx.$t("garages.fleet.total_vehicles", { count: __props.fleetVehicles.length }))}

`); ssrRenderList(__props.fleetVehicles, (v) => { _push(``); }); _push(``); if (__props.fleetVehicles.length === 0 && !__props.fleetLoading) { _push(``); } else { _push(``); } if (__props.fleetLoading) { _push(``); } else { _push(``); } _push(`
${ssrInterpolate(_ctx.$t("garages.fleet.plate"))}${ssrInterpolate(_ctx.$t("garages.fleet.brand_model"))}${ssrInterpolate(_ctx.$t("garages.fleet.year"))}${ssrInterpolate(_ctx.$t("garages.fleet.vin"))}${ssrInterpolate(_ctx.$t("garages.fleet.status"))}
${ssrInterpolate(v.license_plate || "\u2014")}${ssrInterpolate(v.brand || "\u2014")}`); if (v.brand && v.model) { _push(`\xB7`); } else { _push(``); } if (v.model) { _push(`${ssrInterpolate(v.model)}`); } else { _push(``); } _push(`${ssrInterpolate(v.year || "\u2014")}${ssrInterpolate(v.vin || "\u2014")} ${ssrInterpolate(fleetStatusLabel(v.status))}

${ssrInterpolate(_ctx.$t("garages.fleet.no_vehicles"))}

${ssrInterpolate(_ctx.$t("garages.details.loading"))}

`); } else { _push(`

${ssrInterpolate(_ctx.$t("garages.fleet.no_fleet_access"))}

`); } _push(``); }; } }); const _sfc_setup$2 = _sfc_main$2.setup; _sfc_main$2.setup = (props, ctx) => { const ssrContext = useSSRContext(); (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("components/garages/GarageFleetTab.vue"); return _sfc_setup$2 ? _sfc_setup$2(props, ctx) : void 0; }; const _sfc_main$1 = /* @__PURE__ */ defineComponent({ __name: "GarageSubscriptionTab", __ssrInlineRender: true, props: { garage: {}, fleetVehicles: {} }, emits: ["refresh"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const auth = useAuthStore(); const availableTiers = ref([]); const selectedTierId = ref(""); const customExpiresAt = ref(""); const subscriptionSaving = ref(false); const subscriptionSaveError = ref(null); const extraVehicles = ref(0); const extraBranches = ref(0); const extraUsers = ref(0); const addonDates = reactive({ vehicles: "", branches: "", users: "" }); function syncAddonFromSubscription() { var _a, _b, _c, _d, _e; const sub = (_a = props.garage) == null ? void 0 : _a.subscription; if (!sub) return; const allowances = sub.extra_allowances || {}; extraVehicles.value = (_b = allowances.extra_vehicles) != null ? _b : 0; extraBranches.value = (_c = allowances.extra_branches) != null ? _c : 0; extraUsers.value = (_d = allowances.extra_users) != null ? _d : 0; if ((_e = sub.addons) == null ? void 0 : _e.length) { for (const addon of sub.addons) { if (addon.type === "extra_vehicles" && addon.expires_at) { addonDates.vehicles = addon.expires_at.slice(0, 10); } else if (addon.type === "extra_branches" && addon.expires_at) { addonDates.branches = addon.expires_at.slice(0, 10); } else if (addon.type === "extra_users" && addon.expires_at) { addonDates.users = addon.expires_at.slice(0, 10); } } } } watch(() => { var _a; return (_a = props.garage) == null ? void 0 : _a.subscription; }, (newSub) => { if (newSub) { syncAddonFromSubscription(); } }, { immediate: true }); const vehicleQuotaLimit = computed(() => { var _a, _b; if (!((_b = (_a = props.garage) == null ? void 0 : _a.subscription) == null ? void 0 : _b.asset_limit)) return 5; return props.garage.subscription.asset_limit; }); const vehicleQuotaPercent = computed(() => { const limit = vehicleQuotaLimit.value; if (limit <= 0) return 0; return Math.min(100, Math.round(props.fleetVehicles.length / limit * 100)); }); const branchQuotaPercent = computed(() => { var _a, _b, _c, _d; const branches = ((_b = (_a = props.garage) == null ? void 0 : _a.branches) == null ? void 0 : _b.length) || 0; const limit = (_d = (_c = props.garage) == null ? void 0 : _c.subscription) == null ? void 0 : _d.branch_limit; if (!limit || limit <= 0) return 0; return Math.min(100, Math.round(branches / limit * 100)); }); const employeeQuotaPercent = computed(() => { var _a, _b, _c; const count = ((_a = props.garage) == null ? void 0 : _a.member_count) || 0; const limit = (_c = (_b = props.garage) == null ? void 0 : _b.subscription) == null ? void 0 : _c.user_limit; if (!limit || limit <= 0) return 0; return Math.min(100, Math.round(count / limit * 100)); }); const addonsChanged = computed(() => { var _a, _b, _c, _d, _e, _f, _g; if (!((_a = props.garage) == null ? void 0 : _a.subscription)) return false; const sub = props.garage.subscription; const baselineVehicles = (_c = (_b = sub.extra_allowances) == null ? void 0 : _b.extra_vehicles) != null ? _c : 0; const baselineBranches = (_e = (_d = sub.extra_allowances) == null ? void 0 : _d.extra_branches) != null ? _e : 0; const baselineUsers = (_g = (_f = sub.extra_allowances) == null ? void 0 : _f.extra_users) != null ? _g : 0; return extraVehicles.value !== baselineVehicles || extraBranches.value !== baselineBranches || extraUsers.value !== baselineUsers; }); function formatChanges(hist) { var _a, _b, _c, _d, _e, _f; if (!hist) return null; const oldData = hist.old_data || {}; const newData = hist.new_data || {}; const lines = []; if (hist.action === "SUBSCRIPTION_TIER_CHANGE") { const oldTier = oldData.tier_id; const newTier = newData.tier_id; const newTierName = newData.tier_name; if (oldTier !== void 0 || newTier !== void 0) { lines.push(`Csomag: #${oldTier != null ? oldTier : "?"} \u2192 ${newTierName != null ? newTierName : "#" + newTier}`); } const oldAddons = oldData.addons || {}; const newAddons = newData.addons || {}; for (const key of ["extra_vehicles", "extra_branches", "extra_users"]) { const oldVal = (_a = oldAddons[key]) != null ? _a : 0; const newVal = (_b = newAddons[key]) != null ? _b : 0; if (oldVal !== newVal) { const label = key === "extra_vehicles" ? "Extra J\xE1rm\u0171" : key === "extra_branches" ? "Extra Telephely" : "Extra Dolgoz\xF3"; lines.push(`${label}: ${oldVal} \u2192 ${newVal}`); } } return lines.length > 0 ? lines : null; } if (hist.action === "SUBSCRIPTION_ADDON_OVERRIDE") { const oldAddons = oldData.addons || {}; const newAddons = newData.addons || {}; let hasChanges = false; for (const key of ["extra_vehicles", "extra_branches", "extra_users"]) { const oldVal = (_c = oldAddons[key]) != null ? _c : 0; const newVal = (_d = newAddons[key]) != null ? _d : 0; if (oldVal !== newVal) { hasChanges = true; const label = key === "extra_vehicles" ? "Extra J\xE1rm\u0171" : key === "extra_branches" ? "Extra Telephely" : "Extra Dolgoz\xF3"; lines.push(`${label}: ${oldVal} \u2192 ${newVal}`); } } return hasChanges ? lines : null; } const allKeys = /* @__PURE__ */ new Set([...Object.keys(oldData), ...Object.keys(newData)]); for (const key of allKeys) { if (key === "addons") continue; const oldVal = JSON.stringify((_e = oldData[key]) != null ? _e : null); const newVal = JSON.stringify((_f = newData[key]) != null ? _f : null); if (oldVal !== newVal) { lines.push(`${key}: ${oldVal} \u2192 ${newVal}`); } } return lines.length > 0 ? lines : null; } function formatDate(dateStr) { if (!dateStr) return "-"; try { return new Intl.DateTimeFormat("hu-HU", { year: "numeric", month: "2-digit", day: "2-digit" }).format(new Date(dateStr)); } catch { return dateStr; } } function addonLabel(type) { const map = { extra_vehicles: "Extra J\xE1rm\u0171", extra_branches: "Extra Telephely", extra_users: "Extra Dolgoz\xF3" }; return map[type] || type; } function tierBadgeClass(tier) { const map = { basic: "bg-gray-100 text-gray-800", premium: "bg-yellow-100 text-yellow-800", enterprise: "bg-purple-100 text-purple-800", trial: "bg-blue-100 text-blue-800" }; return map[tier == null ? void 0 : tier.toLowerCase()] || "bg-gray-100 text-gray-800"; } function statusLabel(status) { const map = { active: "Active", inactive: "Inactive", suspended: "Suspended", pending: "Pending" }; return map[status == null ? void 0 : status.toLowerCase()] || status; } function statusBadgeClass(status) { const map = { active: "bg-green-100 text-green-800", inactive: "bg-gray-100 text-gray-800", suspended: "bg-red-100 text-red-800", pending: "bg-yellow-100 text-yellow-800" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-100 text-gray-800"; } function statusDotClass(status) { const map = { active: "bg-green-400", inactive: "bg-gray-400", suspended: "bg-red-400", pending: "bg-yellow-400" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-400"; } async function fetchTiers() { try { const tokenCookie = useCookie("access_token"); const token = (tokenCookie.value || auth.token || "").trim(); console.log("[GarageSubscriptionTab] Fetching tiers..."); const res = await fetch("/api/v1/admin/packages?include_hidden=true&limit=100", { headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/json" } }); if (!res.ok) { const errBody = await res.text().catch(() => ""); console.error(`[GarageSubscriptionTab] Fetch tiers failed: ${res.status} ${res.statusText}`, errBody); throw new Error(`Failed to fetch tiers: ${res.status} ${errBody}`); } const data = await res.json(); console.log("[GarageSubscriptionTab] Fetched tiers response:", JSON.stringify(data)); availableTiers.value = data.tiers || []; console.log("[GarageSubscriptionTab] availableTiers set:", availableTiers.value.length, "items"); } catch (e) { console.error("[GarageSubscriptionTab] Failed to fetch tiers:", e); subscriptionSaveError.value = `Hiba a csomagok bet\xF6lt\xE9sekor: ${e.message}`; } } __expose({ fetchTiers }); return (_ctx, _push, _parent, _attrs) => { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k; _push(`

${ssrInterpolate(_ctx.$t("garages.details.subscription_info"))}

`); if (__props.garage.subscription) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.tier_name"))}

${ssrInterpolate(__props.garage.subscription.tier_name)}

${ssrInterpolate(_ctx.$t("garages.details.tier_level"))}

${ssrInterpolate(_ctx.$t("garages.details.level_n", { n: __props.garage.subscription.tier_level }))}

${ssrInterpolate(_ctx.$t("garages.details.expires_at"))}

`); if (__props.garage.subscription.expires_at) { _push(`

${ssrInterpolate(formatDate(__props.garage.subscription.expires_at))}

`); } else { _push(`

${ssrInterpolate(_ctx.$t("garages.indefinite"))}

`); } _push(`

${ssrInterpolate(_ctx.$t("garages.details.asset_limit"))}

${ssrInterpolate(__props.garage.subscription.asset_limit)} ${ssrInterpolate(_ctx.$t("garages.details.vehicles"))}

`); } else { _push(``); } if (__props.garage.subscription) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.vehicles_used"))}

${ssrInterpolate(__props.fleetVehicles.length)} / ${ssrInterpolate((_b = (_a = __props.garage.subscription) == null ? void 0 : _a.asset_limit) != null ? _b : "\u221E")}

= 70 ? "bg-amber-500" : "bg-blue-500", "h-full rounded-full transition-all duration-500"])}" style="${ssrRenderStyle({ width: Math.min(100, vehicleQuotaPercent.value) + "%" })}">

${ssrInterpolate(_ctx.$t("garages.details.branches_used"))}

${ssrInterpolate(((_c = __props.garage.branches) == null ? void 0 : _c.length) || 0)} / ${ssrInterpolate((_e = (_d = __props.garage.subscription) == null ? void 0 : _d.branch_limit) != null ? _e : "\u221E")}

= 70 ? "bg-amber-500" : "bg-emerald-500", "h-full rounded-full transition-all duration-500"])}" style="${ssrRenderStyle({ width: Math.min(100, branchQuotaPercent.value) + "%" })}">

${ssrInterpolate(_ctx.$t("garages.details.employees_used"))}

${ssrInterpolate(__props.garage.member_count || 0)} / ${ssrInterpolate(((_f = __props.garage.subscription) == null ? void 0 : _f.user_limit) && __props.garage.subscription.user_limit > 0 ? __props.garage.subscription.user_limit : "\u221E")}

`); if (((_g = __props.garage.subscription) == null ? void 0 : _g.user_limit) && __props.garage.subscription.user_limit > 0) { _push(`
= 70 ? "bg-amber-500" : "bg-purple-500", "h-full rounded-full transition-all duration-500"])}" style="${ssrRenderStyle({ width: Math.min(100, employeeQuotaPercent.value) + "%" })}">
`); } else { _push(``); } _push(`

${ssrInterpolate(_ctx.$t("garages.details.status"))}

${ssrInterpolate(statusLabel(__props.garage.status))}
`); } else { _push(``); } if ((_i = (_h = __props.garage.subscription) == null ? void 0 : _h.addons) == null ? void 0 : _i.length) { _push(`

${ssrInterpolate(_ctx.$t("garages.active_addons"))}

`); ssrRenderList(__props.garage.subscription.addons, (addon) => { _push(``); }); _push(`
${ssrInterpolate(_ctx.$t("garages.addon_type"))}${ssrInterpolate(_ctx.$t("garages.addon_quantity"))}${ssrInterpolate(_ctx.$t("garages.addon_expires"))}
${ssrInterpolate(addonLabel(addon.type))}${ssrInterpolate(addon.quantity)}`); if (addon.expires_at || addon.valid_until) { _push(`${ssrInterpolate(formatDate(addon.expires_at || addon.valid_until))}`); } else { _push(`${ssrInterpolate(_ctx.$t("garages.indefinite"))}`); } _push(`
`); } else if (__props.garage.subscription) { _push(`

${ssrInterpolate(_ctx.$t("garages.active_addons"))}

${ssrInterpolate(_ctx.$t("garages.no_active_addons"))}

`); } else { _push(`

${ssrInterpolate(_ctx.$t("garages.details.no_subscription"))}

`); } _push(`

${ssrInterpolate(_ctx.$t("garages.change_package"))}

${ssrInterpolate(_ctx.$t("garages.custom_expiration_hint"))}

${ssrInterpolate(_ctx.$t("garages.addon_expiration_hint"))}

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

${ssrInterpolate(subscriptionSaveError.value)}

`); } else { _push(``); } _push(`
`); if (subscriptionSaving.value) { _push(` ${ssrInterpolate(_ctx.$t("garages.saving"))}`); } else { _push(`${ssrInterpolate(_ctx.$t("garages.save"))}`); } _push(`

${ssrInterpolate(_ctx.$t("garages.details.subscription_history"))}

`); if ((_k = (_j = __props.garage) == null ? void 0 : _j.subscription_history) == null ? void 0 : _k.length) { _push(``); ssrRenderList(__props.garage.subscription_history, (hist) => { _push(``); }); _push(``); } else { _push(``); } _push(`
${ssrInterpolate(_ctx.$t("garages.details.history_date"))}${ssrInterpolate(_ctx.$t("garages.details.history_package"))}${ssrInterpolate(_ctx.$t("garages.details.history_action"))}${ssrInterpolate(_ctx.$t("garages.details.history_status"))}
${ssrInterpolate(formatDate(hist.timestamp))}${ssrInterpolate(hist.tier_name || "\u2014")}
${ssrInterpolate(hist.action || "\u2014")}`); if (formatChanges(hist)) { _push(`
`); ssrRenderList(formatChanges(hist), (line, li) => { _push(`
\u203A${ssrInterpolate(line)}
`); }); _push(`
`); } else { _push(`Nincs r\xE9szletes adat`); } _push(`
Sikeres `); if (hist.admin_user_id) { _push(` Admin #${ssrInterpolate(hist.admin_user_id)}`); } else { _push(``); } _push(`

${ssrInterpolate(_ctx.$t("garages.details.no_subscription_history"))}

`); }; } }); const _sfc_setup$1 = _sfc_main$1.setup; _sfc_main$1.setup = (props, ctx) => { const ssrContext = useSSRContext(); (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("components/garages/GarageSubscriptionTab.vue"); return _sfc_setup$1 ? _sfc_setup$1(props, ctx) : void 0; }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "index", __ssrInlineRender: true, setup(__props) { const route = useRoute(); useRouter(); const auth = useAuthStore(); const orgId = route.params.id; const loading = ref(true); const error = ref(null); const garage = ref(null); const members = ref([]); const activeTab = ref("general"); const fleetVehicles = ref([]); const fleetLoading = ref(false); const subscriptionTabRef = ref(null); const showEditModal = ref(false); const editModalTab = ref("basic"); const saving = ref(false); const editForm = ref({ full_name: "", name: "", display_name: "", email: "", phone: "", tax_number: "", reg_number: "", org_type: "", /** P0 BUGFIX: Use address_detail object instead of flat address fields */ address_detail: { zip: null, city: null, street_name: null, street_type: null, house_number: null, stairwell: null, floor: null, door: null, parcel_id: null, full_address_text: null, latitude: null, longitude: null }, contact_person_name: "", contact_email: "", contact_phone: "", billing_zip: "", billing_city: "", billing_street_name: "", billing_street_type: "", billing_house_number: "", notification_zip: "", notification_city: "", notification_street_name: "", notification_street_type: "", notification_house_number: "" }); const showAddEmployeeModal = ref(false); const newMemberEmail = ref(""); const newMemberRole = ref("member"); const addingMember = ref(false); const showEditRoleModal = ref(false); ref(null); const editingRole = ref("member"); const savingRole = ref(false); const showRemoveModal = ref(false); const removingMember = ref(null); const removing = ref(false); const notification = ref({ show: false, type: "success", message: "" }); const tabs = [ { key: "general", label: "garages.details.generalTab" }, { key: "employees", label: "garages.details.employeesTab" }, { key: "fleet", label: "garages.details.fleetTab" }, { key: "subscription", label: "garages.details.subscriptionTab" }, { key: "analytics", label: "garages.details.analyticsTab" } ]; const editModalTabs = [ { key: "basic", label: "garages.details.editBasicTab" }, { key: "contact", label: "garages.details.editContactTab" }, { key: "addresses", label: "garages.details.editAddressTab" } ]; function hasOrgPermission(perm) { var _a, _b, _c, _d, _e; if (auth.isAdmin) return true; if ((_b = (_a = auth.user) == null ? void 0 : _a.system_capabilities) == null ? void 0 : _b[perm]) return true; if ((_e = (_d = (_c = auth.user) == null ? void 0 : _c.org_capabilities) == null ? void 0 : _d[orgId]) == null ? void 0 : _e[perm]) return true; return false; } const vehicleQuotaLimit = computed(() => { var _a, _b; if (!((_b = (_a = garage.value) == null ? void 0 : _a.subscription) == null ? void 0 : _b.asset_limit)) return 5; return garage.value.subscription.asset_limit; }); const vehicleQuotaPercent = computed(() => { const limit = vehicleQuotaLimit.value; if (limit <= 0) return 0; return Math.min(100, Math.round(fleetVehicles.value.length / limit * 100)); }); computed(() => { var _a, _b, _c, _d; const branches = ((_b = (_a = garage.value) == null ? void 0 : _a.branches) == null ? void 0 : _b.length) || 0; const limit = (_d = (_c = garage.value) == null ? void 0 : _c.subscription) == null ? void 0 : _d.branch_limit; if (!limit || limit <= 0) return 0; return Math.min(100, Math.round(branches / limit * 100)); }); computed(() => { var _a, _b, _c; const count = ((_a = garage.value) == null ? void 0 : _a.member_count) || 0; const limit = (_c = (_b = garage.value) == null ? void 0 : _b.subscription) == null ? void 0 : _c.user_limit; if (!limit || limit <= 0) return 0; return Math.min(100, Math.round(count / limit * 100)); }); const missingFields = computed(() => { if (!garage.value) return []; const missing = []; const g = garage.value; const isIndividual = g.org_type === "individual"; if (!isIndividual) { if (!g.tax_number) missing.push({ key: "tax_number", label: "garages.details.missing_tax_number" }); } if (!g.contact_email && !g.email) missing.push({ key: "contact_email", label: "garages.details.missing_contact_email" }); if (!g.contact_phone && !g.phone) missing.push({ key: "contact_phone", label: "garages.details.missing_contact_phone" }); if (!isIndividual) { if (!g.billing_city || !g.billing_zip) missing.push({ key: "billing", label: "garages.details.missing_billing" }); } return missing; }); async function fetchDetails() { loading.value = true; error.value = null; try { const tokenCookie = useCookie("access_token"); const token = (tokenCookie.value || auth.token || "").trim(); const headers = { "Authorization": `Bearer ${token}`, "Content-Type": "application/json" }; const res = await fetch(`/api/v1/admin/organizations/${orgId}/details`, { headers }); if (!res.ok) throw new Error(`Failed to fetch organization: ${res.status}`); const data = await res.json(); garage.value = data; members.value = data.members || []; } catch (e) { error.value = e.message || "Failed to load garage details"; } finally { loading.value = false; } } async function fetchFleetVehicles() { fleetLoading.value = true; try { const tokenCookie = useCookie("access_token"); const token = (tokenCookie.value || auth.token || "").trim(); const res = await fetch(`/api/v1/admin/organizations/${orgId}/vehicles`, { headers: { "Authorization": `Bearer ${token}`, "Content-Type": "application/json" } }); if (!res.ok) throw new Error(`Failed to fetch fleet: ${res.status}`); const data = await res.json(); fleetVehicles.value = data.vehicles || []; } catch (e) { console.error("Fleet fetch error:", e); fleetVehicles.value = []; } finally { fleetLoading.value = false; } } const cleanGarageName = computed(() => { if (!garage.value) return ""; const raw = garage.value.display_name || garage.value.name || garage.value.full_name || ""; return raw.replace(/[\s-]*#\d+\s*$/g, "").trim() || "Garage #" + garage.value.id; }); function garageDisplayName() { if (!garage.value) return ""; return garage.value.name || garage.value.email || garage.value.full_name || "Garage #" + garage.value.id; } function getInitials(name) { if (!name) return "?"; return name.split(" ").map((w) => w[0]).join("").toUpperCase().slice(0, 2); } function getInitialsColor(name) { const colors = [ "bg-red-500", "bg-yellow-500", "bg-green-500", "bg-blue-500", "bg-indigo-500", "bg-purple-500", "bg-pink-500", "bg-teal-500" ]; let hash = 0; for (let i = 0; i < (name || "").length; i++) { hash = name.charCodeAt(i) + ((hash << 5) - hash); } return colors[Math.abs(hash) % colors.length]; } function statusLabel(status) { const map = { active: "Active", inactive: "Inactive", suspended: "Suspended", pending: "Pending" }; return map[status == null ? void 0 : status.toLowerCase()] || status; } function statusBadgeClass(status) { const map = { active: "bg-green-100 text-green-800", inactive: "bg-gray-100 text-gray-800", suspended: "bg-red-100 text-red-800", pending: "bg-yellow-100 text-yellow-800" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-100 text-gray-800"; } function statusDotClass(status) { const map = { active: "bg-green-400", inactive: "bg-gray-400", suspended: "bg-red-400", pending: "bg-yellow-400" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-400"; } function memberFullName(member) { if (!member) return ""; if (member.display_name) return member.display_name; if (member.name) return member.name; if (member.email) return member.email; if (member.person) { const first = member.person.first_name || ""; const last = member.person.last_name || ""; const full = `${last} ${first}`.trim(); if (full) return full; if (member.person.email) return member.person.email; } if (member.user_id) return String(member.user_id); return "Unknown"; } function roleLabel(role) { const map = { admin: "Admin", manager: "Manager", member: "Member", owner: "Owner" }; return map[role == null ? void 0 : role.toLowerCase()] || role || "Member"; } function roleBadgeClass(role) { const map = { admin: "bg-purple-100 text-purple-800", manager: "bg-blue-100 text-blue-800", member: "bg-green-100 text-green-800", owner: "bg-yellow-100 text-yellow-800" }; return map[role == null ? void 0 : role.toLowerCase()] || "bg-gray-100 text-gray-800"; } function memberStatusLabel(status) { const map = { active: "Active", invited: "Invited", suspended: "Suspended", inactive: "Inactive" }; return map[status == null ? void 0 : status.toLowerCase()] || status || "Unknown"; } function memberStatusBadgeClass(status) { const map = { active: "bg-green-100 text-green-800", invited: "bg-blue-100 text-blue-800", suspended: "bg-red-100 text-red-800", inactive: "bg-gray-100 text-gray-800" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-100 text-gray-800"; } function memberStatusDotClass(status) { const map = { active: "bg-green-400", invited: "bg-blue-400", suspended: "bg-red-400", inactive: "bg-gray-400" }; return map[status == null ? void 0 : status.toLowerCase()] || "bg-gray-400"; } watch(activeTab, (newTab) => { var _a; if (newTab === "fleet" || newTab === "analytics" || newTab === "subscription") { if (fleetVehicles.value.length === 0) { fetchFleetVehicles(); } } if (newTab === "subscription") { (_a = subscriptionTabRef.value) == null ? void 0 : _a.fetchTiers(); } }); return (_ctx, _push, _parent, _attrs) => { const _component_GaragesGarageGeneralTab = _sfc_main$3; const _component_GaragesGarageFleetTab = _sfc_main$2; const _component_GaragesGarageSubscriptionTab = _sfc_main$1; const _component_SharedAddressForm = _sfc_main$4; _push(``); if (loading.value) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.loading"))}

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

${ssrInterpolate(error.value)}

`); } else if (garage.value) { _push(``); if (missingFields.value.length > 0) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.missing_data_title"))}

${ssrInterpolate(_ctx.$t("garages.details.missing_data_count", { count: missingFields.value.length }))}

${ssrInterpolate(garage.value.status !== "active" ? _ctx.$t("garages.details.missing_data_activation_required") : _ctx.$t("garages.details.missing_data_desc"))}

`); ssrRenderList(missingFields.value, (field) => { _push(` ${ssrInterpolate(_ctx.$t(field.label))}`); }); _push(`
`); } else { _push(``); } _push(`
${ssrInterpolate(getInitials(garageDisplayName()))}

${ssrInterpolate(cleanGarageName.value)}

${ssrInterpolate(statusLabel(garage.value.status))}

${ssrInterpolate(garage.value.full_name)} `); if (garage.value.tax_number) { _push(`\xB7 ${ssrInterpolate(_ctx.$t("garages.details.tax_number"))}: ${ssrInterpolate(garage.value.tax_number)}`); } else { _push(``); } _push(`

`); if (hasOrgPermission("org:edit")) { _push(``); } else { _push(``); } _push(`
`); if (activeTab.value === "general") { _push(ssrRenderComponent(_component_GaragesGarageGeneralTab, { garage: garage.value }, null, _parent)); } else { _push(``); } if (activeTab.value === "employees") { _push(`

${ssrInterpolate(_ctx.$t("garages.employees.title"))}

${ssrInterpolate(_ctx.$t("garages.employees.total_count", { count: members.value.length }))}

`); if (hasOrgPermission("org:manage-members")) { _push(``); } else { _push(``); } _push(`
`); ssrRenderList(members.value, (member) => { var _a, _b, _c; _push(``); }); _push(``); if (members.value.length === 0) { _push(``); } else { _push(``); } _push(`
${ssrInterpolate(_ctx.$t("garages.employees.name"))}${ssrInterpolate(_ctx.$t("garages.employees.email_phone"))}${ssrInterpolate(_ctx.$t("garages.employees.role"))}${ssrInterpolate(_ctx.$t("garages.employees.status"))}${ssrInterpolate(_ctx.$t("garages.employees.actions"))}
${ssrInterpolate(getInitials(memberFullName(member)))}

${ssrInterpolate(memberFullName(member))}

ID: ${ssrInterpolate(member.user_id || member.id)}

User_id: ${ssrInterpolate(member.user_id || "N/A")}Person_id: ${ssrInterpolate(((_a = member.person) == null ? void 0 : _a.id) || "N/A")}
`); if ((_b = member.person) == null ? void 0 : _b.email) { _push(`

${ssrInterpolate(member.person.email)}

`); } else { _push(`

\u2014

`); } if ((_c = member.person) == null ? void 0 : _c.phone) { _push(`

${ssrInterpolate(member.person.phone)}

`); } else { _push(``); } _push(`
${ssrInterpolate(roleLabel(member.role))} ${ssrInterpolate(memberStatusLabel(member.status))}
`); if (hasOrgPermission("org:manage-members")) { _push(``); } else { _push(``); } if (hasOrgPermission("org:manage-members")) { _push(``); } else { _push(``); } _push(`

${ssrInterpolate(_ctx.$t("garages.employees.no_employees"))}

`); } else { _push(``); } if (activeTab.value === "fleet") { _push(ssrRenderComponent(_component_GaragesGarageFleetTab, { garage: garage.value, "org-id": unref(orgId), "fleet-vehicles": fleetVehicles.value, "fleet-loading": fleetLoading.value }, null, _parent)); } else { _push(``); } if (activeTab.value === "subscription") { _push(ssrRenderComponent(_component_GaragesGarageSubscriptionTab, { ref_key: "subscriptionTabRef", ref: subscriptionTabRef, garage: garage.value, "fleet-vehicles": fleetVehicles.value, onRefresh: fetchDetails }, null, _parent)); } else { _push(``); } if (activeTab.value === "analytics") { _push(`
${ssrInterpolate(_ctx.$t("garages.analytics.ltv"))}

150 000 Ft

+12% ezen a h\xF3napon

${ssrInterpolate(_ctx.$t("garages.analytics.mrr"))}

15 000 Ft

${ssrInterpolate(_ctx.$t("garages.analytics.monthly_recurring"))}

${ssrInterpolate(_ctx.$t("garages.analytics.outstanding"))}

0 Ft

${ssrInterpolate(_ctx.$t("garages.analytics.all_settled"))}

${ssrInterpolate(_ctx.$t("garages.analytics.earned_credits"))}

450 XP

${ssrInterpolate(_ctx.$t("garages.analytics.contribution_xp"))}

${ssrInterpolate(_ctx.$t("garages.analytics.invited_companies"))}

12

${ssrInterpolate(_ctx.$t("garages.analytics.companies_joined"))}

${ssrInterpolate(_ctx.$t("garages.analytics.validated_garages"))}

8

${ssrInterpolate(_ctx.$t("garages.analytics.garages_confirmed"))}

${ssrInterpolate(_ctx.$t("garages.analytics.utilization"))}

${ssrInterpolate(_ctx.$t("garages.analytics.vehicle_quota"))}${ssrInterpolate(fleetVehicles.value.length)} / ${ssrInterpolate(vehicleQuotaLimit.value)}
= 70 ? "bg-amber-500" : "bg-blue-500", "h-full rounded-full transition-all duration-500"])}" style="${ssrRenderStyle({ width: vehicleQuotaPercent.value + "%" })}">

${ssrInterpolate(vehicleQuotaPercent.value)}% ${ssrInterpolate(_ctx.$t("garages.analytics.utilized"))}

${ssrInterpolate(_ctx.$t("garages.analytics.marketplace_engagement"))}

${ssrInterpolate(_ctx.$t("garages.analytics.avg_rating"))}
4.8
${ssrInterpolate(_ctx.$t("garages.analytics.total_reviews"))}124
${ssrInterpolate(_ctx.$t("garages.analytics.service_requests"))}47
${ssrInterpolate(_ctx.$t("garages.analytics.response_rate"))}92%
`); } else { _push(``); } if (showEditModal.value) { _push(`

${ssrInterpolate(_ctx.$t("garages.details.edit_details"))}

`); if (editModalTab.value === "basic") { _push(`

${ssrInterpolate(_ctx.$t("garages.details.address"))}

`); if (editForm.value.address_detail) { _push(ssrRenderComponent(_component_SharedAddressForm, { modelValue: editForm.value.address_detail, "onUpdate:modelValue": ($event) => editForm.value.address_detail = $event }, null, _parent)); } else { _push(``); } _push(`
`); } else { _push(``); } if (editModalTab.value === "contact") { _push(`
`); } else { _push(``); } if (editModalTab.value === "addresses") { _push(`

${ssrInterpolate(_ctx.$t("garages.details.billing_address"))}

${ssrInterpolate(_ctx.$t("garages.details.notification_address"))}

`); } else { _push(``); } _push(`
`); if (saving.value) { _push(``); } else { _push(``); } _push(` ${ssrInterpolate(saving.value ? _ctx.$t("garages.details.saving") : _ctx.$t("garages.details.save"))}
`); } else { _push(``); } if (showAddEmployeeModal.value) { _push(`

${ssrInterpolate(_ctx.$t("garages.employees.add_employee"))}

`); if (addingMember.value) { _push(``); } else { _push(``); } _push(` ${ssrInterpolate(addingMember.value ? _ctx.$t("garages.employees.adding") : _ctx.$t("garages.employees.add"))}
`); } else { _push(``); } if (showEditRoleModal.value) { _push(`

${ssrInterpolate(_ctx.$t("garages.employees.edit_role"))}

`); if (savingRole.value) { _push(``); } else { _push(``); } _push(` ${ssrInterpolate(savingRole.value ? _ctx.$t("garages.employees.saving") : _ctx.$t("garages.employees.save"))}
`); } else { _push(``); } if (showRemoveModal.value) { _push(``); } else { _push(``); } if (notification.value.show) { _push(`
`); if (notification.value.type === "success") { _push(``); } else { _push(``); } if (notification.value.type === "error") { _push(``); } else { _push(``); } _push(`

${ssrInterpolate(notification.value.message)}

`); } else { _push(``); } _push(``); } 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/garages/[id]/index.vue"); return _sfc_setup ? _sfc_setup(props, ctx) : void 0; }; export { _sfc_main as default }; //# sourceMappingURL=index-DEHPSD4s.mjs.map