const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./chunks/OverviewReport-BjCtcDC9.js","./chunks/toastStore-CRCNwITM.js","./chunks/default-i18n-KrIlCc2E.js","./chunks/ApexLineChart-BDoZ0ljB.js","./chunks/vue3-apexcharts-C-WQ0zow.js","./chunks/useChartColors-Bi1Kbjjv.js","./chunks/_plugin-vue_export-helper-1tPrXgE0.js","../css/main-monsterinsights-D8PHJfvy.css","./chunks/LoadingSpinnerInline-B4kX5NYb.js","../css/main-monsterinsights-CKJSBouy.css","./chunks/Icon-Cz1-Vo-r.js","../css/main-monsterinsights-DdCOUrGJ.css","./chunks/SiteNotes-sUVlPnw7.js","./chunks/flatpickr-CNAtgokQ.js","../css/main-monsterinsights-CMSe2SYd.css","./chunks/siteNotes-CUK65xMh.js","./chunks/ajax-B_XS1gT5.js","./chunks/useOverviewChartData-ea-7IFwh.js","./chunks/ReportTableModal-CDgzf1E8.js","./chunks/Modal-B9mMTzc_.js","../css/main-monsterinsights-nGno5xCI.css","./chunks/overviewTableFormatters-Bh6rmRkk.js","../css/main-monsterinsights-PhT_QwHw.css","./chunks/reportValues-hnaHRbaC.js","./chunks/settings-DM9kkmj_.js","./chunks/FunnelModal-BmPkUDcG.js","./chunks/TheAppHeader-DEdY-dez.js","./chunks/addons-CSVIjAyY.js","./chunks/useNotices-BpzNuZJ7.js","./chunks/UniversallyPromo-NH8NC5TQ.js","../css/main-monsterinsights-RvD8Et7x.css","./chunks/useReportPermissions-Lp2-kd6x.js","./chunks/useAuthGate-DCWToggq.js","./chunks/dateIntervals-BPoui_3H.js","./chunks/useFeatureGate-Ds3Z3eq-.js","../css/main-monsterinsights-h4_uXCXe.css","./chunks/ReAuthModal-B3ASDJ6j.js","./chunks/auth-CC6F9_ZC.js","../css/main-monsterinsights-CusxVmhz.css","./chunks/AppOverlays-BGer0Qoo.js","../css/main-monsterinsights-BqoTIBUO.css","../css/main-monsterinsights-Baa52G3M.css","./chunks/TrafficOverviewReport-hZc3xYK7.js","./chunks/trafficSampleData-B7xNOjWd.js","./chunks/reportCache-BGhGkpr3.js","./chunks/aggregateDateEntityRows-i7QMgwng.js","./chunks/compareDateLabels-B56Y3XjZ.js","./chunks/useReport-1GAdDSvm.js","./chunks/ReportPageLayout-CL25dyVF.js","../css/main-monsterinsights-uXEj5soP.css","./chunks/ReportChartSection-CPrm1WSX.js","../css/main-monsterinsights-JsfEpJsg.css","./chunks/ReportDataTable-cdFWEqiZ.js","../css/main-monsterinsights-Bwn3eYFP.css","./chunks/TrafficTechnologyReport-B7j79IAt.js","./chunks/ReportPieChart-DOkDJooB.js","../css/main-monsterinsights-DwI9-V5g.css","../css/main-monsterinsights-Bf6g5qXz.css","./chunks/TrafficLandingPagesReport-DZHWL3yb.js","./chunks/TrafficCampaignReport-RRQtgngn.js","./chunks/TrafficSourceMediumReport-DSn9-Hhb.js","./chunks/TrafficSocialReport-DckX_F9r.js","./chunks/TrafficAIReport-gLVQG8SZ.js","./chunks/FormsReport-CYIHZU3X.js","./chunks/ExceptionsReport-BqbrPB7y.js","../css/main-monsterinsights-D7IMHQB2.css","./chunks/MediaReport-DVjR8wbG.js","./chunks/DimensionsReport-DVKG-z4b.js","./chunks/RealtimeReport-aG55UKdD.js","../css/main-monsterinsights-Dqpti7IV.css","./chunks/SearchConsoleReport-Ca4U4Pfd.js","./chunks/ReportKeyMetrics-DORZJ7iF.js","./chunks/seo-vgfHxltu.js","./chunks/SiteSpeedReport-bvIiCOoJ.js","./chunks/EcommerceOverviewReport-W0_HJibW.js","./chunks/ecommerceReports-D13-vEUK.js","./chunks/ecommerceSampleData-CfcmM5cV.js","./chunks/EcommerceCouponsReport-UnBihghQ.js","./chunks/EcommerceCartAbandonmentReport-CyxzBz21.js","./chunks/EcommerceFunnelReport-C10DCbSD.js","../css/main-monsterinsights-BACmtAc6.css","./chunks/EcommercePurchasesByLocationReport-y2BQfhe5.js","../css/main-monsterinsights-eahFLOfq.css","./chunks/EcommerceSpendByDayReport-CdvuQFug.js","./chunks/EcommerceSpendByHourReport-Di3T2Yaf.js","./chunks/EcommerceRefundsReport-DeCy9BUv.js","./chunks/EcommerceRefundsByGeoReport-Cx39Kj8U.js","./chunks/EcommerceProductFeedReport-J8pJYjsx.js","./chunks/CountriesReport-LDJq4uCM.js","./chunks/buildGaExplorerReportUrl-EaZ84MNO.js","../css/main-monsterinsights-B9O8V_Vm.css","./chunks/PublishersOverviewReport-BDpvyCXL.js","./chunks/ApexBarChart-El9oBk9E.js","../css/main-monsterinsights-BPvLcjwH.css","./chunks/PublishersPagesReport-DkN_jiZF.js","./chunks/CustomEventsReport-BjYBQ5Mb.js","./chunks/UserJourneyReport-Bo70e0c-.js","./chunks/vue-multiselect.esm-DVzdjNub.js"])))=>i.map(i=>d[i]);
import { l as defineStore, I as inject, r as resolveComponent, o as openBlock, c as createElementBlock, F as Fragment, f as renderList, E as createBlock, D as withCtx, a as createBaseVNode, t as toDisplayString, u as unref, s as createCommentVNode, m as computed, C as watch, y as onMounted, J as onUnmounted, A as createTextVNode, i as normalizeClass, K as renderSlot, b as createVNode, j as ref, L as reactive, M as provide, k as getMiGlobal, N as isNetworkAdmin, w as withDirectives, v as vModelText, x as nextTick, O as getMonsterInsightsUrl, P as vModelSelect, d as createApp } from "./chunks/toastStore-CRCNwITM.js";
import { u as useRouter, b as useRoute, d as _sfc_main$9, _ as _sfc_main$c, c as createRouter, a as createWebHashHistory } from "./chunks/TheAppHeader-DEdY-dez.js";
import { _ as _sfc_main$e, i as installOverlays } from "./chunks/AppOverlays-BGer0Qoo.js";
import { _ as __vitePreload, g as getNonce, a as ajaxPost, b as getAjaxUrl, R as REPORTING_REAUTH_ERROR, c as guardReportingConnection, i as isAddonActive, e as ensureBearerToken, d as isReportingConnected, f as isAuthed, h as getAddonBasename, j as getMiGlobal$1, k as isPro, l as isAddonInstalled, m as getAddonsPageUrl, n as getUpgradeUrl, o as getUrl, s as setupPinia } from "./chunks/ajax-B_XS1gT5.js";
import { d as dateIntervals, h as hooks } from "./chunks/dateIntervals-BPoui_3H.js";
import { _ as __$2, s as sprintf } from "./chunks/default-i18n-KrIlCc2E.js";
import { u as useModal, a as useToast, _ as _sfc_main$d } from "./chunks/addons-CSVIjAyY.js";
import { I as Icon } from "./chunks/Icon-Cz1-Vo-r.js";
import { h as html2pdf, _ as _sfc_main$a, u as useAuthGate } from "./chunks/useAuthGate-DCWToggq.js";
import { _ as _sfc_main$b } from "./chunks/Modal-B9mMTzc_.js";
import { _ as _export_sfc } from "./chunks/_plugin-vue_export-helper-1tPrXgE0.js";
import { U as UniversallyPromo } from "./chunks/UniversallyPromo-NH8NC5TQ.js";
import "./chunks/useNotices-BpzNuZJ7.js";
import "./chunks/flatpickr-CNAtgokQ.js";
import "./chunks/useFeatureGate-Ds3Z3eq-.js";
const DEFAULT_ECOMMERCE_FUNNEL = {
  id: "default-ecommerce",
  name: "eCommerce",
  steps: [
    { type: "event", value: "view_item" },
    { type: "event", value: "add_to_cart" },
    { type: "event", value: "purchase" }
  ]
};
function computePreviousPeriod(start, end) {
  if (!start || !end) {
    return { compareStart: "", compareEnd: "" };
  }
  const startM = hooks(start);
  const endM = hooks(end);
  const days = endM.diff(startM, "days") + 1;
  const compareEndM = startM.clone().subtract(1, "days");
  const compareStartM = compareEndM.clone().subtract(days - 1, "days");
  return {
    compareStart: compareStartM.format("YYYY-MM-DD"),
    compareEnd: compareEndM.format("YYYY-MM-DD")
  };
}
const useOverviewReportStore = defineStore("overviewReport", {
  state: () => {
    const last30 = dateIntervals.last30days;
    return {
      // Shared date range state
      dateRange: {
        interval: "last30days",
        start: last30.start.format("YYYY-MM-DD"),
        end: last30.end.format("YYYY-MM-DD"),
        compareStart: last30.compareStart?.format("YYYY-MM-DD") ?? "",
        compareEnd: last30.compareEnd?.format("YYYY-MM-DD") ?? "",
        compareReport: false
      },
      // Pro feature modal
      showProModal: false,
      // True while the upgrade upsell overlay is covering the current report
      // (gated report, not in sample mode). The reports App uses this to blur
      // + disable the shared header toolbar so it matches the blurred report
      // behind the modal (production behavior).
      reportUpsellActive: false,
      // Raw API data from each data source
      marketingCampaigns: null,
      // { campaign, source, medium, term, content }
      pages: null,
      // { landingPage, pageLocation, pageTitle, queryString }
      customDimensions: null,
      // { loggedIn, postType, author, category, tags, focusKeyword, dayOfWeek, seoScore, focusKeyphrase }
      formSubmissions: null,
      // raw form submissions API response
      demographics: null,
      // { country, state, newVsReturning }
      devices: null,
      // { browser, os, size }
      ecommerceOverview: null,
      // { log: { date, sourceMedium, campaign }, data: ecommerce_data }
      // Active filters applied by the user
      activeFilters: [],
      // Array of { type, condition, value }
      activeDevice: "",
      // Device filter (desktop, mobile, tablet)
      chartActiveTab: "traffic",
      // Tab above the chart
      // Funnel data
      funnels: [],
      // Array of saved funnels from DB { id, name, steps: [{ type, value }] }
      activeFunnelId: null
      // Currently selected/applied funnel ID
    };
  },
  getters: {
    /**
     * Whether any filters are currently active.
     */
    hasActiveFilters: (state) => {
      return state.activeFilters.length > 0 || state.activeDevice !== "";
    },
    getChartActiveTab: (state) => {
      return state.chartActiveTab;
    },
    /**
     * Get the currently active funnel object.
     */
    activeFunnel: (state) => {
      if (!state.activeFunnelId) {
        return null;
      }
      return state.funnels.find((f) => f.id === state.activeFunnelId) || null;
    }
  },
  actions: {
    setMarketingCampaigns(data) {
      this.marketingCampaigns = data;
    },
    setPages(data) {
      this.pages = data;
    },
    setCustomDimensions(data) {
      this.customDimensions = data;
    },
    setFormSubmissions(data) {
      this.formSubmissions = data;
    },
    setDemographics(data) {
      this.demographics = data;
    },
    setDevices(data) {
      this.devices = data;
    },
    setEcommerceOverview(data) {
      this.ecommerceOverview = data;
    },
    setActiveFilters(filters, device = "") {
      this.activeFilters = filters;
      this.activeDevice = device;
    },
    clearFilters() {
      this.activeFilters = [];
      this.activeDevice = "";
    },
    setChartActiveTab(tab) {
      this.chartActiveTab = tab;
    },
    setFunnels(funnels) {
      const saved = Array.isArray(funnels) ? funnels.filter((f) => f.id !== DEFAULT_ECOMMERCE_FUNNEL.id) : [];
      this.funnels = [DEFAULT_ECOMMERCE_FUNNEL, ...saved];
      const storedId = localStorage.getItem("mi_active_funnel_id");
      if (storedId && this.funnels.some((f) => String(f.id) === storedId)) {
        this.activeFunnelId = storedId === DEFAULT_ECOMMERCE_FUNNEL.id ? storedId : Number(storedId) || storedId;
      } else if (!this.activeFunnelId || !this.funnels.some((f) => f.id === this.activeFunnelId)) {
        this.activeFunnelId = this.funnels[0].id;
      }
    },
    setActiveFunnelId(id) {
      this.activeFunnelId = id;
      if (id) {
        localStorage.setItem("mi_active_funnel_id", String(id));
      } else {
        localStorage.removeItem("mi_active_funnel_id");
      }
    },
    addFunnel(funnel) {
      this.funnels.push(funnel);
    },
    updateFunnel(funnel) {
      const index = this.funnels.findIndex((f) => f.id === funnel.id);
      if (index !== -1) {
        this.funnels[index] = funnel;
      }
    },
    removeFunnel(funnelId) {
      this.funnels = this.funnels.filter((f) => f.id !== funnelId);
      if (this.activeFunnelId === funnelId) {
        this.setActiveFunnelId(this.funnels.length > 0 ? this.funnels[0].id : null);
      }
    },
    clearAllFunnels() {
      this.funnels = [DEFAULT_ECOMMERCE_FUNNEL];
      this.setActiveFunnelId(DEFAULT_ECOMMERCE_FUNNEL.id);
    },
    /**
     * Update the shared date range.
     * Handles interval presets, compare toggles, and custom ranges.
     */
    updateDateRange(updates) {
      Object.assign(this.dateRange, updates);
      const intervalKey = updates?.interval;
      if (updates?.compareReport !== void 0) {
        this.dateRange.compareReport = !!updates.compareReport;
        if (this.dateRange.compareReport && this.dateRange.start && this.dateRange.end) {
          if (!updates?.compareStart && !updates?.compareEnd) {
            const prev = computePreviousPeriod(this.dateRange.start, this.dateRange.end);
            this.dateRange.compareStart = prev.compareStart;
            this.dateRange.compareEnd = prev.compareEnd;
          }
        } else {
          this.dateRange.compareStart = "";
          this.dateRange.compareEnd = "";
        }
        return;
      }
      if (intervalKey && typeof intervalKey === "string" && dateIntervals[intervalKey]) {
        const interval = dateIntervals[intervalKey];
        if (this.dateRange.compareReport) {
          this.dateRange.compareStart = interval.compareStart?.format("YYYY-MM-DD") ?? "";
          this.dateRange.compareEnd = interval.compareEnd?.format("YYYY-MM-DD") ?? "";
        }
      } else if (intervalKey === false) {
        if (updates?.compareStart === void 0 && updates?.compareEnd === void 0) {
          this.dateRange.compareStart = "";
          this.dateRange.compareEnd = "";
          this.dateRange.compareReport = false;
        }
      } else if (this.dateRange.compareReport && this.dateRange.start && this.dateRange.end && (updates?.start !== void 0 || updates?.end !== void 0) && typeof intervalKey === "string") {
        const prev = computePreviousPeriod(this.dateRange.start, this.dateRange.end);
        this.dateRange.compareStart = prev.compareStart;
        this.dateRange.compareEnd = prev.compareEnd;
      }
    },
    openProModal() {
      this.showProModal = true;
    },
    closeProModal() {
      this.showProModal = false;
    }
  }
});
const OverviewReport = () => __vitePreload(() => import("./chunks/OverviewReport-BjCtcDC9.js"), true ? __vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41]) : void 0, import.meta.url);
const TrafficOverviewReport = () => __vitePreload(() => import("./chunks/TrafficOverviewReport-hZc3xYK7.js"), true ? __vite__mapDeps([42,1,2,43,44,21,16,17,45,46,23,24,31,32,13,14,33,34,35,47,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const TrafficTechnologyReport = () => __vitePreload(() => import("./chunks/TrafficTechnologyReport-B7j79IAt.js"), true ? __vite__mapDeps([54,1,2,43,44,31,32,13,14,33,34,35,16,47,17,23,24,48,27,28,19,20,36,6,37,38,49,55,4,56,8,9,26,39,40,10,11,29,30,57]) : void 0, import.meta.url);
const TrafficLandingPagesReport = () => __vitePreload(() => import("./chunks/TrafficLandingPagesReport-DZHWL3yb.js"), true ? __vite__mapDeps([58,1,2,43,44,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const TrafficCampaignReport = () => __vitePreload(() => import("./chunks/TrafficCampaignReport-RRQtgngn.js"), true ? __vite__mapDeps([59,1,2,43,44,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const TrafficSourceMediumReport = () => __vitePreload(() => import("./chunks/TrafficSourceMediumReport-DSn9-Hhb.js"), true ? __vite__mapDeps([60,1,2,43,44,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const TrafficSocialReport = () => __vitePreload(() => import("./chunks/TrafficSocialReport-DckX_F9r.js"), true ? __vite__mapDeps([61,1,2,43,44,31,32,13,14,33,34,35,16,47,21,17,45,46,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const TrafficAIReport = () => __vitePreload(() => import("./chunks/TrafficAIReport-gLVQG8SZ.js"), true ? __vite__mapDeps([62,1,2,43,44,31,32,13,14,33,34,35,16,47,21,17,45,46,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const FormsReport = () => __vitePreload(() => import("./chunks/FormsReport-CYIHZU3X.js"), true ? __vite__mapDeps([63,1,2,44,31,32,13,14,33,34,35,16,47,21,23,24,46,17,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const ExceptionsReport = () => __vitePreload(() => import("./chunks/ExceptionsReport-BqbrPB7y.js"), true ? __vite__mapDeps([64,1,2,31,32,13,14,33,34,35,16,27,28,19,20,48,36,6,37,38,49,10,11,26,39,40,29,30,65]) : void 0, import.meta.url);
const MediaReport = () => __vitePreload(() => import("./chunks/MediaReport-DVjR8wbG.js"), true ? __vite__mapDeps([66,1,2,44,31,32,13,14,33,34,35,16,47,21,23,24,46,17,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const DimensionsReport = () => __vitePreload(() => import("./chunks/DimensionsReport-DVKG-z4b.js"), true ? __vite__mapDeps([67,1,2,44,16,21,23,24,45,46,31,32,13,14,33,34,35,47,27,28,19,20,48,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const RealtimeReport = () => __vitePreload(() => import("./chunks/RealtimeReport-aG55UKdD.js"), true ? __vite__mapDeps([68,2,1,16,31,32,13,14,33,34,35,27,28,19,20,21,23,24,48,36,6,37,38,49,52,10,11,8,9,18,22,53,3,4,5,7,26,39,40,29,30,69]) : void 0, import.meta.url);
const SearchConsoleReport = () => __vitePreload(() => import("./chunks/SearchConsoleReport-Ca4U4Pfd.js"), true ? __vite__mapDeps([70,1,2,16,31,32,13,14,33,34,35,27,28,19,20,21,23,24,17,48,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,71,72,26,39,40,29,30]) : void 0, import.meta.url);
const SiteSpeedReport = () => __vitePreload(() => import("./chunks/SiteSpeedReport-bvIiCOoJ.js"), true ? __vite__mapDeps([73,2,48,27,28,1,16,19,20,31,32,13,14,33,34,35,36,6,37,38,49,8,9,26,39,40,10,11,29,30]) : void 0, import.meta.url);
const EcommerceOverviewReport = () => __vitePreload(() => import("./chunks/EcommerceOverviewReport-W0_HJibW.js"), true ? __vite__mapDeps([74,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,71,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceCouponsReport = () => __vitePreload(() => import("./chunks/EcommerceCouponsReport-UnBihghQ.js"), true ? __vite__mapDeps([77,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,45,46,23,24,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceCartAbandonmentReport = () => __vitePreload(() => import("./chunks/EcommerceCartAbandonmentReport-CyxzBz21.js"), true ? __vite__mapDeps([78,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceFunnelReport = () => __vitePreload(() => import("./chunks/EcommerceFunnelReport-C10DCbSD.js"), true ? __vite__mapDeps([79,1,2,31,32,13,14,33,34,35,16,76,10,6,11,8,9,25,26,27,28,19,20,48,36,37,38,49,39,40,29,30,80]) : void 0, import.meta.url);
const EcommercePurchasesByLocationReport = () => __vitePreload(() => import("./chunks/EcommercePurchasesByLocationReport-y2BQfhe5.js"), true ? __vite__mapDeps([81,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,45,46,23,24,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30,82]) : void 0, import.meta.url);
const EcommerceSpendByDayReport = () => __vitePreload(() => import("./chunks/EcommerceSpendByDayReport-CdvuQFug.js"), true ? __vite__mapDeps([83,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,46,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,17,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceSpendByHourReport = () => __vitePreload(() => import("./chunks/EcommerceSpendByHourReport-Di3T2Yaf.js"), true ? __vite__mapDeps([84,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,45,46,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,17,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceRefundsReport = () => __vitePreload(() => import("./chunks/EcommerceRefundsReport-DeCy9BUv.js"), true ? __vite__mapDeps([85,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,17,45,46,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceRefundsByGeoReport = () => __vitePreload(() => import("./chunks/EcommerceRefundsByGeoReport-Cx39Kj8U.js"), true ? __vite__mapDeps([86,1,2,75,44,76,31,32,13,14,33,34,35,16,47,21,45,46,23,24,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const EcommerceProductFeedReport = () => __vitePreload(() => import("./chunks/EcommerceProductFeedReport-J8pJYjsx.js"), true ? __vite__mapDeps([87,1,2,31,32,13,14,33,34,35,16,21,23,24,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,17,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const CountriesReport = () => __vitePreload(() => import("./chunks/CountriesReport-LDJq4uCM.js"), true ? __vite__mapDeps([88,1,2,44,31,32,13,14,33,34,35,16,47,17,46,89,45,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,21,51,26,39,40,29,30,90]) : void 0, import.meta.url);
const PublishersOverviewReport = () => __vitePreload(() => import("./chunks/PublishersOverviewReport-BDpvyCXL.js"), true ? __vite__mapDeps([91,1,2,31,32,13,14,33,34,35,16,44,21,89,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,55,4,56,92,5,93,26,39,40,29,30]) : void 0, import.meta.url);
const PublishersPagesReport = () => __vitePreload(() => import("./chunks/PublishersPagesReport-DkN_jiZF.js"), true ? __vite__mapDeps([94,1,2,44,31,32,13,14,33,34,35,16,47,21,23,24,45,46,89,48,27,28,19,20,36,6,37,38,49,52,10,11,8,9,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const CustomEventsReport = () => __vitePreload(() => import("./chunks/CustomEventsReport-BjYBQ5Mb.js"), true ? __vite__mapDeps([95,1,2,44,31,32,13,14,33,34,35,16,47,17,46,21,45,48,27,28,19,20,36,6,37,38,49,50,3,4,5,7,8,9,10,11,12,15,51,52,18,22,53,26,39,40,29,30]) : void 0, import.meta.url);
const UserJourneyReport = () => __vitePreload(() => import("./chunks/UserJourneyReport-Bo70e0c-.js"), true ? __vite__mapDeps([96,48,2,27,28,1,16,19,20,31,32,13,14,33,34,35,36,6,37,38,49,97,26,39,40,10,11,29,30]) : void 0, import.meta.url);
const routes = [
  {
    path: "/",
    name: "overview-report",
    component: OverviewReport,
    meta: {
      title: "Overview Report",
      reportType: "overview",
      requiresAuth: true
    }
  },
  // Traffic reports
  {
    path: "/traffic-overview",
    name: "traffic-overview",
    component: TrafficOverviewReport,
    meta: {
      title: "Traffic Overview",
      reportType: "traffic_overview",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-technology",
    name: "traffic-technology",
    component: TrafficTechnologyReport,
    meta: {
      title: "Technology",
      reportType: "traffic_technology",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-landing-pages",
    name: "traffic-landing-pages",
    component: TrafficLandingPagesReport,
    meta: {
      title: "Landing Pages",
      reportType: "traffic_landing_pages",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-campaign",
    name: "traffic-campaign",
    component: TrafficCampaignReport,
    meta: {
      title: "Campaigns",
      reportType: "traffic_campaign",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-source-medium",
    name: "traffic-source-medium",
    component: TrafficSourceMediumReport,
    meta: {
      title: "Source / Medium",
      reportType: "traffic_source_medium",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-social",
    name: "traffic-social",
    component: TrafficSocialReport,
    meta: {
      title: "Social Traffic",
      reportType: "traffic_social",
      requiresAuth: true
    }
  },
  {
    path: "/traffic-ai",
    name: "traffic-ai",
    component: TrafficAIReport,
    meta: {
      title: "AI Traffic",
      reportType: "traffic_ai",
      requiresAuth: true
    }
  },
  // eCommerce reports
  {
    path: "/ecommerce",
    name: "ecommerce-overview",
    component: EcommerceOverviewReport,
    meta: {
      title: "eCommerce Overview",
      reportType: "ecommerce",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-coupons",
    name: "ecommerce-coupons",
    component: EcommerceCouponsReport,
    meta: {
      title: "Coupons",
      reportType: "ecommerce_coupons",
      requiresAuth: true
    }
  },
  {
    path: "/cart-abandonment",
    name: "cart-abandonment",
    component: EcommerceCartAbandonmentReport,
    meta: {
      title: "Cart Abandonment",
      reportType: "cart_abandonment",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-funnel",
    name: "ecommerce-funnel",
    component: EcommerceFunnelReport,
    meta: {
      title: "eCommerce Funnel",
      reportType: "ecommerce_funnel",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-purchases-by-location",
    name: "ecommerce-purchases-by-location",
    component: EcommercePurchasesByLocationReport,
    meta: {
      title: "Purchases by Location",
      reportType: "ecommerce_purchases_by_location",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-spend-by-day",
    name: "ecommerce-spend-by-day",
    component: EcommerceSpendByDayReport,
    meta: {
      title: "Spend by Day",
      reportType: "ecommerce_spend_by_day",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-spend-by-hour",
    name: "ecommerce-spend-by-hour",
    component: EcommerceSpendByHourReport,
    meta: {
      title: "Spend by Hour",
      reportType: "ecommerce_spend_by_hour",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-refunds",
    name: "ecommerce-refunds",
    component: EcommerceRefundsReport,
    meta: {
      title: "Refunds",
      reportType: "ecommerce_refunds",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-refunds-by-geo",
    name: "ecommerce-refunds-by-geo",
    component: EcommerceRefundsByGeoReport,
    meta: {
      title: "Refunds by Geography",
      reportType: "ecommerce_refunds_by_geo",
      requiresAuth: true
    }
  },
  {
    path: "/ecommerce-product-feed",
    name: "ecommerce-product-feed",
    component: EcommerceProductFeedReport,
    meta: {
      title: "Product Feed",
      reportType: "ecommerce_product_feed",
      requiresAuth: true
    }
  },
  {
    path: "/forms",
    name: "forms",
    component: FormsReport,
    meta: {
      title: "Forms",
      reportType: "forms",
      requiresAuth: true
    }
  },
  {
    path: "/countries",
    name: "countries",
    component: CountriesReport,
    meta: {
      title: "Country Report",
      reportType: "countries",
      requiresAuth: true
    }
  },
  {
    path: "/exceptions",
    name: "exceptions",
    component: ExceptionsReport,
    meta: {
      title: "Exceptions",
      reportType: "exceptions",
      requiresAuth: true
    }
  },
  {
    path: "/publishers",
    name: "publishers-overview",
    component: PublishersOverviewReport,
    meta: {
      title: "Publishers",
      reportType: "publisher",
      requiresAuth: true
    }
  },
  {
    path: "/media",
    name: "media",
    component: MediaReport,
    meta: {
      title: "Media",
      reportType: "media",
      requiresAuth: true
    }
  },
  {
    path: "/publishers-pages",
    name: "publishers-pages",
    component: PublishersPagesReport,
    meta: {
      title: "Pages Report",
      reportType: "engagement_pages",
      requiresAuth: true
    }
  },
  {
    path: "/dimensions",
    name: "dimensions",
    component: DimensionsReport,
    meta: {
      title: "Dimensions",
      reportType: "dimensions",
      requiresAuth: true
    }
  },
  {
    path: "/real-time",
    name: "realtime",
    component: RealtimeReport,
    meta: {
      title: "Realtime",
      reportType: "realtime",
      requiresAuth: true,
      // Live data has no date range or dimension filters to choose.
      hideDateControls: true
    }
  },
  {
    path: "/search-console",
    name: "search-console",
    component: SearchConsoleReport,
    meta: {
      title: "Search Console",
      reportType: "search_console",
      requiresAuth: true
    }
  },
  {
    path: "/site-speed",
    name: "site-speed",
    component: SiteSpeedReport,
    meta: {
      title: "Site Speed",
      reportType: "site_speed",
      requiresAuth: true,
      // Point-in-time audit; no date range or dimension filters apply.
      hideDateControls: true
    }
  },
  {
    path: "/custom-events",
    name: "custom-events",
    component: CustomEventsReport,
    meta: {
      title: "Custom Events",
      reportType: "custom_events",
      requiresAuth: true
    }
  },
  {
    path: "/user-journey-report",
    name: "user-journey-report",
    component: UserJourneyReport,
    meta: {
      title: "User Journey Report",
      reportType: "user_journey",
      requiresAuth: true
    }
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/"
  }
];
const _hoisted_1$8 = {
  key: 0,
  class: "submenu"
};
const _hoisted_2$8 = { class: "submenu_title" };
const _hoisted_3$7 = { class: "submenu_text" };
const _hoisted_4$6 = ["href"];
const _hoisted_5$5 = { class: "submenu_title" };
const _hoisted_6$4 = { class: "submenu_text" };
const _sfc_main$8 = {
  __name: "ReportNavigationSubmenu",
  props: {
    menuId: {
      type: String,
      required: true
    },
    items: {
      type: Array,
      required: true
    },
    submenuIndex: {
      type: Number,
      required: true
    }
  },
  setup(__props) {
    const props = __props;
    const sharedState = inject("sharedState");
    const router2 = useRouter();
    const reportsPageSlug = "monsterinsights_reports";
    const reportsBaseUrl = `admin.php?page=${reportsPageSlug}#`;
    const isActive = computed(() => {
      return sharedState.active === props.submenuIndex;
    });
    function isVue3Route(path) {
      if (!path) return false;
      const resolved = router2.resolve(path);
      return resolved.name && resolved.name !== "overview-report" && !resolved.redirectedFrom;
    }
    function getFullUrl(path) {
      return reportsBaseUrl + path;
    }
    return (_ctx, _cache) => {
      const _component_router_link = resolveComponent("router-link");
      return isActive.value ? (openBlock(), createElementBlock("ul", _hoisted_1$8, [
        (openBlock(true), createElementBlock(Fragment, null, renderList(__props.items, (item, itemIndex) => {
          return openBlock(), createElementBlock("li", {
            key: __props.menuId + itemIndex
          }, [
            isVue3Route(item.to) ? (openBlock(), createBlock(_component_router_link, {
              key: 0,
              to: item.to,
              onClick: _cache[0] || (_cache[0] = ($event) => unref(sharedState).active = null)
            }, {
              default: withCtx(() => [
                createBaseVNode("span", _hoisted_2$8, toDisplayString(item.label), 1),
                createBaseVNode("span", _hoisted_3$7, toDisplayString(item.description), 1)
              ]),
              _: 2
            }, 1032, ["to"])) : (openBlock(), createElementBlock("a", {
              key: 1,
              href: getFullUrl(item.to)
            }, [
              createBaseVNode("span", _hoisted_5$5, toDisplayString(item.label), 1),
              createBaseVNode("span", _hoisted_6$4, toDisplayString(item.description), 1)
            ], 8, _hoisted_4$6))
          ]);
        }), 128))
      ])) : createCommentVNode("", true);
    };
  }
};
const _hoisted_1$7 = ["href"];
const _hoisted_2$7 = ["onClick"];
const _sfc_main$7 = {
  __name: "ReportNavigationMenu",
  props: {
    menuId: {
      type: String,
      required: true
    },
    menuData: {
      type: Array,
      required: true
    },
    navClass: {
      type: String,
      default: ""
    }
  },
  setup(__props) {
    const menuRef = ref(null);
    const router2 = useRouter();
    const route = useRoute();
    const reportsPageSlug = "monsterinsights_reports";
    const reportsBaseUrl = `admin.php?page=${reportsPageSlug}#`;
    const sharedState = reactive({
      active: null
    });
    provide("sharedState", sharedState);
    function getFullUrl(path) {
      return reportsBaseUrl + path;
    }
    function isVue3Route(path) {
      if (!path) return false;
      const resolved = router2.resolve(path);
      return !!resolved.name && !resolved.redirectedFrom;
    }
    function hasActiveChild(children) {
      if (children.length === 0) {
        return false;
      }
      return children.some((child) => child.to === route.path);
    }
    function itemClasses(item) {
      if (hasActiveChild(item.children)) {
        return "active";
      }
      return "";
    }
    function menuToggle(index) {
      if (sharedState.active !== index) {
        sharedState.active = index;
      } else {
        sharedState.active = null;
      }
    }
    watch(() => route.path, () => {
      sharedState.active = null;
    });
    function closeMenu() {
      sharedState.active = null;
    }
    function handleClickOutside(event) {
      if (menuRef.value && !menuRef.value.contains(event.target)) {
        closeMenu();
      }
    }
    onMounted(() => {
      document.addEventListener("click", handleClickOutside);
    });
    onUnmounted(() => {
      document.removeEventListener("click", handleClickOutside);
    });
    return (_ctx, _cache) => {
      const _component_router_link = resolveComponent("router-link");
      return openBlock(), createElementBlock("div", {
        ref_key: "menuRef",
        ref: menuRef
      }, [
        createBaseVNode("ul", {
          class: normalizeClass(__props.navClass)
        }, [
          (openBlock(true), createElementBlock(Fragment, null, renderList(__props.menuData, (item, index) => {
            return openBlock(), createElementBlock("li", {
              key: __props.menuId + index
            }, [
              item.children.length === 0 && isVue3Route(item.to) ? (openBlock(), createBlock(_component_router_link, {
                key: 0,
                to: item.to,
                class: normalizeClass(item.class),
                onClick: closeMenu
              }, {
                default: withCtx(() => [
                  createTextVNode(toDisplayString(item.label), 1)
                ]),
                _: 2
              }, 1032, ["to", "class"])) : item.children.length === 0 ? (openBlock(), createElementBlock("a", {
                key: 1,
                href: getFullUrl(item.to),
                class: normalizeClass(item.class)
              }, toDisplayString(item.label), 11, _hoisted_1$7)) : (openBlock(), createElementBlock("div", {
                key: 2,
                class: normalizeClass(itemClasses(item)),
                onClick: ($event) => menuToggle(index)
              }, [
                renderSlot(_ctx.$slots, "menuToggler", {}, () => [
                  createBaseVNode("button", null, [
                    createTextVNode(toDisplayString(item.label) + " ", 1),
                    _cache[0] || (_cache[0] = createBaseVNode("span", { class: "caret" }, [
                      createBaseVNode("svg", {
                        width: "10",
                        height: "6",
                        viewBox: "0 0 10 6",
                        fill: "none",
                        xmlns: "http://www.w3.org/2000/svg"
                      }, [
                        createBaseVNode("path", {
                          d: "M9 1L5 5L1 1",
                          stroke: "#8EA4B4",
                          "stroke-width": "2",
                          "stroke-linecap": "round",
                          "stroke-linejoin": "round"
                        })
                      ])
                    ], -1))
                  ])
                ]),
                createVNode(_sfc_main$8, {
                  items: item.children,
                  "menu-id": __props.menuId,
                  "submenu-index": index
                }, null, 8, ["items", "menu-id", "submenu-index"])
              ], 10, _hoisted_2$7))
            ]);
          }), 128))
        ], 2)
      ], 512);
    };
  }
};
const { __: __$1 } = wp.i18n;
function getMenuData() {
  const baseMenu = [
    {
      id: "overview",
      label: __$1("Overview", "google-analytics-for-wordpress"),
      // Point at the real Vue 3 overview route ('/') so it renders as a
      // <router-link> and Vue Router toggles `router-link-exact-active`
      // itself — only when actually on the Overview page. The old static
      // `router-link-exact-active` class kept Overview lit on every report.
      to: "/",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "traffic",
      label: __$1("Traffic", "google-analytics-for-wordpress"),
      children: [
        {
          label: __$1("Overview", "google-analytics-for-wordpress"),
          to: "/traffic-overview",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See how customers find your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Technology", "google-analytics-for-wordpress"),
          to: "/traffic-technology",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("Uncover the devices and browsers your visitors are utilizing.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Landing Page Details", "google-analytics-for-wordpress"),
          to: "/traffic-landing-pages",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See the first page visitors land when visiting your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Campaigns", "google-analytics-for-wordpress"),
          to: "/traffic-campaign",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("Easily measure the effectiveness of your marketing efforts.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Source / Medium", "google-analytics-for-wordpress"),
          to: "/traffic-source-medium",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("Details about referring traffic to your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Social", "google-analytics-for-wordpress"),
          to: "/traffic-social",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("Details about social traffic to your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("AI Traffic", "google-analytics-for-wordpress"),
          to: "/traffic-ai",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See AI Tool Traffic Stats.", "google-analytics-for-wordpress")
        }
      ],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "Publishers",
      label: __$1("Publishers", "google-analytics-for-wordpress"),
      children: [
        {
          label: __$1("Overview", "google-analytics-for-wordpress"),
          to: "/publishers",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See how visitors interact with your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Pages Report", "google-analytics-for-wordpress"),
          to: "/publishers-pages",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("The most popular pages on your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Country Report", "google-analytics-for-wordpress"),
          to: "/countries",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which countries your visitors come from.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Events", "google-analytics-for-wordpress"),
          to: "/custom-events",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See your custom events and performance", "google-analytics-for-wordpress")
        }
      ],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "search-console",
      label: __$1("Search Console", "google-analytics-for-wordpress"),
      to: "/search-console",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "ecommerce",
      label: __$1("eCommerce", "google-analytics-for-wordpress"),
      children: [
        {
          label: __$1("Overview", "google-analytics-for-wordpress"),
          to: "/ecommerce",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See how your store is performing.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Coupons", "google-analytics-for-wordpress"),
          to: "/ecommerce-coupons",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See the coupons and discounts being used on your website.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Cart Abandonment", "google-analytics-for-wordpress"),
          to: "/cart-abandonment",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which products are abandoned the most.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Funnel", "google-analytics-for-wordpress"),
          to: "/ecommerce-funnel",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("Visually measure how customers convert in your store.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Orders by Location", "google-analytics-for-wordpress"),
          to: "/ecommerce-purchases-by-location",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which cities and countries make up your store's sales.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("User Journeys", "google-analytics-for-wordpress"),
          to: "/user-journey-report",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See every step your visitors take with User Journeys.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Spend by Day", "google-analytics-for-wordpress"),
          to: "/ecommerce-spend-by-day",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which days are most profitable for your store.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Spend by Hour", "google-analytics-for-wordpress"),
          to: "/ecommerce-spend-by-hour",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which hours are most profitable for your store.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Refunds", "google-analytics-for-wordpress"),
          to: "/ecommerce-refunds",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which products are most frequently refunded.", "google-analytics-for-wordpress")
        },
        {
          label: __$1("Refunds by Geo", "google-analytics-for-wordpress"),
          to: "/ecommerce-refunds-by-geo",
          children: [],
          class: "monsterinsights-navigation-submenu-link",
          description: __$1("See which cities and countries make up your store's refunds.", "google-analytics-for-wordpress")
        }
      ],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "dimensions",
      label: __$1("Dimensions", "google-analytics-for-wordpress"),
      to: "/dimensions",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "forms",
      label: __$1("Forms", "google-analytics-for-wordpress"),
      to: "/forms",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "realtime",
      label: __$1("Realtime", "google-analytics-for-wordpress"),
      to: "/real-time",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "site-speed",
      label: __$1("Site Speed", "google-analytics-for-wordpress"),
      to: "/site-speed",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "media",
      label: __$1("Media", "google-analytics-for-wordpress"),
      to: "/media",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    },
    {
      id: "exceptions",
      label: __$1("Exceptions", "google-analytics-for-wordpress"),
      to: "/exceptions",
      children: [],
      class: "monsterinsights-navigation-tab-link"
    }
  ];
  getMiGlobal("woo_product_feed");
  isNetworkAdmin() ? getMiGlobal("license_network", {}).type : getMiGlobal("license", {}).type;
  return baseMenu;
}
const _hoisted_1$6 = { class: "monsterinsights-navigation-bar" };
const _hoisted_2$6 = { class: "monsterinsights-container" };
const _hoisted_3$6 = {
  key: 0,
  class: "monsterinsights-route-title"
};
const _sfc_main$6 = {
  __name: "ReportsNavigation",
  setup(__props) {
    const menuData = getMenuData();
    const navOpen = ref(false);
    const routeTitle = computed(() => {
      return "";
    });
    const navClass = computed(() => {
      let cls = "monsterinsights-main-navigation monsterinsights-reports-navigation";
      if (navOpen.value) {
        cls += " monsterinsights-main-navigation-open";
      }
      return cls;
    });
    const buttonIconClass = computed(() => {
      let cls = "monstericon-arrow";
      if (navOpen.value) {
        cls += " monstericon-down";
      }
      return cls;
    });
    const triggerClass = computed(() => {
      let cls = "monsterinsights-mobile-nav-trigger";
      if (navOpen.value) {
        cls += " monsterinsights-mobile-nav-trigger-open";
      }
      return cls;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1$6, [
        createBaseVNode("div", _hoisted_2$6, [
          createBaseVNode("nav", null, [
            createBaseVNode("button", {
              class: normalizeClass(triggerClass.value),
              onClick: _cache[0] || (_cache[0] = ($event) => navOpen.value = !navOpen.value)
            }, [
              routeTitle.value ? (openBlock(), createElementBlock("span", _hoisted_3$6, toDisplayString(routeTitle.value), 1)) : createCommentVNode("", true),
              createBaseVNode("i", {
                class: normalizeClass(buttonIconClass.value)
              }, null, 2)
            ], 2),
            createVNode(_sfc_main$7, {
              "menu-id": "monsterinsights-top-menu",
              "menu-data": unref(menuData),
              "nav-class": navClass.value
            }, null, 8, ["menu-data", "nav-class"])
          ])
        ])
      ]);
    };
  }
};
const _hoisted_1$5 = {
  class: "monsterinsights-download-dropdown",
  "data-html2canvas-ignore": "true"
};
const _hoisted_2$5 = {
  key: 0,
  class: "monsterinsights-download-dropdown__menu"
};
const _hoisted_3$5 = ["disabled"];
const _hoisted_4$5 = ["disabled"];
const _hoisted_5$4 = ["disabled"];
const PDF_CONTENT_WIDTH = 1e3;
const _sfc_main$5 = {
  __name: "ExportDropdown",
  props: {
    reportContainer: {
      type: String,
      default: ".monsterinsights-reports-page"
    },
    filename: {
      type: String,
      default: "monsterinsights-report.pdf"
    },
    showCsv: {
      type: Boolean,
      default: true
    },
    showExcel: {
      type: Boolean,
      default: true
    }
  },
  setup(__props) {
    const props = __props;
    const route = useRoute();
    const reportType = computed(() => route.meta?.reportType || "");
    const isExceptionsReport = computed(() => reportType.value === "exceptions");
    const overviewStore = useOverviewReportStore();
    const { showSuccessModal, showErrorModal, showLoadingModal, closeModal } = useModal();
    const isOpen = ref(false);
    const isExportingPdf = ref(false);
    const isExportingSpreadsheet = ref(false);
    const vClickOutside = {
      mounted(el, binding) {
        el._clickOutside = (event) => {
          if (!(el === event.target || el.contains(event.target))) {
            binding.value(event);
          }
        };
        document.body.addEventListener("click", el._clickOutside);
      },
      unmounted(el) {
        document.body.removeEventListener("click", el._clickOutside);
      }
    };
    function toggle() {
      {
        overviewStore.openProModal();
        return;
      }
    }
    function close() {
      isOpen.value = false;
    }
    async function exportPdf() {
      if (isExportingPdf.value) return;
      const report = document.querySelector(props.reportContainer);
      if (!report) {
        showErrorModal({
          title: __$2("Export failed", "google-analytics-for-wordpress"),
          message: __$2("Error: Report container not found.", "google-analytics-for-wordpress")
        });
        return;
      }
      isExportingPdf.value = true;
      isOpen.value = false;
      document.body.classList.add("monsterinsights-downloading-pdf-report");
      await new Promise((resolve) => setTimeout(resolve, 500));
      const opt = {
        margin: [10, 10, 10, 10],
        filename: props.filename,
        image: { type: "jpeg", quality: 0.98 },
        enableLinks: false,
        html2canvas: {
          scale: 2,
          useCORS: true,
          scrollX: 0,
          scrollY: 0,
          onclone: (_doc, clone) => {
            clone.style.width = `${PDF_CONTENT_WIDTH}px`;
            clone.style.maxWidth = `${PDF_CONTENT_WIDTH}px`;
            clone.style.minWidth = `${PDF_CONTENT_WIDTH}px`;
            clone.style.overflow = "visible";
            clone.querySelectorAll('[data-html2canvas-ignore="true"]').forEach((el) => {
              el.style.display = "none";
            });
            clone.querySelectorAll(".monsterinsights-widget, .monsterinsights-widget-display").forEach((el) => {
              el.style.maxWidth = "100%";
              el.style.overflow = "hidden";
            });
            clone.querySelectorAll("canvas, svg, .chart-container, .chartjs-render-monitor").forEach((el) => {
              el.style.maxWidth = "100%";
            });
          }
        },
        jsPDF: { unit: "mm", format: [210, 297], orientation: "portrait" }
      };
      try {
        const worker = html2pdf().set(opt).from(report);
        const pdf = await worker.toPdf().get("pdf");
        const totalPages = pdf.internal.getNumberOfPages();
        for (let i = 1; i <= totalPages; i++) {
          pdf.setPage(i);
          pdf.setFontSize(8);
          pdf.text(
            sprintf(__$2("Page %1$d of %2$d", "google-analytics-for-wordpress"), i, totalPages),
            105,
            287,
            { align: "center" }
          );
        }
        pdf.save(props.filename);
        showSuccessModal({
          title: __$2("Downloaded PDF report successfully!", "google-analytics-for-wordpress"),
          confirmButtonText: __$2("Ok", "google-analytics-for-wordpress")
        });
      } catch (error) {
        console.error("Failed to generate PDF:", error);
        showErrorModal({
          title: __$2("Export failed", "google-analytics-for-wordpress"),
          message: __$2("Failed to generate PDF. See console for details.", "google-analytics-for-wordpress")
        });
      } finally {
        document.body.classList.remove("monsterinsights-downloading-pdf-report");
        isExportingPdf.value = false;
      }
    }
    function buildExportFilters() {
      const conditions = [];
      for (const filter of overviewStore.activeFilters) {
        if (!filter.type || !filter.value) continue;
        conditions.push({
          field: filter.type,
          type: "dimension",
          match: filter.condition === "is_not" ? "not_equal" : "exact",
          value: String(filter.value).trim(),
          caseSensitive: false
        });
      }
      if (overviewStore.activeDevice) {
        conditions.push({
          field: "deviceCategory",
          type: "dimension",
          match: "exact",
          value: overviewStore.activeDevice,
          caseSensitive: false
        });
      }
      if (conditions.length === 0) return null;
      return { operator: "and", conditions };
    }
    async function exportExceptionsCsv() {
      isExportingSpreadsheet.value = true;
      isOpen.value = false;
      showLoadingModal({
        title: __$2("Generating CSV File", "google-analytics-for-wordpress"),
        message: __$2("Gathering data to export into CSV", "google-analytics-for-wordpress")
      });
      try {
        const formData = new FormData();
        formData.set("action", "monsterinsights_exceptions_report_csv");
        formData.set("nonce", getNonce());
        formData.set("start", overviewStore.dateRange.start);
        formData.set("end", overviewStore.dateRange.end);
        const response = await fetch(getAjaxUrl(), {
          method: "POST",
          body: formData
        });
        if (!response.ok) {
          throw new Error(`${response.status} ${response.statusText}`);
        }
        const disposition = response.headers.get("content-disposition") || "";
        const match = disposition.match(/filename="?([^";]+)"?/);
        const filename = match ? match[1] : `exceptions-report-${overviewStore.dateRange.start}-to-${overviewStore.dateRange.end}.csv`;
        const blob = await response.blob();
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement("a");
        link.href = url;
        link.setAttribute("download", filename);
        document.body.appendChild(link);
        link.click();
        link.remove();
        window.URL.revokeObjectURL(url);
        closeModal();
      } catch (error) {
        closeModal();
        showErrorModal({
          title: __$2("Export Failed", "google-analytics-for-wordpress"),
          message: error.message || __$2("Failed to create export. Please try again.", "google-analytics-for-wordpress")
        });
      } finally {
        isExportingSpreadsheet.value = false;
      }
    }
    async function exportSpreadsheet(format) {
      if (!reportType.value) return;
      if (isExportingSpreadsheet.value) return;
      if (isExceptionsReport.value && format === "csv") {
        await exportExceptionsCsv();
        return;
      }
      isExportingSpreadsheet.value = true;
      isOpen.value = false;
      showLoadingModal({
        title: __$2("Creating export...", "google-analytics-for-wordpress")
      });
      try {
        const formData = new FormData();
        formData.set("action", "monsterinsights_export_report");
        formData.set("nonce", getNonce());
        formData.set("report_type", reportType.value);
        formData.set("start_date", overviewStore.dateRange.start);
        formData.set("end_date", overviewStore.dateRange.end);
        formData.set("format", format);
        const filters = buildExportFilters();
        if (filters) {
          formData.set("filters", JSON.stringify(filters));
        }
        const response = await ajaxPost(formData);
        closeModal();
        if (response.success) {
          showSuccessModal({
            title: __$2("Export Started", "google-analytics-for-wordpress"),
            message: response.data?.message || __$2("Your export is being processed. You will receive a notification when it is ready.", "google-analytics-for-wordpress")
          });
        } else {
          throw new Error(response.data?.message || "Export failed");
        }
      } catch (error) {
        closeModal();
        showErrorModal({
          title: __$2("Export Failed", "google-analytics-for-wordpress"),
          message: error.message || __$2("Failed to create export. Please try again.", "google-analytics-for-wordpress")
        });
      } finally {
        isExportingSpreadsheet.value = false;
      }
    }
    return (_ctx, _cache) => {
      return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$5, [
        createBaseVNode("button", {
          type: "button",
          class: "monsterinsights-header-btn monsterinsights-header-btn--download",
          onClick: toggle
        }, [
          createVNode(Icon, {
            name: "download",
            size: 20
          }),
          createVNode(Icon, {
            name: "chevron-down",
            size: 16
          })
        ]),
        isOpen.value ? (openBlock(), createElementBlock("div", _hoisted_2$5, [
          createBaseVNode("button", {
            type: "button",
            class: "monsterinsights-download-dropdown__item",
            disabled: isExportingPdf.value,
            onClick: exportPdf
          }, [
            createVNode(Icon, {
              name: "download",
              size: 16
            }),
            createBaseVNode("span", null, toDisplayString(isExportingPdf.value ? unref(__$2)("Exporting...", "google-analytics-for-wordpress") : unref(__$2)("Export PDF Report", "google-analytics-for-wordpress")), 1)
          ], 8, _hoisted_3$5),
          __props.showCsv ? (openBlock(), createElementBlock("button", {
            key: 0,
            type: "button",
            class: "monsterinsights-download-dropdown__item",
            disabled: isExportingSpreadsheet.value,
            onClick: _cache[0] || (_cache[0] = ($event) => exportSpreadsheet("csv"))
          }, [
            createVNode(Icon, {
              name: "download",
              size: 16
            }),
            createBaseVNode("span", null, toDisplayString(unref(__$2)("Export CSV", "google-analytics-for-wordpress")), 1)
          ], 8, _hoisted_4$5)) : createCommentVNode("", true),
          __props.showExcel && !isExceptionsReport.value ? (openBlock(), createElementBlock("button", {
            key: 1,
            type: "button",
            class: "monsterinsights-download-dropdown__item",
            disabled: isExportingSpreadsheet.value,
            onClick: _cache[1] || (_cache[1] = ($event) => exportSpreadsheet("excel"))
          }, [
            createVNode(Icon, {
              name: "download",
              size: 16
            }),
            createBaseVNode("span", null, toDisplayString(unref(__$2)("Export Excel", "google-analytics-for-wordpress")), 1)
          ], 8, _hoisted_5$4)) : createCommentVNode("", true)
        ])) : createCommentVNode("", true)
      ])), [
        [vClickOutside, close]
      ]);
    };
  }
};
const _hoisted_1$4 = ["disabled", "aria-expanded"];
const _hoisted_2$4 = {
  key: 0,
  class: "monsterinsights-searchable-select__dropdown",
  role: "listbox"
};
const _hoisted_3$4 = { class: "monsterinsights-searchable-select__search-wrapper" };
const _hoisted_4$4 = ["placeholder"];
const _hoisted_5$3 = ["aria-selected", "onClick", "onMouseenter"];
const _hoisted_6$3 = {
  key: 0,
  class: "monsterinsights-searchable-select__no-results"
};
const _sfc_main$4 = {
  __name: "SearchableSelect",
  props: {
    modelValue: {
      type: String,
      default: ""
    },
    options: {
      type: Array,
      default: () => []
    },
    disabled: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: ""
    },
    searchPlaceholder: {
      type: String,
      default: ""
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const containerRef = ref(null);
    const searchInputRef = ref(null);
    const optionsRef = ref(null);
    const isOpen = ref(false);
    const searchQuery = ref("");
    const highlightedIndex = ref(0);
    const displayLabel = computed(() => {
      if (!props.modelValue) {
        return props.placeholder || __$2("Select...", "google-analytics-for-wordpress");
      }
      const found = props.options.find((opt) => opt.value === props.modelValue);
      return found ? found.label : props.modelValue;
    });
    const filteredOptions = computed(() => {
      if (!searchQuery.value) return props.options;
      const query = searchQuery.value.toLowerCase();
      return props.options.filter(
        (opt) => opt.label.toLowerCase().includes(query) || opt.value.toLowerCase().includes(query)
      );
    });
    watch(searchQuery, () => {
      highlightedIndex.value = 0;
    });
    function toggleDropdown() {
      if (props.disabled) return;
      isOpen.value = !isOpen.value;
      if (isOpen.value) {
        searchQuery.value = "";
        highlightedIndex.value = 0;
        nextTick(() => {
          searchInputRef.value?.focus();
        });
      }
    }
    function closeDropdown() {
      isOpen.value = false;
      searchQuery.value = "";
    }
    function selectOption(opt) {
      emit("update:modelValue", opt.value);
      closeDropdown();
    }
    function handleSearchKeydown(event) {
      const opts = filteredOptions.value;
      switch (event.key) {
        case "ArrowDown":
          event.preventDefault();
          highlightedIndex.value = Math.min(highlightedIndex.value + 1, opts.length - 1);
          scrollHighlightedIntoView();
          break;
        case "ArrowUp":
          event.preventDefault();
          highlightedIndex.value = Math.max(highlightedIndex.value - 1, 0);
          scrollHighlightedIntoView();
          break;
        case "Enter":
          event.preventDefault();
          if (opts[highlightedIndex.value]) {
            selectOption(opts[highlightedIndex.value]);
          }
          break;
        case "Escape":
          event.preventDefault();
          event.stopPropagation();
          closeDropdown();
          break;
      }
    }
    function scrollHighlightedIntoView() {
      nextTick(() => {
        const container = optionsRef.value;
        if (!container) return;
        const highlighted = container.children[highlightedIndex.value];
        if (highlighted) {
          highlighted.scrollIntoView({ block: "nearest" });
        }
      });
    }
    function handleClickOutside(event) {
      if (containerRef.value && !containerRef.value.contains(event.target)) {
        closeDropdown();
      }
    }
    onMounted(() => {
      document.addEventListener("mousedown", handleClickOutside);
    });
    onUnmounted(() => {
      document.removeEventListener("mousedown", handleClickOutside);
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        ref_key: "containerRef",
        ref: containerRef,
        class: normalizeClass(["monsterinsights-searchable-select", {
          "monsterinsights-searchable-select--open": isOpen.value,
          "monsterinsights-searchable-select--disabled": __props.disabled
        }])
      }, [
        createBaseVNode("button", {
          type: "button",
          class: "monsterinsights-searchable-select__trigger",
          disabled: __props.disabled,
          "aria-expanded": isOpen.value,
          "aria-haspopup": "listbox",
          onClick: toggleDropdown
        }, [
          createBaseVNode("span", {
            class: normalizeClass(["monsterinsights-searchable-select__value", { "monsterinsights-searchable-select__value--placeholder": !__props.modelValue }])
          }, toDisplayString(displayLabel.value), 3),
          createVNode(Icon, {
            name: "chevron-down",
            size: 16
          })
        ], 8, _hoisted_1$4),
        isOpen.value ? (openBlock(), createElementBlock("div", _hoisted_2$4, [
          createBaseVNode("div", _hoisted_3$4, [
            createVNode(Icon, {
              name: "search",
              size: 16
            }),
            withDirectives(createBaseVNode("input", {
              ref_key: "searchInputRef",
              ref: searchInputRef,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchQuery.value = $event),
              type: "text",
              class: "monsterinsights-searchable-select__search",
              placeholder: __props.searchPlaceholder || unref(__$2)("Search...", "google-analytics-for-wordpress"),
              onKeydown: handleSearchKeydown
            }, null, 40, _hoisted_4$4), [
              [vModelText, searchQuery.value]
            ])
          ]),
          createBaseVNode("div", {
            class: "monsterinsights-searchable-select__options",
            ref_key: "optionsRef",
            ref: optionsRef
          }, [
            (openBlock(true), createElementBlock(Fragment, null, renderList(filteredOptions.value, (opt, idx) => {
              return openBlock(), createElementBlock("button", {
                key: opt.value,
                type: "button",
                class: normalizeClass(["monsterinsights-searchable-select__option", {
                  "monsterinsights-searchable-select__option--highlighted": idx === highlightedIndex.value,
                  "monsterinsights-searchable-select__option--selected": opt.value === __props.modelValue
                }]),
                role: "option",
                "aria-selected": opt.value === __props.modelValue,
                onClick: ($event) => selectOption(opt),
                onMouseenter: ($event) => highlightedIndex.value = idx
              }, toDisplayString(opt.label), 43, _hoisted_5$3);
            }), 128)),
            filteredOptions.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_6$3, toDisplayString(unref(__$2)("No results found", "google-analytics-for-wordpress")), 1)) : createCommentVNode("", true)
          ], 512)
        ])) : createCommentVNode("", true)
      ], 2);
    };
  }
};
const REGISTRY_KEY = "mi_cache_registry";
const CACHE_TTL = 3600;
function isReAuthError(err) {
  const msg = String(err?.message || err || "").toLowerCase();
  return msg.includes("invalid_grant") || msg.includes("bearer token unavailable") || msg.includes(REPORTING_REAUTH_ERROR);
}
function hashString(str) {
  let hash = 5381;
  for (let i = 0; i < str.length; i++) {
    hash = (hash << 5) + hash + str.charCodeAt(i) >>> 0;
  }
  return hash.toString(16).padStart(8, "0");
}
function buildCacheKey(cacheKeyPrefix, cacheKeyFrom, ...args) {
  const keyData = cacheKeyFrom(...args);
  const prefix = cacheKeyPrefix ? `${cacheKeyPrefix}_` : "";
  return prefix + hashString(JSON.stringify(keyData));
}
async function getBackfillCache(cacheKey, cacheGroup, extraParams = {}) {
  guardReportingConnection();
  const formData = new FormData();
  formData.set("action", "monsterinsights_get_backfill_cache");
  formData.set("nonce", getNonce());
  formData.set("cache_key", cacheKey);
  formData.set("cache_group", cacheGroup);
  if (extraParams && typeof extraParams === "object") {
    for (const [key, value] of Object.entries(extraParams)) {
      if (value !== null && value !== void 0) {
        formData.set(key, typeof value === "object" ? JSON.stringify(value) : String(value));
      }
    }
  }
  const res = await ajaxPost(formData);
  if (res.success && res.data) {
    return res.data;
  }
  throw new Error(res.data?.message || "Cache miss");
}
async function backfillToWp(cacheGroup, cacheKey, data) {
  const formData = new FormData();
  formData.set("action", "monsterinsights_backfill_cache");
  formData.set("nonce", getNonce());
  formData.set("cache_group", cacheGroup);
  formData.set("cache_key", cacheKey);
  formData.set("data", JSON.stringify(data));
  await ajaxPost(formData);
}
function getRegistry() {
  try {
    const raw = localStorage.getItem(REGISTRY_KEY);
    return raw ? JSON.parse(raw) : {};
  } catch {
    return {};
  }
}
function setRegistry(registry) {
  try {
    localStorage.setItem(REGISTRY_KEY, JSON.stringify(registry));
  } catch {
  }
}
function cleanExpired(registry) {
  const now = Math.floor(Date.now() / 1e3);
  const cleaned = {};
  for (const key in registry) {
    if (registry[key].expires > now) {
      cleaned[key] = registry[key];
    }
  }
  return cleaned;
}
function isCached(cacheKey) {
  const registry = cleanExpired(getRegistry());
  setRegistry(registry);
  return !!registry[cacheKey];
}
function registerCache(cacheKey, ttl = CACHE_TTL) {
  const registry = cleanExpired(getRegistry());
  registry[cacheKey] = {
    expires: Math.floor(Date.now() / 1e3) + ttl
  };
  setRegistry(registry);
}
function invalidateCache(cacheKey) {
  const registry = getRegistry();
  if (registry[cacheKey]) {
    delete registry[cacheKey];
    setRegistry(registry);
  }
}
function clearCache() {
  try {
    localStorage.removeItem(REGISTRY_KEY);
  } catch {
  }
}
function useCachedFetch({
  cacheKeyPrefix = "",
  wpFetch,
  directFetch = null,
  canDirectFetch = () => false,
  backfill = null,
  cacheKeyFrom = (...args) => args,
  formatResponse = (rawData) => rawData
}) {
  function generateCacheKey(...args) {
    const keyData = cacheKeyFrom(...args);
    const prefix = cacheKeyPrefix ? `${cacheKeyPrefix}_` : "";
    return prefix + hashString(JSON.stringify(keyData));
  }
  async function fetchWithCache(...args) {
    const cacheKey = generateCacheKey(...args);
    if (isCached(cacheKey)) {
      try {
        return await wpFetch(cacheKey, ...args);
      } catch (err) {
        if (isReAuthError(err)) {
          throw err;
        }
        invalidateCache(cacheKey);
        if (typeof console !== "undefined" && console.debug) {
          console.debug("[useCachedFetch] Registry hit but wpFetch failed (invalidated registry):", err?.message || err, err);
        }
      }
    }
    if (directFetch && canDirectFetch()) {
      try {
        const rawData = await directFetch(...args);
        if (backfill) {
          Promise.resolve(backfill(...args, rawData)).then(() => {
            registerCache(cacheKey);
          }).catch((backfillErr) => {
            if (typeof console !== "undefined" && console.debug) {
              console.debug("[useCachedFetch] Backfill to WP failed (cache not stored); next load will retry direct fetch:", backfillErr?.message || backfillErr, backfillErr);
            }
            registerCache(cacheKey);
          });
        } else {
          registerCache(cacheKey);
        }
        return formatResponse(rawData, ...args);
      } catch (directError) {
        if (isReAuthError(directError)) {
          throw directError;
        }
        if (typeof console !== "undefined" && console.debug) {
          console.debug("[useCachedFetch] Direct fetch failed, falling back to wpFetch:", directError?.message || directError, directError);
        }
      }
    }
    const response = await wpFetch(cacheKey, ...args);
    registerCache(cacheKey);
    return response;
  }
  return {
    fetchWithCache,
    clearCache,
    generateCacheKey
  };
}
function createRequestQueue({ concurrency = 2, delayMs = 300 } = {}) {
  let running = 0;
  let lastStartTime = 0;
  const queue = [];
  function processNext() {
    if (running >= concurrency || queue.length === 0) {
      return;
    }
    const { fn, resolve, reject } = queue.shift();
    running++;
    const now = Date.now();
    const elapsed = now - lastStartTime;
    const wait = elapsed < delayMs ? delayMs - elapsed : 0;
    const run = () => {
      lastStartTime = Date.now();
      fn().then(resolve, reject).finally(() => {
        running--;
        processNext();
      });
    };
    if (wait > 0) {
      setTimeout(run, wait);
    } else {
      run();
    }
  }
  function enqueue(fn) {
    return new Promise((resolve, reject) => {
      queue.push({ fn, resolve, reject });
      processNext();
    });
  }
  return { enqueue };
}
const OVERVIEW_METRICS = [
  "totalUsers",
  "screenPageViews",
  "sessions",
  "bounceRate",
  "ecommercePurchases",
  "averagePurchaseRevenue",
  "newUsers",
  "engagementRate",
  "totalRevenue",
  "averageSessionDuration",
  "addToCarts",
  "engagedSessions",
  "sessionKeyEventRate"
];
const DEFAULT_OVERVIEW_METRICS = [
  "sessions",
  "engagedSessions",
  "sessionKeyEventRate"
];
const DEFAULT_ROW_LIMIT = 1e3;
const TAB_METRICS = {
  traffic: ["totalUsers", "newUsers", "sessions", "engagementRate"],
  engagement: ["sessions", "screenPageViews", "bounceRate", "averageSessionDuration", "engagementRate", "newUsers", "totalUsers"],
  referrals: ["sessions", "engagedSessions", "sessionKeyEventRate", "totalUsers"],
  ecommerce: ["sessions", "totalRevenue", "ecommercePurchases", "averagePurchaseRevenue", "addToCarts"]
};
const CHART_METRICS = [
  "sessions",
  "engagedSessions",
  "totalUsers",
  "newUsers",
  "engagementRate",
  "screenPageViews",
  "bounceRate",
  "averageSessionDuration",
  "sessionKeyEventRate",
  "totalRevenue",
  "ecommercePurchases",
  "averagePurchaseRevenue"
];
const CHANNEL_GROUPS = ["Organic Search", "Direct", "Referral", "Paid Search", "Organic Social"];
const DIMENSION_SCALES = {
  deviceCategory: {
    desktop: 0.55,
    mobile: 0.35,
    tablet: 0.1
  },
  country: {
    "United States": 0.4,
    "United Kingdom": 0.15,
    Germany: 0.12,
    Canada: 0.08,
    Australia: 0.07,
    France: 0.06,
    Japan: 0.05,
    Mexico: 0.04,
    Brazil: 0.03
  },
  sessionDefaultChannelGroup: {
    "Organic Search": 0.45,
    Direct: 0.25,
    Referral: 0.15,
    "Paid Search": 0.1,
    "Organic Social": 0.05
  }
};
function seededRandom(seed) {
  let hash = 0;
  for (let i = 0; i < seed.length; i++) {
    const char = seed.charCodeAt(i);
    hash = (hash << 5) - hash + char;
    hash = hash & hash;
  }
  const x = Math.sin(hash) * 1e4;
  return x - Math.floor(x);
}
function generateDateRange(start, end) {
  const dates = [];
  const startDate = new Date(start);
  const endDate = new Date(end);
  while (startDate <= endDate) {
    const year = startDate.getFullYear();
    const month = String(startDate.getMonth() + 1).padStart(2, "0");
    const day = String(startDate.getDate()).padStart(2, "0");
    dates.push(`${year}${month}${day}`);
    startDate.setDate(startDate.getDate() + 1);
  }
  return dates;
}
function getFilterScale(apiFilters) {
  if (!apiFilters?.conditions?.length) {
    return 1;
  }
  let scale = 1;
  for (const condition of apiFilters.conditions) {
    const field = condition.field;
    const value = condition.value;
    const fieldScales = DIMENSION_SCALES[field];
    if (fieldScales && fieldScales[value] !== void 0) {
      scale *= fieldScales[value] / Math.max(...Object.values(fieldScales));
    }
  }
  return Math.max(0.1, Math.min(1, scale));
}
function isRateMetric(name) {
  return ["bounceRate", "engagementRate", "sessionKeyEventRate"].includes(name);
}
function isAvgMetric(name) {
  return ["averageSessionDuration", "averagePurchaseRevenue"].includes(name);
}
function generateMetricValue(metric, seed, scale = 1) {
  const rand = seededRandom(seed);
  const baseVariance = 0.7 + rand * 0.6;
  const baseValues = {
    totalUsers: 80,
    newUsers: 55,
    sessions: 95,
    screenPageViews: 220,
    bounceRate: 0.45,
    engagementRate: 0.55,
    engagedSessions: 52,
    averageSessionDuration: 135,
    sessionKeyEventRate: 0.035,
    totalRevenue: 1200,
    ecommercePurchases: 12,
    averagePurchaseRevenue: 100,
    purchaseRevenue: 1200,
    eventCount: 45,
    addToCarts: 28
  };
  const base = baseValues[metric] ?? 50;
  if (isRateMetric(metric)) {
    const rateBase = base * baseVariance;
    return Math.max(0.2, Math.min(0.8, rateBase));
  }
  if (isAvgMetric(metric)) {
    return Math.max(1, Math.round(base * baseVariance));
  }
  return Math.round(base * baseVariance * scale);
}
function formatMetricValue(value, metric) {
  const num = Number(value);
  if (Number.isNaN(num) || num < 0) {
    return isRateMetric(metric) ? "0.000000" : metric === "averagePurchaseRevenue" || metric === "totalRevenue" || metric === "purchaseRevenue" ? "0.00" : "0";
  }
  if (isRateMetric(metric)) {
    return num.toFixed(14);
  }
  if (metric === "averageSessionDuration") {
    return num.toFixed(1);
  }
  if (metric === "averagePurchaseRevenue" || metric === "totalRevenue" || metric === "purchaseRevenue") {
    return num.toFixed(2);
  }
  return String(Math.round(num));
}
function generateOverviewRows({ dates, selectedMetrics, overviewMetricsToRequest, scale, useCompare }) {
  const requested = overviewMetricsToRequest ?? selectedMetrics;
  const filtered = requested?.length ? requested.filter((m) => OVERVIEW_METRICS.includes(m)) : [];
  const list = filtered.length ? filtered : DEFAULT_OVERVIEW_METRICS;
  const rows = [];
  for (const date of dates) {
    const m = [];
    for (const metric of list) {
      const seed = `${date}-${metric}`;
      const currentVal = generateMetricValue(metric, seed, scale);
      if (useCompare) {
        const prevSeed = `${date}-${metric}-prev`;
        const previousVal = generateMetricValue(metric, prevSeed, scale * 0.9);
        m.push([formatMetricValue(previousVal, metric), formatMetricValue(currentVal, metric)]);
      } else {
        m.push(formatMetricValue(currentVal, metric));
      }
    }
    if (useCompare) {
      rows.push({ d: [date], m });
    } else {
      rows.push({ d: [date], m: [m] });
    }
  }
  return { rows };
}
function generateTabMetrics({ dates, activeTab, scale, useCompare }) {
  const metrics = TAB_METRICS[activeTab] || TAB_METRICS.traffic;
  const rows = [];
  for (const date of dates) {
    const m = [];
    for (const metric of metrics) {
      const seed = `${date}-tab-${activeTab}-${metric}`;
      const currentVal = generateMetricValue(metric, seed, scale);
      if (useCompare) {
        const prevSeed = `${date}-tab-${activeTab}-${metric}-prev`;
        const previousVal = generateMetricValue(metric, prevSeed, scale * 0.9);
        m.push([formatMetricValue(previousVal, metric), formatMetricValue(currentVal, metric)]);
      } else {
        m.push(formatMetricValue(currentVal, metric));
      }
    }
    if (useCompare) {
      rows.push({ d: [date], m });
    } else {
      rows.push({ d: [date], m: [m] });
    }
  }
  return { rows };
}
const ORDER_COUPON_VALUES = [
  { value: "(not set)", share: 0.55 },
  { value: "SAVE10", share: 0.2 },
  { value: "FREESHIP", share: 0.15 },
  { value: "WELCOME15", share: 0.1 }
];
function generateFormulaCouponRows({ dates, scale }) {
  const rows = [];
  for (const date of dates) {
    const baseTotal = Math.max(10, Math.round(generateMetricValue("ecommercePurchases", `${date}-coupon-total`, scale) * 3));
    for (const { value: orderCoupon, share } of ORDER_COUPON_VALUES) {
      const raw = Math.round(baseTotal * share * (0.8 + seededRandom(`${date}-${orderCoupon}`) * 0.4));
      const purchases = Math.max(1, raw);
      rows.push({
        d: [date, orderCoupon],
        m: [[purchases]]
      });
    }
  }
  return { rows };
}
function generateChartMetrics({ dates, scale }) {
  const rows = [];
  for (const date of dates) {
    const m = [];
    for (const metric of CHART_METRICS) {
      const seed = `${date}-chart-${metric}`;
      const val = generateMetricValue(metric, seed, scale);
      m.push(formatMetricValue(val, metric));
    }
    rows.push({ d: [date], m: [m] });
  }
  return { rows };
}
function generateChartBySource({ dates, scale }) {
  const rows = [];
  for (const date of dates) {
    for (const channel of CHANNEL_GROUPS) {
      const seed = `${date}-${channel}`;
      const channelScale = (DIMENSION_SCALES.sessionDefaultChannelGroup[channel] || 0.1) * scale;
      const users = Math.round(generateMetricValue("totalUsers", seed, channelScale));
      const newUsers = Math.round(users * (0.6 + seededRandom(`${seed}-new`) * 0.3));
      rows.push({
        d: [date, channel],
        m: [[String(users), String(newUsers)]]
      });
    }
  }
  return { rows };
}
function generateKeyMetrics({ scale, useCompare }) {
  const baseTotalSessions = 2e3 * scale;
  const CHANNEL_WEIGHTS = [
    { name: "Organic Search", weight: 0.4 },
    // → organic
    { name: "Social", weight: 0.12 },
    // → social
    { name: "Paid Search", weight: 0.2 },
    // → paid
    { name: "Email", weight: 0.08 },
    // → email
    { name: "Referral", weight: 0.1 },
    // → referral
    { name: "Direct", weight: 0.1 }
    // → direct
  ];
  const rows = [];
  const date = "20260101";
  for (const { name, weight } of CHANNEL_WEIGHTS) {
    const seed = `key-${name}`;
    const currentSessions = Math.max(1, Math.round(baseTotalSessions * weight * (0.9 + seededRandom(seed) * 0.2)));
    if (useCompare) {
      const prevSeed = `key-${name}-prev`;
      const previousSessions = Math.max(
        1,
        Math.round(currentSessions * (0.8 + seededRandom(prevSeed) * 0.15))
      );
      rows.push({
        d: [date, name],
        m: [[
          formatMetricValue(currentSessions, "sessions"),
          formatMetricValue(previousSessions, "sessions")
        ]]
      });
    } else {
      rows.push({
        d: [date, name],
        m: [[formatMetricValue(currentSessions, "sessions")]]
      });
    }
  }
  return { rows };
}
function generateMarketingCampaigns({ scale }) {
  const campaigns = ["spring_sale_2026", "newsletter_feb", "google_ads_brand", "facebook_retargeting", "organic"];
  const sources = ["google", "facebook", "direct", "newsletter", "bing"];
  const mediums = ["organic", "cpc", "email", "referral", "social"];
  const terms = ["analytics", "wordpress", "seo", "marketing", "(not set)"];
  const contents = ["banner_a", "sidebar_b", "header_c", "(not set)", "footer_d"];
  const generateRows = (values, prefix) => ({
    rows: values.map((val, idx) => {
      const seed = `${prefix}-${val}`;
      const rowScale = scale * (1 - idx * 0.15);
      return {
        d: [val],
        m: [[
          formatMetricValue(generateMetricValue("sessions", seed, rowScale), "sessions"),
          formatMetricValue(generateMetricValue("totalUsers", seed, rowScale), "totalUsers"),
          formatMetricValue(generateMetricValue("engagementRate", seed, rowScale), "engagementRate"),
          formatMetricValue(generateMetricValue("totalRevenue", seed, rowScale), "totalRevenue"),
          formatMetricValue(generateMetricValue("ecommercePurchases", seed, rowScale), "ecommercePurchases"),
          formatMetricValue(generateMetricValue("averagePurchaseRevenue", seed, rowScale), "averagePurchaseRevenue")
        ]]
      };
    })
  });
  return {
    campaign: generateRows(campaigns, "mc-campaign"),
    source: generateRows(sources, "mc-source"),
    medium: generateRows(mediums, "mc-medium"),
    term: generateRows(terms, "mc-term"),
    content: generateRows(contents, "mc-content")
  };
}
function generatePages({ scale }) {
  const landingPages = ["/", "/blog/", "/products/", "/about/", "/contact/"];
  const pageLocations = ["/blog/post-1/", "/products/item-a/", "/services/", "/pricing/", "/faq/"];
  const pageTitles = ["Home", "Blog", "Products", "About Us", "Contact"];
  const queryStrings = ["?utm_source=google", "?ref=newsletter", "?campaign=spring", "(not set)", "?source=twitter"];
  const generateRows = (values, prefix) => ({
    rows: values.map((val, idx) => {
      const seed = `${prefix}-${val}`;
      const rowScale = scale * (1 - idx * 0.12);
      return {
        d: [val],
        m: [[
          formatMetricValue(generateMetricValue("sessions", seed, rowScale), "sessions"),
          formatMetricValue(generateMetricValue("totalUsers", seed, rowScale), "totalUsers"),
          formatMetricValue(generateMetricValue("engagementRate", seed, rowScale), "engagementRate"),
          formatMetricValue(generateMetricValue("totalRevenue", seed, rowScale), "totalRevenue"),
          formatMetricValue(generateMetricValue("ecommercePurchases", seed, rowScale), "ecommercePurchases"),
          formatMetricValue(generateMetricValue("averagePurchaseRevenue", seed, rowScale), "averagePurchaseRevenue")
        ]]
      };
    })
  });
  return {
    landingPage: generateRows(landingPages, "pages-landing"),
    pageLocation: generateRows(pageLocations, "pages-location"),
    pageTitle: generateRows(pageTitles, "pages-title"),
    queryString: generateRows(queryStrings, "pages-qs")
  };
}
function generateDemographics({ scale, apiFilters = null }) {
  const countries = ["United States", "United Kingdom", "Germany", "Canada", "Australia", "France", "Japan"];
  const userTypes = ["new", "returning"];
  const COUNTRY_STATES = {
    "United States": ["California", "Texas", "New York", "Florida", "Illinois", "Washington"],
    Canada: ["Ontario", "Quebec", "British Columbia", "Alberta"],
    "Australia": ["New South Wales", "Victoria", "Queensland"],
    "United Kingdom": ["England", "Scotland", "Wales"],
    Germany: ["Bavaria", "Berlin", "Hamburg"],
    France: ["Île-de-France", "Provence-Alpes-Côte d’Azur"],
    Japan: ["Tokyo", "Osaka", "Hokkaido"]
  };
  let filteredCountries = countries;
  const countryConditions = apiFilters?.conditions?.filter((c) => c.field === "country" && c.value && typeof c.value === "string") || [];
  if (countryConditions.length > 0) {
    const wanted = new Set(countryConditions.map((c) => c.value));
    const subset = countries.filter((c) => wanted.has(c));
    if (subset.length > 0) {
      filteredCountries = subset;
    }
  }
  const generateRows = (values, prefix, metrics = ["sessions", "totalRevenue", "engagementRate"]) => ({
    rows: values.map((val, idx) => {
      const seed = `${prefix}-${val}`;
      const rowScale = scale * (1 - idx * 0.1);
      return {
        d: [val],
        m: [metrics.map((m) => formatMetricValue(generateMetricValue(m, seed, rowScale), m))]
      };
    })
  });
  const country = generateRows(filteredCountries, "demo-country");
  const stateRows = [];
  filteredCountries.forEach((countryName, countryIndex) => {
    const statesForCountry = COUNTRY_STATES[countryName] || ["Region A", "Region B"];
    statesForCountry.forEach((stateName, stateIndex) => {
      const seed = `demo-state-${countryName}-${stateName}`;
      const rowScale = scale * (1 - (countryIndex * 0.1 + stateIndex * 0.05));
      stateRows.push({
        d: [stateName],
        m: [["sessions", "totalRevenue", "engagementRate"].map((m) => formatMetricValue(generateMetricValue(m, seed, rowScale), m))]
      });
    });
  });
  const state = { rows: stateRows };
  const newVsReturning = generateRows(userTypes, "demo-nvr");
  return {
    country,
    state,
    newVsReturning
  };
}
function generateDevices({ scale }) {
  const browsers = ["Chrome", "Safari", "Firefox", "Edge", "Samsung Internet", "Opera"];
  const operatingSystems = ["Windows", "macOS", "iOS", "Android", "Linux"];
  const sizes = ["desktop", "mobile", "tablet"];
  const generateRows = (values, prefix) => ({
    rows: values.map((val, idx) => {
      const seed = `${prefix}-${val}`;
      const rowScale = scale * (1 - idx * 0.12);
      return {
        d: [val],
        m: [[
          formatMetricValue(generateMetricValue("sessions", seed, rowScale), "sessions"),
          formatMetricValue(generateMetricValue("totalRevenue", seed, rowScale), "totalRevenue"),
          formatMetricValue(generateMetricValue("engagementRate", seed, rowScale), "engagementRate")
        ]]
      };
    })
  });
  return {
    browser: generateRows(browsers, "devices-browser"),
    os: generateRows(operatingSystems, "devices-os"),
    size: generateRows(sizes, "devices-size")
  };
}
function generateEcommerceOverview({ dates, scale, apiFilters = null }) {
  const hasFilters = !!apiFilters?.conditions?.length;
  const transactionIds = ["TXN-001", "TXN-002", "TXN-003", "TXN-004", "TXN-005"];
  const sources = ["google", "facebook", "direct", "newsletter"];
  const mediums = ["cpc", "organic", "email", "referral"];
  const campaigns = ["spring_sale", "brand_2026", "(not set)", "newsletter_feb"];
  function buildLogRow(date, txn, source, medium, campaign, seed) {
    const dateHour = `${date}12`;
    const revenue = generateMetricValue("purchaseRevenue", seed, scale);
    return {
      d: [dateHour, campaign, medium, source, txn],
      m: [[formatMetricValue(revenue, "purchaseRevenue")]]
    };
  }
  const maxLogRows = hasFilters ? 6 : 12;
  const allLogRows = [];
  for (let i = 0; i < Math.min(dates.length, maxLogRows); i++) {
    const date = dates[i];
    const txn = transactionIds[i % transactionIds.length];
    const source = sources[i % sources.length];
    const medium = mediums[i % mediums.length];
    const campaign = campaigns[i % campaigns.length];
    const seed = `ecom-log-${date}-${txn}`;
    allLogRows.push(buildLogRow(date, txn, source, medium, campaign, seed));
  }
  const ecommerce_log_date = {
    rows: [...allLogRows].sort((a, b) => (b.d[0] || "").localeCompare(a.d[0] || ""))
  };
  const ecommerce_log_source_medium = {
    rows: [...allLogRows].sort((a, b) => {
      const cmp = (a.d[3] || "").localeCompare(b.d[3] || "");
      return cmp !== 0 ? cmp : (a.d[2] || "").localeCompare(b.d[2] || "");
    })
  };
  const ecommerce_log_campaign = {
    rows: [...allLogRows].sort((a, b) => (a.d[1] || "").localeCompare(b.d[1] || ""))
  };
  const products = ["Premium Plan", "Starter Kit", "Add-on License", "Pro Bundle", "Annual Subscription", "Starter Pack"];
  const coupons = ["SAVE10", "WELCOME", "(not set)", "BLACKFRIDAY", "NEWYEAR"];
  const maxDataRows = hasFilters ? 3 : products.length;
  const ecommerce_data_rows = [];
  for (let i = 0; i < maxDataRows; i++) {
    const product = products[i];
    const coupon = coupons[i % coupons.length];
    const seed = `ecom-data-${product}-${coupon}`;
    const itemRevenue = generateMetricValue("totalRevenue", seed, scale) * (0.8 + seededRandom(seed) * 0.4);
    const itemsPurchased = Math.max(1, Math.round(generateMetricValue("ecommercePurchases", seed, scale)));
    ecommerce_data_rows.push({
      d: [product, coupon],
      m: [[formatMetricValue(itemRevenue, "totalRevenue"), formatMetricValue(itemsPurchased, "ecommercePurchases")]]
    });
  }
  const ecommerce_data = { rows: ecommerce_data_rows };
  return {
    ecommerce_log_date,
    ecommerce_log_source_medium,
    ecommerce_log_campaign,
    ecommerce_data
  };
}
function generateFormSubmissions({ dates, scale, apiFilters = null }) {
  const formIds = ["contact-form", "newsletter-signup", "checkout-form", "feedback-form"];
  const allCountries = ["United States", "United Kingdom", "Germany"];
  const campaigns = ["spring_sale", "newsletter", "(not set)", "brand_awareness"];
  const countryConditions = apiFilters?.conditions?.filter((c) => c.field === "country" && c.value) || [];
  const filterCountries = countryConditions.length ? countryConditions.map((c) => c.value).filter((v) => allCountries.includes(v)) : null;
  const countries = filterCountries?.length ? filterCountries : allCountries;
  const maxRows = apiFilters?.conditions?.length ? 10 : 20;
  const sourceMediumRows = [];
  for (let i = 0; i < Math.min(dates.length * 2, maxRows); i++) {
    const date = dates[i % dates.length];
    const formId = formIds[i % formIds.length];
    const country = countries[i % countries.length];
    const seed = `form-sm-${date}-${formId}-${country}`;
    sourceMediumRows.push({
      d: [country, formId, `${date}14`, "cpc", "google"],
      m: [[formatMetricValue(generateMetricValue("eventCount", seed, scale), "eventCount")]]
    });
  }
  const campaignRows = [];
  for (let i = 0; i < Math.min(dates.length * 2, maxRows); i++) {
    const date = dates[i % dates.length];
    const formId = formIds[i % formIds.length];
    const country = countries[i % countries.length];
    const campaign = campaigns[i % campaigns.length];
    const seed = `form-camp-${date}-${formId}-${country}`;
    campaignRows.push({
      d: [country, formId, campaign, "cpc", "google"],
      m: [[formatMetricValue(generateMetricValue("eventCount", seed, scale), "eventCount")]]
    });
  }
  return {
    sourceMedium: { rows: sourceMediumRows },
    campaign: { rows: campaignRows }
  };
}
function isSampleDataEnabled$1() {
  return !!getMiGlobal("sample_data_enabled", false);
}
function generateSampleOverviewData({ dateRange, apiFilters = null, selectedMetrics = null, overviewMetricsToRequest = null, activeTab = "traffic" }) {
  const start = dateRange?.start || "2026-01-19";
  const end = dateRange?.end || "2026-02-17";
  const useCompare = !!(dateRange?.compareReport && dateRange?.compareStart && dateRange?.compareEnd);
  const dates = generateDateRange(start, end);
  const scale = getFilterScale(apiFilters);
  const overview = generateOverviewRows({
    dates,
    selectedMetrics,
    overviewMetricsToRequest,
    scale,
    useCompare
  });
  const result = {
    date_range: { start, end },
    overview,
    key_metrics: generateKeyMetrics({ scale, useCompare }),
    key_metrics_compare: useCompare ? generateKeyMetrics({ scale: scale * 0.9, useCompare: false }) : null,
    chart_metrics: generateChartMetrics({ dates, scale }),
    tab_metrics: generateTabMetrics({ dates, activeTab, scale, useCompare }),
    chart_by_source: generateChartBySource({ dates, scale })
  };
  if (Array.isArray(selectedMetrics) && selectedMetrics.includes("couponUsedPercent")) {
    result.overview_formula_couponUsedPercent = generateFormulaCouponRows({ dates, scale });
  }
  return result;
}
function generateSampleBundleData({ dateRange, apiFilters = null }) {
  const start = dateRange?.start || "2026-01-19";
  const end = dateRange?.end || "2026-02-17";
  const dates = generateDateRange(start, end);
  const scale = getFilterScale(apiFilters);
  const pages = generatePages({ scale });
  return {
    marketing_campaigns: generateMarketingCampaigns({ scale }),
    // Top Posts/Pages widget — reuse the pages pageTitle sample (same { rows } shape).
    top_pages_title: pages.pageTitle,
    pages,
    demographics: generateDemographics({ scale, apiFilters }),
    devices: generateDevices({ scale }),
    form_submissions: generateFormSubmissions({ dates, scale, apiFilters }),
    ecommerce_overview: generateEcommerceOverview({ dates, scale, apiFilters })
  };
}
function generateSampleFunnelData({ apiFilters = null }) {
  const scale = getFilterScale(apiFilters);
  const steps = ["1. view_item", "2. add_to_cart", "3. purchase"];
  const baseUsers = [450, 57, 2];
  const tableRows = steps.map((step, idx) => {
    const users = Math.round(baseUsers[idx] * scale);
    const completionRate = idx < steps.length - 1 ? baseUsers[idx + 1] / baseUsers[idx] : 1;
    const abandonments = idx < steps.length - 1 ? users - Math.round(baseUsers[idx + 1] * scale) : 0;
    const abandonmentRate = 1 - completionRate;
    return {
      d: [step, "RESERVED_TOTAL"],
      m: [[
        String(users),
        completionRate.toFixed(6),
        String(abandonments),
        abandonmentRate.toFixed(6)
      ]]
    };
  });
  const vizRows = steps.map((step, idx) => ({
    d: [step],
    m: [[String(Math.round(baseUsers[idx] * scale))]]
  }));
  return {
    funnelTable: {
      dimensionHeaders: [
        { name: "funnelStepName" },
        { name: "deviceCategory" }
      ],
      metricHeaders: [
        { name: "activeUsers", type: "TYPE_INTEGER" },
        { name: "funnelStepCompletionRate", type: "TYPE_FLOAT" },
        { name: "funnelStepAbandonments", type: "TYPE_INTEGER" },
        { name: "funnelStepAbandonmentRate", type: "TYPE_FLOAT" }
      ],
      rows: tableRows,
      metadata: {}
    },
    funnelVisualization: {
      dimensionHeaders: [{ name: "funnelStepName" }],
      metricHeaders: [
        { name: "activeUsers", type: "TYPE_INTEGER" },
        { name: "activeUsers", type: "TYPE_INTEGER" }
      ],
      rows: vizRows,
      metadata: {}
    },
    kind: "analyticsData#runFunnelReport"
  };
}
function generateSampleCustomDimensionsData({ apiFilters = null }) {
  const scale = getFilterScale(apiFilters);
  const generateRows = (values, prefix) => ({
    rows: values.map((val, idx) => {
      const seed = `${prefix}-${val}`;
      const rowScale = scale * (1 - idx * 0.1);
      return {
        d: [val],
        m: [[
          formatMetricValue(generateMetricValue("sessions", seed, rowScale), "sessions"),
          formatMetricValue(generateMetricValue("totalUsers", seed, rowScale), "totalUsers"),
          formatMetricValue(generateMetricValue("engagementRate", seed, rowScale), "engagementRate"),
          formatMetricValue(generateMetricValue("totalRevenue", seed, rowScale), "totalRevenue"),
          formatMetricValue(generateMetricValue("ecommercePurchases", seed, rowScale), "ecommercePurchases"),
          formatMetricValue(generateMetricValue("averagePurchaseRevenue", seed, rowScale), "averagePurchaseRevenue")
        ]]
      };
    })
  });
  return {
    loggedIn: generateRows(["yes", "no"], "cd-logged"),
    postType: generateRows(["post", "page", "product"], "cd-posttype"),
    author: generateRows(["John Smith", "Jane Doe", "Mike Johnson", "Sarah Wilson"], "cd-author"),
    category: generateRows(["Tutorials", "News", "Tips & Tricks", "Reviews"], "cd-category"),
    tags: generateRows(["analytics", "wordpress", "google-analytics", "seo"], "cd-tags"),
    focusKeyword: generateRows(["wordpress seo", "analytics plugin", "google analytics", "site optimization", "(not set)"], "cd-focus-keyword"),
    dayOfWeek: generateRows(["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], "cd-dow"),
    seoScore: generateRows(["76-100", "51-75", "26-50", "0-25", "(not set)"], "cd-seo-score"),
    focusKeyphrase: generateRows(["best seo plugin", "how to install analytics", "track website traffic", "conversion tracking", "(not set)"], "cd-focus-keyphrase")
  };
}
const { __ } = wp.i18n;
function isSampleDataEnabled() {
  return isSampleDataEnabled$1() || !isReportingConnected();
}
function getRelayRequestOptions(apiPath, body) {
  const relayApiUrl = (getMiGlobal("relay_api_url") || "").replace(/\/$/, "");
  const bearerToken = getMiGlobal("bearer_token");
  const pluginVersion = getMiGlobal("plugin_version", "1.0.0");
  const url = relayApiUrl ? `${relayApiUrl}/${apiPath}` : "";
  const headers = {
    "Content-Type": "application/json",
    Authorization: `Bearer ${bearerToken || ""}`
  };
  const bodyWithVersion = { ...body, plugin_version: pluginVersion };
  return { url, headers, body: bodyWithVersion };
}
async function getRelayRequestOptionsWithFreshToken(apiPath, body) {
  guardReportingConnection();
  const hasToken = await ensureBearerToken();
  const tokenNow = getMiGlobal("bearer_token");
  if (!hasToken || !tokenNow || typeof tokenNow !== "string") {
    throw new Error("Bearer token unavailable or expired");
  }
  return getRelayRequestOptions(apiPath, body);
}
const relayQueue = createRequestQueue({ concurrency: 2, delayMs: 300 });
async function _relayReportingQueryRaw(body) {
  const relay = await getRelayRequestOptionsWithFreshToken("api/v3/reporting/query", body);
  if (!relay.url) {
    throw new Error("Relay URL not configured");
  }
  const response = await fetch(relay.url, {
    method: "POST",
    headers: relay.headers,
    body: JSON.stringify(relay.body)
  });
  const decodedBody = await response.json();
  if (!response.ok || decodedBody?.success === false && decodedBody?.error) {
    const msg = decodedBody?.error?.message ?? decodedBody?.error ?? decodedBody?.message ?? "Request failed";
    throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
  }
  return decodedBody;
}
function relayReportingQuery(body) {
  return relayQueue.enqueue(() => _relayReportingQueryRaw(body));
}
async function _relayFunnelRaw(body) {
  const relay = await getRelayRequestOptionsWithFreshToken("api/v3/reporting/funnel", body);
  if (!relay.url) {
    throw new Error("Relay URL not configured");
  }
  const response = await fetch(relay.url, {
    method: "POST",
    headers: relay.headers,
    body: JSON.stringify(relay.body)
  });
  const decodedBody = await response.json();
  if (!response.ok || decodedBody?.success === false && decodedBody?.error) {
    const msg = decodedBody?.error?.message ?? decodedBody?.error ?? decodedBody?.message ?? "Request failed";
    throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
  }
  return decodedBody;
}
function relayFunnel(body) {
  return relayQueue.enqueue(() => _relayFunnelRaw(body));
}
function rejectReport(title, message) {
  return Promise.reject({
    title,
    message: message || __("An unknown error occurred.", "google-analytics-for-wordpress"),
    support_url: getMonsterInsightsUrl(
      "admin-notices",
      "error-overview-api",
      "https://www.monsterinsights.com/my-account/support"
    ),
    isAjaxError: true
  });
}
function relayFallbackFetch(apiPath, body, formatFn, errorLabel, signal) {
  guardReportingConnection();
  const reportingApi = getMiGlobal("reporting_api", {});
  const apiUrl = `${(reportingApi.url || "").replace(/\/$/, "")}/${apiPath.replace(/^\//, "")}`;
  const bodyToSend = { ...body, plugin_version: getMiGlobal("plugin_version", "1.0.0") };
  const headers = {
    "Content-Type": "application/json",
    "X-Relay-Site-Key": reportingApi.key || "",
    "X-Relay-Token": reportingApi.token || "",
    "X-Relay-Site-URL": reportingApi.site_url || ""
  };
  if (reportingApi.license) {
    headers["X-Relay-License"] = reportingApi.license;
  }
  return fetch(apiUrl, { method: "POST", headers, body: JSON.stringify(bodyToSend), signal }).then((response) => response.json().then((decodedBody) => ({ ok: response.ok, status: response.status, body: decodedBody }))).then(({ ok, status, body: decodedBody }) => {
    if (ok && status >= 200 && status < 300) {
      try {
        return formatFn(decodedBody);
      } catch (err) {
        return rejectReport(errorLabel, err?.message);
      }
    }
    const message = decodedBody?.error?.message ?? (typeof decodedBody?.error === "string" ? decodedBody.error : null) ?? decodedBody?.message ?? __("An unknown error occurred.", "google-analytics-for-wordpress");
    return rejectReport(errorLabel, message);
  });
}
const OVERVIEW_CACHE_GROUP = "overview";
function overviewCacheKeyFrom(dateRange, apiFilters, selectedMetrics, activeTab) {
  return {
    start: dateRange?.start,
    end: dateRange?.end,
    compare: dateRange?.compareReport,
    compareStart: dateRange?.compareStart,
    compareEnd: dateRange?.compareEnd,
    filters: apiFilters,
    selectedMetrics: selectedMetrics ?? null,
    activeTab: activeTab ?? null
  };
}
function injectFormulaResultsIntoOverviewRows(overviewData, selectedMetrics, formulaQueryResults, dateRange) {
  const rows = overviewData?.rows ?? [];
  const requestedMetrics = getOverviewMetricsToRequest(selectedMetrics);
  if (!Array.isArray(rows) || rows.length === 0) {
    return overviewData;
  }
  const isCompare = !!(dateRange?.compareReport && dateRange?.compareStart && dateRange?.compareEnd);
  const formulaRowsByDate = {};
  for (const key of selectedMetrics) {
    const formula = FORMULA_METRICS[key];
    if (!formula?.computeFromDimensionRows) {
      continue;
    }
    const raw = formulaQueryResults[`overview_formula_${key}`] ?? formulaQueryResults[key];
    const formulaRows = Array.isArray(raw) ? raw : Array.isArray(raw?.rows) ? raw.rows : [];
    const byDate = {};
    for (const row of formulaRows) {
      const date = row?.d?.[0];
      if (!date) {
        continue;
      }
      if (!byDate[date]) {
        byDate[date] = [];
      }
      byDate[date].push(row);
    }
    formulaRowsByDate[key] = byDate;
  }
  const newRows = rows.map((row) => {
    const date = row?.d?.[0];
    const rowM = row?.m ?? [];
    const requestedValues = isCompare ? requestedMetrics.map((_, idx) => {
      const cell = rowM[idx];
      return Array.isArray(cell) && cell.length >= 2 ? cell[1] : cell;
    }) : Array.isArray(rowM[0]) ? rowM[0] : [];
    const previousValues = isCompare ? requestedMetrics.map((_, idx) => {
      const cell = rowM[idx];
      return Array.isArray(cell) && cell.length >= 2 ? cell[0] : cell;
    }) : [];
    const metricsByKey = {};
    requestedMetrics.forEach((name, idx) => {
      metricsByKey[name] = requestedValues[idx] != null ? Number(requestedValues[idx]) : 0;
    });
    const prevMetricsByKey = {};
    if (isCompare) {
      requestedMetrics.forEach((name, idx) => {
        prevMetricsByKey[name] = previousValues[idx] != null ? Number(previousValues[idx]) : 0;
      });
    }
    const outValues = [];
    for (const key of selectedMetrics) {
      const formula = FORMULA_METRICS[key];
      if (formula) {
        if (formula.compute) {
          const currVal = formula.compute(metricsByKey);
          if (isCompare) {
            const prevVal = formula.compute(prevMetricsByKey);
            outValues.push([prevVal, currVal]);
          } else {
            outValues.push(currVal);
          }
        } else if (formula.computeFromDimensionRows) {
          const rowsForDate = formulaRowsByDate[key]?.[date] ?? [];
          const val = formula.computeFromDimensionRows(rowsForDate);
          outValues.push(isCompare ? [val, val] : val);
        } else {
          outValues.push(isCompare ? [0, 0] : 0);
        }
        continue;
      }
      if (DERIVED_CHART_KEYS[key]) {
        for (const baseKey of DERIVED_CHART_KEYS[key]) {
          const baseIdx = requestedMetrics.indexOf(baseKey);
          if (isCompare && baseIdx >= 0 && Array.isArray(rowM[baseIdx])) {
            outValues.push(rowM[baseIdx]);
          } else {
            const raw = baseIdx >= 0 ? requestedValues[baseIdx] : void 0;
            outValues.push(raw != null ? raw : isCompare ? [0, 0] : 0);
          }
        }
        continue;
      }
      const apiName = CHART_KEY_TO_OVERVIEW_METRIC[key] || key;
      const metricIdx = requestedMetrics.indexOf(apiName);
      if (isCompare && metricIdx >= 0 && Array.isArray(rowM[metricIdx])) {
        outValues.push(rowM[metricIdx]);
      } else {
        const raw = metricIdx >= 0 ? requestedValues[metricIdx] : void 0;
        outValues.push(raw != null ? raw : isCompare ? [0, 0] : 0);
      }
    }
    return {
      ...row,
      m: isCompare ? outValues : [outValues]
    };
  });
  return {
    ...overviewData,
    rows: newRows
  };
}
function formatOverviewResponse(decodedBody, dateRange, selectedMetrics) {
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  let data = null;
  if (decodedBody?.success && decodedBody?.data) {
    data = decodedBody.data?.data ?? decodedBody.data;
  } else if (decodedBody?.data) {
    data = decodedBody.data?.data ?? decodedBody.data;
  }
  if (!data) {
    throw new Error("Invalid overview response");
  }
  let overviewData = data?.overview ?? data;
  const formulaQueryResults = {};
  for (const key of Object.keys(FORMULA_METRICS)) {
    const formula = FORMULA_METRICS[key];
    if (formula?.dimensions?.length) {
      const id = `overview_formula_${key}`;
      if (data[id]) {
        formulaQueryResults[id] = data[id];
      }
    }
  }
  if (Array.isArray(selectedMetrics) && selectedMetrics.length > 0) {
    overviewData = injectFormulaResultsIntoOverviewRows(overviewData, selectedMetrics, formulaQueryResults, dateRange);
  }
  return {
    date_range: { start, end },
    overview: overviewData,
    key_metrics: data?.key_metrics ?? null,
    key_metrics_compare: data?.key_metrics_compare ?? null,
    chart_metrics: data?.chart_metrics ?? null,
    tab_metrics: data?.tab_metrics ?? null
  };
}
async function directFetchOverviewFromRelay(dateRange, apiFilters, selectedMetrics, activeTab) {
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  const useCompare = !!(dateRange?.compareReport && dateRange?.compareStart && dateRange?.compareEnd);
  let keyMetricsQuery = { ...KEY_METRICS_QUERY, compare: useCompare };
  if (keyMetricsQuery.compare) {
    keyMetricsQuery.compare_start = dateRange.compareStart;
    keyMetricsQuery.compare_end = dateRange.compareEnd;
  }
  const overviewMetrics = getOverviewMetricsToRequest(selectedMetrics);
  const overviewQuery = applyFiltersToQuery(
    {
      ...OVERVIEW_QUERY,
      metrics: overviewMetrics,
      compare: useCompare,
      ...useCompare && { compare_start: dateRange.compareStart, compare_end: dateRange.compareEnd }
    },
    apiFilters
  );
  keyMetricsQuery = applyFiltersToQuery(keyMetricsQuery, apiFilters);
  let chartMetricsQuery = { ...CHART_METRICS_QUERY, compare: useCompare };
  if (chartMetricsQuery.compare) {
    chartMetricsQuery.compare_start = dateRange.compareStart;
    chartMetricsQuery.compare_end = dateRange.compareEnd;
  }
  chartMetricsQuery = applyFiltersToQuery(chartMetricsQuery, apiFilters);
  const tabMetricsNames = getTabMetricsForQuery(activeTab);
  const tabMetricsQuery = applyFiltersToQuery(
    {
      id: "tab_metrics",
      dimensions: ["date"],
      metrics: tabMetricsNames,
      compare: useCompare,
      limit: DEFAULT_ROW_LIMIT,
      groupBy: "date",
      ...useCompare && { compare_start: dateRange.compareStart, compare_end: dateRange.compareEnd }
    },
    apiFilters
  );
  const formulaQueries = getFormulaQueries(selectedMetrics, dateRange, apiFilters);
  const allQueries = [overviewQuery, keyMetricsQuery, chartMetricsQuery, tabMetricsQuery, ...formulaQueries];
  const body = {
    start,
    end,
    ...useCompare && { compareStart: dateRange.compareStart, compareEnd: dateRange.compareEnd },
    queries: allQueries
  };
  const relay = await getRelayRequestOptionsWithFreshToken("api/v3/reporting/query", body);
  if (!relay.url) {
    throw new Error("Relay URL not configured");
  }
  const response = await fetch(relay.url, {
    method: "POST",
    headers: relay.headers,
    body: JSON.stringify(relay.body)
  });
  const decodedBody = await response.json();
  if (!response.ok || decodedBody?.success === false && decodedBody?.error) {
    const msg = decodedBody?.error?.message ?? decodedBody?.error ?? decodedBody?.message ?? "Request failed";
    throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
  }
  return decodedBody;
}
const overviewCachedFetch = useCachedFetch({
  cacheKeyPrefix: "overview",
  cacheKeyFrom: (...args) => overviewCacheKeyFrom(...args),
  wpFetch: async (cacheKey, dateRange, apiFilters, selectedMetrics, activeTab) => {
    const useCompare = !!(dateRange?.compareReport && dateRange?.compareStart && dateRange?.compareEnd);
    return getBackfillCache(cacheKey, OVERVIEW_CACHE_GROUP, {
      selected_metrics: selectedMetrics,
      active_tab: activeTab,
      compare: useCompare,
      api_filters: apiFilters ?? null
    });
  },
  directFetch: directFetchOverviewFromRelay,
  canDirectFetch: () => !isSampleDataEnabled() && !!getMiGlobal("bearer_token"),
  backfill: async (dateRange, apiFilters, selectedMetrics, activeTab, rawData) => {
    const cacheKey = buildCacheKey("overview", overviewCacheKeyFrom, dateRange, apiFilters, selectedMetrics, activeTab);
    const formatted = formatOverviewResponse(rawData, dateRange, selectedMetrics);
    await backfillToWp(OVERVIEW_CACHE_GROUP, cacheKey, formatted);
  },
  formatResponse: (rawData, ...args) => formatOverviewResponse(rawData, args[0], args[2])
});
const CUSTOM_DIMENSIONS_CACHE_GROUP = "custom_dimensions";
function customDimensionsCacheKeyFrom(dateRange, apiFilters, includeEcommerceMetrics = true) {
  return { start: dateRange?.start, end: dateRange?.end, filters: apiFilters, includeEcommerceMetrics };
}
function formatCustomDimensionsResponse(decodedBody) {
  let data = null;
  if (decodedBody?.success && decodedBody?.data) {
    data = decodedBody.data?.data ?? decodedBody.data;
  } else if (decodedBody && typeof decodedBody === "object" && !decodedBody.error && Object.keys(decodedBody).some((k) => String(k).startsWith("custom_dimensions_"))) {
    data = decodedBody;
  }
  if (!data) {
    throw new Error("Invalid custom dimensions response");
  }
  return {
    loggedIn: data.custom_dimensions_logged_in ?? null,
    postType: data.custom_dimensions_post_type ?? null,
    author: data.custom_dimensions_author ?? null,
    category: data.custom_dimensions_category ?? null,
    tags: data.custom_dimensions_tags ?? null,
    focusKeyword: data.custom_dimensions_focus_keyword ?? null,
    dayOfWeek: data.custom_dimensions_day_of_week ?? null,
    seoScore: data.custom_dimensions_seo_score ?? null,
    focusKeyphrase: data.custom_dimensions_focus_keyphrase ?? null
  };
}
async function directFetchCustomDimensionsFromRelay(dateRange, apiFilters, includeEcommerceMetrics = true) {
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  const customDimensionsQueries = getCustomDimensionsQueries(includeEcommerceMetrics).map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const body = { start, end, queries: customDimensionsQueries };
  const relay = await getRelayRequestOptionsWithFreshToken("api/v3/reporting/query", body);
  if (!relay.url) {
    throw new Error("Relay URL not configured");
  }
  const response = await fetch(relay.url, { method: "POST", headers: relay.headers, body: JSON.stringify(relay.body) });
  const decodedBody = await response.json();
  if (!response.ok || decodedBody?.success === false && decodedBody?.error) {
    const msg = decodedBody?.error?.message ?? decodedBody?.error ?? decodedBody?.message ?? "Request failed";
    throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
  }
  return decodedBody;
}
const customDimensionsCachedFetch = useCachedFetch({
  cacheKeyPrefix: "custom_dimensions",
  cacheKeyFrom: (...args) => customDimensionsCacheKeyFrom(...args),
  wpFetch: async (cacheKey, _dateRange, apiFilters) => getBackfillCache(cacheKey, CUSTOM_DIMENSIONS_CACHE_GROUP, {
    api_filters: apiFilters ?? null
  }),
  directFetch: directFetchCustomDimensionsFromRelay,
  canDirectFetch: () => !isSampleDataEnabled() && !!getMiGlobal("bearer_token"),
  backfill: async (dateRange, apiFilters, includeEcommerceMetrics, rawData) => {
    const cacheKey = buildCacheKey("custom_dimensions", customDimensionsCacheKeyFrom, dateRange, apiFilters, includeEcommerceMetrics);
    const formatted = formatCustomDimensionsResponse(rawData);
    await backfillToWp(CUSTOM_DIMENSIONS_CACHE_GROUP, cacheKey, formatted);
  },
  formatResponse: (rawData) => formatCustomDimensionsResponse(rawData)
});
function formatCustomDimensionsDeferredResponse(decodedBody) {
  let data = null;
  if (decodedBody?.success && decodedBody?.data) {
    data = decodedBody.data?.data ?? decodedBody.data;
  } else if (decodedBody && typeof decodedBody === "object" && !decodedBody.error && Object.keys(decodedBody).some((k) => String(k).startsWith("custom_dimensions_"))) {
    data = decodedBody;
  }
  if (!data) {
    throw new Error("Invalid custom dimensions deferred response");
  }
  return {
    focusKeyword: data.custom_dimensions_focus_keyword ?? null,
    dayOfWeek: data.custom_dimensions_day_of_week ?? null,
    seoScore: data.custom_dimensions_seo_score ?? null,
    focusKeyphrase: data.custom_dimensions_focus_keyphrase ?? null
  };
}
async function directFetchCustomDimensionsDeferredFromRelay(dateRange, apiFilters, includeEcommerceMetrics = true) {
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  const queries = getCustomDimensionsDeferredQueries(includeEcommerceMetrics).map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const body = { start, end, queries };
  const relay = await getRelayRequestOptionsWithFreshToken("api/v3/reporting/query", body);
  if (!relay.url) {
    throw new Error("Relay URL not configured");
  }
  const response = await fetch(relay.url, { method: "POST", headers: relay.headers, body: JSON.stringify(relay.body) });
  const decodedBody = await response.json();
  if (!response.ok || decodedBody?.success === false && decodedBody?.error) {
    const msg = decodedBody?.error?.message ?? decodedBody?.error ?? decodedBody?.message ?? "Request failed";
    throw new Error(typeof msg === "string" ? msg : JSON.stringify(msg));
  }
  return decodedBody;
}
const customDimensionsDeferredCachedFetch = useCachedFetch({
  cacheKeyPrefix: "custom_dimensions_deferred",
  cacheKeyFrom: (...args) => customDimensionsCacheKeyFrom(...args),
  wpFetch: async (cacheKey, _dateRange, apiFilters) => getBackfillCache(cacheKey, CUSTOM_DIMENSIONS_CACHE_GROUP, {
    api_filters: apiFilters ?? null
  }),
  directFetch: directFetchCustomDimensionsDeferredFromRelay,
  canDirectFetch: () => !isSampleDataEnabled() && !!getMiGlobal("bearer_token"),
  backfill: async (dateRange, apiFilters, includeEcommerceMetrics, rawData) => {
    const cacheKey = buildCacheKey("custom_dimensions_deferred", customDimensionsCacheKeyFrom, dateRange, apiFilters, includeEcommerceMetrics);
    const formatted = formatCustomDimensionsDeferredResponse(rawData);
    await backfillToWp(CUSTOM_DIMENSIONS_CACHE_GROUP, cacheKey, formatted);
  },
  formatResponse: (rawData) => formatCustomDimensionsDeferredResponse(rawData)
});
const FORMULA_METRICS = {
  cartAbandonRatePercent: {
    metrics: ["addToCarts", "ecommercePurchases"],
    dimensions: [],
    compute(metrics) {
      const addToCarts = Number(metrics.addToCarts ?? 0) || 0;
      const purchases = Number(metrics.ecommercePurchases ?? 0) || 0;
      if (!addToCarts) {
        return 0;
      }
      return (addToCarts - purchases) / addToCarts;
    }
  },
  couponUsedPercent: {
    metrics: ["ecommercePurchases"],
    dimensions: ["orderCoupon"],
    computeFromDimensionRows(rows) {
      let totalPurchases = 0;
      let couponPurchases = 0;
      for (const row of rows) {
        const val = Number(row?.m?.[0]?.[0] ?? row?.m?.[0] ?? 0) || 0;
        totalPurchases += val;
        const dimCoupon = row?.d?.[1];
        if (dimCoupon != null && String(dimCoupon).trim() !== "" && String(dimCoupon) !== "(not set)") {
          couponPurchases += val;
        }
      }
      return totalPurchases ? couponPurchases / totalPurchases : 0;
    }
  }
};
const CHART_KEY_TO_OVERVIEW_METRIC = {
  itemsPurchased: "ecommercePurchases",
  totalUsers: "totalUsers",
  newUsers: "newUsers",
  engagementRate: "engagementRate",
  bounceRate: "bounceRate",
  ecommercePurchases: "ecommercePurchases",
  totalRevenue: "totalRevenue",
  averagePurchaseRevenue: "averagePurchaseRevenue",
  sessionDuration: "averageSessionDuration",
  averageSessionDuration: "averageSessionDuration",
  sessions: "sessions",
  screenPageViews: "screenPageViews",
  engagedSessions: "engagedSessions",
  sessionKeyEventRate: "sessionKeyEventRate"
};
const DERIVED_CHART_KEYS = {
  returningUsers: ["totalUsers", "newUsers"],
  pageViewsPerUser: ["screenPageViews", "totalUsers"]
};
const OVERVIEW_QUERY = {
  id: "overview",
  dimensions: [
    "date"
  ],
  metrics: OVERVIEW_METRICS,
  compare: true,
  limit: DEFAULT_ROW_LIMIT,
  groupBy: "date"
};
function getOverviewMetricsToRequest(selectedMetrics) {
  if (!Array.isArray(selectedMetrics) || selectedMetrics.length === 0) {
    return DEFAULT_OVERVIEW_METRICS;
  }
  const allowed = new Set(OVERVIEW_METRICS);
  const seen = /* @__PURE__ */ new Set();
  const result = [];
  function addMetric(name) {
    if (!allowed.has(name) || seen.has(name)) {
      return;
    }
    seen.add(name);
    result.push(name);
  }
  for (const key of selectedMetrics) {
    const formula = FORMULA_METRICS[key];
    if (formula) {
      for (const m of formula.metrics) {
        addMetric(m);
      }
      continue;
    }
    const derived = DERIVED_CHART_KEYS[key];
    if (derived) {
      for (const m of derived) {
        addMetric(m);
      }
      continue;
    }
    const apiName = CHART_KEY_TO_OVERVIEW_METRIC[key] || key;
    addMetric(apiName);
  }
  return result.length > 0 ? result : DEFAULT_OVERVIEW_METRICS;
}
function getInjectedMetricNames(selectedMetrics) {
  if (!Array.isArray(selectedMetrics) || selectedMetrics.length === 0) {
    return DEFAULT_OVERVIEW_METRICS;
  }
  const result = [];
  for (const key of selectedMetrics) {
    if (FORMULA_METRICS[key]) {
      result.push(key);
      continue;
    }
    const derived = DERIVED_CHART_KEYS[key];
    if (derived) {
      for (const m of derived) {
        result.push(m);
      }
      continue;
    }
    const apiName = CHART_KEY_TO_OVERVIEW_METRIC[key] || key;
    result.push(apiName);
  }
  return result.length > 0 ? result : DEFAULT_OVERVIEW_METRICS;
}
function getFormulaQueries(selectedMetrics, dateRange, apiFilters) {
  if (!Array.isArray(selectedMetrics)) {
    return [];
  }
  const useCompare = !!(dateRange?.compareReport && dateRange?.compareStart && dateRange?.compareEnd);
  const queries = [];
  for (const key of selectedMetrics) {
    const formula = FORMULA_METRICS[key];
    if (!formula || !formula.dimensions || formula.dimensions.length === 0) {
      continue;
    }
    const dimensions = ["date", ...formula.dimensions];
    const metrics = [...formula.metrics];
    const q = applyFiltersToQuery(
      {
        id: `overview_formula_${key}`,
        dimensions,
        metrics,
        compare: useCompare,
        limit: DEFAULT_ROW_LIMIT,
        ...useCompare && {
          compare_start: dateRange.compareStart,
          compare_end: dateRange.compareEnd
        }
      },
      apiFilters
    );
    queries.push(q);
  }
  return queries;
}
const KEY_METRICS_QUERY = {
  id: "key_metrics",
  dimensions: ["date", "sessionDefaultChannelGroup"],
  metrics: ["sessions", "engagedSessions"],
  compare: true,
  limit: DEFAULT_ROW_LIMIT
};
const CHART_METRICS_QUERY = {
  id: "chart_metrics",
  dimensions: ["date"],
  metrics: ["sessions", "engagedSessions", "totalUsers", "newUsers", "engagementRate"],
  compare: false,
  limit: DEFAULT_ROW_LIMIT
};
const TAB_METRICS_FOR_QUERY = {
  traffic: ["totalUsers", "newUsers", "sessions", "engagementRate"],
  engagement: ["sessions", "screenPageViews", "bounceRate", "averageSessionDuration", "engagementRate", "newUsers", "totalUsers"],
  referrals: ["sessions", "engagedSessions", "sessionKeyEventRate", "totalUsers"],
  ecommerce: ["sessions", "totalRevenue", "ecommercePurchases", "averagePurchaseRevenue", "addToCarts"]
};
function getTabMetricsForQuery(activeTab) {
  const tab = activeTab && TAB_METRICS_FOR_QUERY[activeTab] ? activeTab : "traffic";
  return TAB_METRICS_FOR_QUERY[tab] || TAB_METRICS_FOR_QUERY.traffic;
}
const MARKETING_CAMPAIGNS_METRICS_FULL = ["sessions", "totalUsers", "engagementRate", "totalRevenue", "ecommercePurchases", "averagePurchaseRevenue"];
const MARKETING_CAMPAIGNS_METRICS_LITE = ["sessions", "totalUsers", "engagementRate", "totalRevenue"];
const MARKETING_CAMPAIGNS_QUERIES = [
  { id: "marketing_campaigns_campaign", dimensions: ["sessionCampaignName"], metrics: MARKETING_CAMPAIGNS_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "marketing_campaigns_source", dimensions: ["sessionSource"], metrics: MARKETING_CAMPAIGNS_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "marketing_campaigns_medium", dimensions: ["sessionMedium"], metrics: MARKETING_CAMPAIGNS_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "marketing_campaigns_term", dimensions: ["sessionManualTerm"], metrics: MARKETING_CAMPAIGNS_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "marketing_campaigns_content", dimensions: ["sessionManualAdContent"], metrics: MARKETING_CAMPAIGNS_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT }
];
function getMarketingCampaignsQueries(includeEcommerceMetrics) {
  const metrics = includeEcommerceMetrics ? MARKETING_CAMPAIGNS_METRICS_FULL : MARKETING_CAMPAIGNS_METRICS_LITE;
  return [
    { id: "marketing_campaigns_campaign", dimensions: ["sessionCampaignName"], metrics, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "marketing_campaigns_source", dimensions: ["sessionSource"], metrics, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "marketing_campaigns_medium", dimensions: ["sessionMedium"], metrics, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "marketing_campaigns_term", dimensions: ["sessionManualTerm"], metrics, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "marketing_campaigns_content", dimensions: ["sessionManualAdContent"], metrics, compare: false, limit: DEFAULT_ROW_LIMIT }
  ];
}
const PAGES_METRICS_FULL = ["sessions", "totalUsers", "engagementRate", "totalRevenue", "ecommercePurchases", "averagePurchaseRevenue"];
const PAGES_METRICS_LITE = ["sessions", "totalUsers", "engagementRate", "totalRevenue"];
const PAGES_METRICS_PAGE_LOCATION = ["sessions", "totalUsers", "engagementRate", "purchaseRevenue"];
const PAGES_METRICS_PAGE_LOCATION_LITE = ["sessions", "totalUsers", "engagementRate"];
const PAGES_QUERIES = [
  { id: "pages_landing_page", dimensions: ["landingPagePlusQueryString"], metrics: PAGES_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "pages_page_location", dimensions: ["pageLocation"], metrics: PAGES_METRICS_PAGE_LOCATION, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "pages_page_title", dimensions: ["pageTitle"], metrics: PAGES_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "pages_query_string", dimensions: ["pagePathPlusQueryString"], metrics: PAGES_METRICS_FULL, compare: false, limit: DEFAULT_ROW_LIMIT }
];
function getPagesQueries(includeEcommerceMetrics) {
  if (includeEcommerceMetrics) {
    return PAGES_QUERIES;
  }
  return [
    { id: "pages_landing_page", dimensions: ["landingPagePlusQueryString"], metrics: PAGES_METRICS_LITE, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "pages_page_location", dimensions: ["pageLocation"], metrics: PAGES_METRICS_PAGE_LOCATION_LITE, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "pages_page_title", dimensions: ["pageTitle"], metrics: PAGES_METRICS_LITE, compare: false, limit: DEFAULT_ROW_LIMIT },
    { id: "pages_query_string", dimensions: ["pagePathPlusQueryString"], metrics: PAGES_METRICS_LITE, compare: false, limit: DEFAULT_ROW_LIMIT }
  ];
}
const TOP_PAGES_QUERIES = [
  { id: "top_pages_title", dimensions: ["pageTitle"], metrics: ["sessions"], compare: false, limit: 10 }
];
const CUSTOM_DIMENSIONS_METRICS = ["sessions", "totalUsers", "engagementRate", "totalRevenue", "ecommercePurchases", "averagePurchaseRevenue"];
const CUSTOM_DIMENSIONS_METRICS_LITE = ["sessions", "totalUsers", "engagementRate", "totalRevenue"];
const CUSTOM_DIMENSIONS_QUERIES = [
  { id: "custom_dimensions_logged_in", dimensions: ["customEvent:logged_in"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_post_type", dimensions: ["customEvent:post_type"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_author", dimensions: ["customEvent:author"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_category", dimensions: ["customEvent:category"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_tags", dimensions: ["customEvent:tags"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_focus_keyword", dimensions: ["customEvent:focus_keyword"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_day_of_week", dimensions: ["dayOfWeek"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "custom_dimensions_seo_score", dimensions: ["customEvent:seo_score"], metrics: CUSTOM_DIMENSIONS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT }
];
const CUSTOM_DIMENSIONS_QUERIES_PRIMARY = CUSTOM_DIMENSIONS_QUERIES.slice(0, 5);
const CUSTOM_DIMENSIONS_QUERIES_DEFERRED = CUSTOM_DIMENSIONS_QUERIES.slice(5, 9);
function getCustomDimensionsQueries(includeEcommerceMetrics) {
  const metrics = includeEcommerceMetrics ? CUSTOM_DIMENSIONS_METRICS : CUSTOM_DIMENSIONS_METRICS_LITE;
  return CUSTOM_DIMENSIONS_QUERIES_PRIMARY.map((q) => ({ ...q, metrics }));
}
function getCustomDimensionsDeferredQueries(includeEcommerceMetrics) {
  const metrics = includeEcommerceMetrics ? CUSTOM_DIMENSIONS_METRICS : CUSTOM_DIMENSIONS_METRICS_LITE;
  return CUSTOM_DIMENSIONS_QUERIES_DEFERRED.map((q) => ({
    ...q,
    metrics: (includeEcommerceMetrics ? q.metricsOverride : q.metricsOverrideLite) ?? metrics
  }));
}
const DEMOGRAPHICS_METRICS = ["sessions", "totalRevenue", "engagementRate"];
const DEMOGRAPHICS_QUERIES = [
  { id: "demographics_country", dimensions: ["country"], metrics: DEMOGRAPHICS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "demographics_state", dimensions: ["region"], metrics: DEMOGRAPHICS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "demographics_new_vs_returning", dimensions: ["newVsReturning"], metrics: DEMOGRAPHICS_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT }
];
const DEVICES_METRICS = ["sessions", "totalRevenue", "engagementRate"];
const DEVICES_QUERIES = [
  { id: "devices_browser", dimensions: ["browser"], metrics: DEVICES_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "devices_os", dimensions: ["operatingSystem"], metrics: DEVICES_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT },
  { id: "devices_size", dimensions: ["deviceCategory"], metrics: DEVICES_METRICS, compare: false, limit: DEFAULT_ROW_LIMIT }
];
const FORM_SUBMISSIONS_FILTERS = {
  conditions: [{ field: "customEvent:form_id", match: "notEmpty" }]
};
const FORM_SUBMISSIONS_QUERY_SOURCE_MEDIUM = {
  id: "form_submissions_source_medium",
  dimensions: ["dateHour", "country", "sessionSource", "sessionMedium", "customEvent:form_id"],
  metrics: ["eventCount"],
  compare: false,
  orderBy: [{ field: "dateHour" }],
  limit: DEFAULT_ROW_LIMIT,
  filters: FORM_SUBMISSIONS_FILTERS
};
const FORM_SUBMISSIONS_QUERY_CAMPAIGN = {
  id: "form_submissions_campaign",
  dimensions: ["sessionCampaignName", "country", "sessionSource", "sessionMedium", "customEvent:form_id"],
  metrics: ["eventCount"],
  compare: false,
  orderBy: [{ field: "sessionCampaignName" }],
  limit: DEFAULT_ROW_LIMIT,
  filters: FORM_SUBMISSIONS_FILTERS
};
const FORM_SUBMISSIONS_QUERIES = [
  FORM_SUBMISSIONS_QUERY_SOURCE_MEDIUM,
  FORM_SUBMISSIONS_QUERY_CAMPAIGN
];
const ECOMMERCE_LOG_DIMENSIONS = [
  "dateHour",
  "transactionId",
  "sessionSource",
  "sessionMedium",
  "sessionCampaignName"
];
const ECOMMERCE_LOG_METRICS = ["purchaseRevenue"];
const ECOMMERCE_LOG_QUERY_DATE = {
  id: "ecommerce_log_date",
  dimensions: ECOMMERCE_LOG_DIMENSIONS,
  metrics: ECOMMERCE_LOG_METRICS,
  compare: false,
  orderBy: [{ field: "dateHour", desc: true }],
  limit: DEFAULT_ROW_LIMIT
};
const ECOMMERCE_LOG_QUERY_SOURCE_MEDIUM = {
  id: "ecommerce_log_source_medium",
  dimensions: ECOMMERCE_LOG_DIMENSIONS,
  metrics: ECOMMERCE_LOG_METRICS,
  compare: false,
  orderBy: [{ field: "sessionSource" }, { field: "sessionMedium" }],
  limit: DEFAULT_ROW_LIMIT
};
const ECOMMERCE_LOG_QUERY_CAMPAIGN = {
  id: "ecommerce_log_campaign",
  dimensions: ECOMMERCE_LOG_DIMENSIONS,
  metrics: ECOMMERCE_LOG_METRICS,
  compare: false,
  orderBy: [{ field: "sessionCampaignName" }],
  limit: DEFAULT_ROW_LIMIT
};
const ECOMMERCE_DATA_QUERY = {
  id: "ecommerce_data",
  dimensions: ["itemName", "orderCoupon"],
  metrics: ["itemRevenue", "itemsPurchased"],
  compare: false,
  limit: DEFAULT_ROW_LIMIT
};
const QUERY_DIMENSIONS = Object.fromEntries(
  [
    ...MARKETING_CAMPAIGNS_QUERIES,
    ...PAGES_QUERIES,
    ...CUSTOM_DIMENSIONS_QUERIES,
    ...DEMOGRAPHICS_QUERIES,
    ...DEVICES_QUERIES,
    ...FORM_SUBMISSIONS_QUERIES,
    ECOMMERCE_LOG_QUERY_DATE,
    ECOMMERCE_LOG_QUERY_SOURCE_MEDIUM,
    ECOMMERCE_LOG_QUERY_CAMPAIGN,
    ECOMMERCE_DATA_QUERY
  ].map((q) => [q.id, q.dimensions])
);
function buildApiFilters(filterRows, device = "") {
  const conditions = [];
  if (Array.isArray(filterRows)) {
    for (const row of filterRows) {
      if (!row.type || row.value == null || String(row.value).trim() === "") {
        continue;
      }
      conditions.push({
        field: row.type,
        type: "dimension",
        match: row.condition === "is_not" ? "not_equal" : "exact",
        value: String(row.value).trim(),
        caseSensitive: false
      });
    }
  }
  if (device && ["desktop", "mobile", "tablet"].includes(device)) {
    conditions.push({
      field: "deviceCategory",
      type: "dimension",
      match: "exact",
      value: device,
      caseSensitive: false
    });
  }
  if (conditions.length === 0) {
    return null;
  }
  return { operator: "and", conditions };
}
function mapFunnelStepsToApi(steps) {
  if (!Array.isArray(steps) || steps.length === 0) {
    return [];
  }
  return steps.filter((s) => s && String(s.value || "").trim()).map((s) => {
    const value = String(s.value).trim();
    if (s.type === "event") {
      return { name: value, eventName: value };
    }
    return { name: value, eventName: "page_view" };
  });
}
function buildFunnelRequestBody(dateRange, activeFunnel, apiFilters = null) {
  const apiSteps = mapFunnelStepsToApi(activeFunnel?.steps || []);
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  const hasFilters = apiFilters && Array.isArray(apiFilters.conditions) && apiFilters.conditions.length > 0;
  const body = {
    start,
    end,
    funnel: {
      isOpenFunnel: false,
      steps: apiSteps
    },
    funnelBreakdown: { dimension: "deviceCategory", limit: 5 },
    funnelVisualizationType: "STANDARD_FUNNEL",
    limit: 100,
    returnPropertyQuota: false
  };
  if (hasFilters) {
    body.filters = apiFilters;
  }
  return body;
}
function funnelCacheKeyFrom(dateRange, activeFunnel, apiFilters) {
  return {
    start: dateRange?.start,
    end: dateRange?.end,
    funnel: activeFunnel ?? null,
    filters: apiFilters ?? null
  };
}
function formatFunnelResponse(decodedBody) {
  if (decodedBody?.success && decodedBody?.data) {
    return decodedBody.data;
  }
  if (decodedBody?.data) {
    return decodedBody.data;
  }
  return decodedBody ?? null;
}
async function directFetchFunnelFromRelay(dateRange, activeFunnel, apiFilters) {
  const body = buildFunnelRequestBody(dateRange, activeFunnel, apiFilters);
  return relayFunnel(body);
}
const funnelCachedFetch = useCachedFetch({
  cacheKeyPrefix: "overview_funnel",
  cacheKeyFrom: (...args) => funnelCacheKeyFrom(...args),
  wpFetch: async (cacheKey, _dateRange, _activeFunnel, apiFilters) => getBackfillCache(cacheKey, OVERVIEW_CACHE_GROUP, {
    api_filters: apiFilters ?? null
  }),
  directFetch: directFetchFunnelFromRelay,
  canDirectFetch: () => !isSampleDataEnabled() && !!getMiGlobal("bearer_token"),
  backfill: async (dateRange, activeFunnel, apiFilters, rawData) => {
    const cacheKey = buildCacheKey("overview_funnel", funnelCacheKeyFrom, dateRange, activeFunnel, apiFilters);
    const formatted = formatFunnelResponse(rawData);
    await backfillToWp(OVERVIEW_CACHE_GROUP, cacheKey, formatted);
  },
  formatResponse: (rawData) => formatFunnelResponse(rawData)
});
const fetchFunnelData = async (dateRange, activeFunnel, apiFilters = null) => {
  if (!isAddonActive("ecommerce")) {
    return null;
  }
  if (isSampleDataEnabled()) {
    return generateSampleFunnelData({ apiFilters });
  }
  const reportingApi = getMiGlobal("reporting_api", {});
  const canUseBearer = await ensureBearerToken();
  if (!canUseBearer && (!reportingApi.url || !reportingApi.key || !reportingApi.token)) {
    return Promise.reject({
      title: __("Error loading funnel data", "google-analytics-for-wordpress"),
      message: __("Reporting API credentials are not available.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  if (!start || !end) {
    return Promise.reject({
      title: __("Error loading funnel data", "google-analytics-for-wordpress"),
      message: __("Start and end dates are required.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  if (!activeFunnel || !Array.isArray(activeFunnel.steps) || activeFunnel.steps.length < 2) {
    return Promise.reject({
      title: __("Error loading funnel data", "google-analytics-for-wordpress"),
      message: __("A funnel with at least two steps is required.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  try {
    return await funnelCachedFetch.fetchWithCache(dateRange, activeFunnel, apiFilters);
  } catch (err) {
    return rejectReport(__("Error loading funnel data", "google-analytics-for-wordpress"), err?.message);
  }
};
function applyFiltersToQuery(query, apiFilters) {
  if (!apiFilters || !apiFilters.conditions?.length) {
    return query;
  }
  const hasExisting = query.filters && Array.isArray(query.filters.conditions);
  const filters = hasExisting ? { operator: "and", conditions: [...query.filters.conditions, ...apiFilters.conditions] } : apiFilters;
  return { ...query, filters };
}
function formatMarketingResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid marketing response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    campaign: data?.marketing_campaigns_campaign ?? null,
    source: data?.marketing_campaigns_source ?? null,
    medium: data?.marketing_campaigns_medium ?? null,
    term: data?.marketing_campaigns_term ?? null,
    content: data?.marketing_campaigns_content ?? null
  };
}
function formatPagesResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid pages response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    landingPage: data?.pages_landing_page ?? null,
    pageLocation: data?.pages_page_location ?? null,
    pageTitle: data?.pages_page_title ?? null,
    queryString: data?.pages_query_string ?? null
  };
}
function formatTopPagesResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid top pages response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return data?.top_pages_title ?? null;
}
function formatFormSubmissionsResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid form submissions response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    sourceMedium: data?.form_submissions_source_medium ?? null,
    campaign: data?.form_submissions_campaign ?? null
  };
}
function formatEcommerceOverviewResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid ecommerce response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    ecommerce_log_date: data?.ecommerce_log_date ?? null,
    ecommerce_log_source_medium: data?.ecommerce_log_source_medium ?? null,
    ecommerce_log_campaign: data?.ecommerce_log_campaign ?? null,
    ecommerce_data: data?.ecommerce_data ?? null
  };
}
function formatDemographicsResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid demographics response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    country: data?.demographics_country ?? null,
    state: data?.demographics_state ?? null,
    newVsReturning: data?.demographics_new_vs_returning ?? null
  };
}
function formatDevicesResponse(decodedBody) {
  if (!decodedBody?.success || !decodedBody?.data) {
    throw new Error("Invalid devices response");
  }
  const data = decodedBody.data?.data ?? decodedBody.data;
  return {
    browser: data?.devices_browser ?? null,
    os: data?.devices_os ?? null,
    size: data?.devices_size ?? null
  };
}
function overviewBundleCacheKeyFrom(dateRange, apiFilters) {
  return { start: dateRange?.start, end: dateRange?.end, filters: apiFilters };
}
async function directFetchOverviewBundle(dateRange, apiFilters) {
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  const hasFormsAddon = isAddonActive("forms");
  const hasEcommerceAddon = isAddonActive("ecommerce");
  const hasPageInsightsAddon = isAddonActive("page_insights");
  const marketingQueries = MARKETING_CAMPAIGNS_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const demographicsQueries = DEMOGRAPHICS_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const devicesQueries = DEVICES_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const topPagesQueries = TOP_PAGES_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const requests = [];
  const requestKeys = [];
  requests.push(relayReportingQuery({ start, end, queries: marketingQueries }));
  requestKeys.push("marketing");
  requests.push(relayReportingQuery({ start, end, queries: topPagesQueries }));
  requestKeys.push("top_pages");
  if (hasPageInsightsAddon) {
    const pagesQueries = PAGES_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
    requests.push(relayReportingQuery({ start, end, queries: pagesQueries }));
    requestKeys.push("pages");
  }
  if (hasFormsAddon) {
    const formQueries = FORM_SUBMISSIONS_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
    requests.push(relayReportingQuery({ start, end, queries: formQueries }));
    requestKeys.push("forms");
  }
  if (hasEcommerceAddon) {
    const logDateQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_DATE }, apiFilters);
    const logSourceMediumQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_SOURCE_MEDIUM }, apiFilters);
    const logCampaignQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_CAMPAIGN }, apiFilters);
    const dataQuery = applyFiltersToQuery({ ...ECOMMERCE_DATA_QUERY }, apiFilters);
    requests.push(relayReportingQuery({
      start,
      end,
      queries: [logDateQuery, logSourceMediumQuery, logCampaignQuery, dataQuery]
    }));
    requestKeys.push("ecommerce");
  }
  requests.push(relayReportingQuery({ start, end, queries: demographicsQueries }));
  requestKeys.push("demographics");
  requests.push(relayReportingQuery({ start, end, queries: devicesQueries }));
  requestKeys.push("devices");
  const results = await Promise.all(requests);
  const resultMap = {};
  requestKeys.forEach((key, idx) => {
    resultMap[key] = results[idx];
  });
  return {
    marketing_campaigns: formatMarketingResponse(resultMap.marketing),
    top_pages_title: formatTopPagesResponse(resultMap.top_pages),
    pages: resultMap.pages ? formatPagesResponse(resultMap.pages) : null,
    form_submissions: resultMap.forms ? formatFormSubmissionsResponse(resultMap.forms) : null,
    ecommerce_overview: resultMap.ecommerce ? formatEcommerceOverviewResponse(resultMap.ecommerce) : null,
    demographics: formatDemographicsResponse(resultMap.demographics),
    devices: formatDevicesResponse(resultMap.devices)
  };
}
const overviewBundleCachedFetch = useCachedFetch({
  // _v2: invalidate bundles cached before top_pages_title was added, so a fresh bundle (which
  // includes top_pages_title) is written instead of a stale one that never regains the key.
  cacheKeyPrefix: "overview_bundle_v2",
  cacheKeyFrom: (...args) => overviewBundleCacheKeyFrom(...args),
  wpFetch: async (cacheKey, _dateRange, apiFilters) => getBackfillCache(cacheKey, OVERVIEW_CACHE_GROUP, {
    api_filters: apiFilters ?? null
  }),
  directFetch: directFetchOverviewBundle,
  canDirectFetch: () => !isSampleDataEnabled() && !!getMiGlobal("bearer_token"),
  backfill: async (dateRange, apiFilters, rawData) => {
    const cacheKey = buildCacheKey("overview_bundle_v2", overviewBundleCacheKeyFrom, dateRange, apiFilters);
    await backfillToWp(OVERVIEW_CACHE_GROUP, cacheKey, rawData);
  },
  formatResponse: (raw) => raw
});
const overviewBundleInFlight = /* @__PURE__ */ new Map();
async function getOverviewBundle(dateRange, apiFilters) {
  if (isSampleDataEnabled()) {
    return generateSampleBundleData({ dateRange, apiFilters });
  }
  const key = overviewBundleCachedFetch.generateCacheKey(dateRange, apiFilters);
  if (overviewBundleInFlight.has(key)) {
    return overviewBundleInFlight.get(key);
  }
  const p = overviewBundleCachedFetch.fetchWithCache(dateRange, apiFilters).finally(() => overviewBundleInFlight.delete(key));
  overviewBundleInFlight.set(key, p);
  return p;
}
const fetchOverviewData = async (dateRange, apiFilters = null, selectedMetrics = null, activeTab = null) => {
  if (isSampleDataEnabled()) {
    const overviewMetricsToRequest = getOverviewMetricsToRequest(selectedMetrics);
    const raw = generateSampleOverviewData({
      dateRange,
      apiFilters,
      selectedMetrics,
      activeTab,
      overviewMetricsToRequest
    });
    return formatOverviewResponse({ success: true, data: raw }, dateRange, selectedMetrics);
  }
  const canUseBearer = await ensureBearerToken() || !!getMiGlobal("bearer_token");
  if (!canUseBearer) {
    return Promise.reject({
      title: __("Error loading overview data", "google-analytics-for-wordpress"),
      message: __("Unable to get authentication token. Please refresh the page.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  if (!start || !end) {
    return Promise.reject({
      title: __("Error loading overview data", "google-analytics-for-wordpress"),
      message: __("Start and end dates are required.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  try {
    return await overviewCachedFetch.fetchWithCache(dateRange, apiFilters, selectedMetrics, activeTab);
  } catch (err) {
    const supportUrl = getMonsterInsightsUrl(
      "admin-notices",
      "error-overview-api",
      "https://www.monsterinsights.com/my-account/support"
    );
    const message = err?.message || __("An unknown error occurred.", "google-analytics-for-wordpress");
    return Promise.reject({
      title: __("Error loading overview data", "google-analytics-for-wordpress"),
      message,
      support_url: supportUrl,
      isAjaxError: true
    });
  }
};
async function fetchOverviewSection({ dateRange, errorLabel, onBearer, onFallback }) {
  if (isSampleDataEnabled()) {
    return onBearer({ start: dateRange?.start || "", end: dateRange?.end || "", reportingApi: {} });
  }
  const reportingApi = getMiGlobal("reporting_api", {});
  const canUseBearer = await ensureBearerToken();
  if (!canUseBearer && (!reportingApi.url || !reportingApi.key || !reportingApi.token)) {
    return Promise.reject({
      title: errorLabel,
      message: __("Reporting API credentials are not available.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  if (!start || !end) {
    return Promise.reject({
      title: errorLabel,
      message: __("Start and end dates are required.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  if (canUseBearer) {
    try {
      return await onBearer({ start, end, reportingApi });
    } catch (err) {
      return rejectReport(errorLabel, err?.message);
    }
  }
  return onFallback({ start, end, reportingApi });
}
const fetchMarketingCampaignsData = async (dateRange, apiFilters = null, includeEcommerceMetrics = true) => {
  const marketingQueries = getMarketingCampaignsQueries(includeEcommerceMetrics).map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const errorLabel = __("Error loading marketing campaigns data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async ({ start, end }) => {
      if (includeEcommerceMetrics) {
        const bundle = await getOverviewBundle(dateRange, apiFilters);
        return bundle?.marketing_campaigns ?? null;
      }
      const marketingBody = await relayReportingQuery({ start, end, queries: marketingQueries });
      return formatMarketingResponse(marketingBody);
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries: marketingQueries },
      formatMarketingResponse,
      errorLabel
    )
  });
};
const fetchPagesData = async (dateRange, apiFilters = null, includeEcommerceMetrics = true) => {
  if (!isAddonActive("page_insights")) {
    return null;
  }
  const pagesQueries = getPagesQueries(includeEcommerceMetrics).map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const errorLabel = __("Error loading pages data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async ({ start, end }) => {
      if (includeEcommerceMetrics) {
        const bundle = await getOverviewBundle(dateRange, apiFilters);
        return bundle?.pages ?? null;
      }
      const pagesBody = await relayReportingQuery({ start, end, queries: pagesQueries });
      return formatPagesResponse(pagesBody);
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries: pagesQueries },
      formatPagesResponse,
      errorLabel
    )
  });
};
const fetchTopPagesData = async (dateRange, apiFilters = null) => {
  if (isSampleDataEnabled()) {
    const bundle = generateSampleBundleData({ dateRange, apiFilters });
    return bundle?.top_pages_title ?? null;
  }
  const queries = TOP_PAGES_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const errorLabel = __("Error loading top pages data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async () => {
      const bundle = await getOverviewBundle(dateRange, apiFilters);
      return bundle?.top_pages_title ?? null;
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries },
      formatTopPagesResponse,
      errorLabel
    )
  });
};
const fetchCustomDimensionsData = async (dateRange, apiFilters = null, includeEcommerceMetrics = true) => {
  if (!isAddonActive("dimensions")) {
    return null;
  }
  if (isSampleDataEnabled()) {
    return generateSampleCustomDimensionsData({ apiFilters });
  }
  const canUseBearer = await ensureBearerToken() || !!getMiGlobal("bearer_token");
  if (!canUseBearer) {
    return Promise.reject({
      title: __("Error loading custom dimensions data", "google-analytics-for-wordpress"),
      message: __("Unable to get authentication token. Please refresh the page.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  if (!start || !end) {
    return Promise.reject({
      title: __("Error loading custom dimensions data", "google-analytics-for-wordpress"),
      message: __("Start and end dates are required.", "google-analytics-for-wordpress"),
      support_url: getMonsterInsightsUrl(
        "admin-notices",
        "error-overview-api",
        "https://www.monsterinsights.com/my-account/support"
      ),
      isAjaxError: true
    });
  }
  try {
    return await customDimensionsCachedFetch.fetchWithCache(dateRange, apiFilters, includeEcommerceMetrics);
  } catch (err) {
    const supportUrl = getMonsterInsightsUrl(
      "admin-notices",
      "error-overview-api",
      "https://www.monsterinsights.com/my-account/support"
    );
    return Promise.reject({
      title: __("Error loading custom dimensions data", "google-analytics-for-wordpress"),
      message: err?.message || __("An unknown error occurred.", "google-analytics-for-wordpress"),
      support_url: supportUrl,
      isAjaxError: true
    });
  }
};
const fetchCustomDimensionsDeferredData = async (dateRange, apiFilters = null, includeEcommerceMetrics = true) => {
  if (!isAddonActive("dimensions")) {
    return { focusKeyword: null, dayOfWeek: null, seoScore: null, focusKeyphrase: null };
  }
  if (isSampleDataEnabled()) {
    const full = generateSampleCustomDimensionsData({ apiFilters });
    return {
      focusKeyword: full?.focusKeyword ?? null,
      dayOfWeek: full?.dayOfWeek ?? null,
      seoScore: full?.seoScore ?? null,
      focusKeyphrase: full?.focusKeyphrase ?? null
    };
  }
  const start = dateRange?.start || "";
  const end = dateRange?.end || "";
  if (!start || !end) {
    return { focusKeyword: null, dayOfWeek: null, seoScore: null, focusKeyphrase: null };
  }
  try {
    return await customDimensionsDeferredCachedFetch.fetchWithCache(dateRange, apiFilters, includeEcommerceMetrics);
  } catch (_err) {
    return { focusKeyword: null, dayOfWeek: null, seoScore: null, focusKeyphrase: null };
  }
};
const fetchFormSubmissionsData = async (dateRange, apiFilters = null) => {
  if (!isAddonActive("forms")) {
    return null;
  }
  const errorLabel = __("Error loading form submissions data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async () => {
      const bundle = await getOverviewBundle(dateRange, apiFilters);
      return bundle?.form_submissions ?? null;
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      {
        start,
        end,
        queries: FORM_SUBMISSIONS_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters))
      },
      formatFormSubmissionsResponse,
      errorLabel
    )
  });
};
const fetchEcommerceOverviewData = async (dateRange, apiFilters = null) => {
  if (!isAddonActive("ecommerce")) {
    return null;
  }
  const logDateQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_DATE }, apiFilters);
  const logSourceMediumQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_SOURCE_MEDIUM }, apiFilters);
  const logCampaignQuery = applyFiltersToQuery({ ...ECOMMERCE_LOG_QUERY_CAMPAIGN }, apiFilters);
  const dataQuery = applyFiltersToQuery({ ...ECOMMERCE_DATA_QUERY }, apiFilters);
  const errorLabel = __("Error loading eCommerce data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async () => {
      const bundle = await getOverviewBundle(dateRange, apiFilters);
      return bundle?.ecommerce_overview ?? null;
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries: [logDateQuery, logSourceMediumQuery, logCampaignQuery, dataQuery] },
      formatEcommerceOverviewResponse,
      errorLabel
    )
  });
};
const fetchDemographicsData = async (dateRange, apiFilters = null) => {
  const demographicsQueries = DEMOGRAPHICS_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const errorLabel = __("Error loading demographics data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async () => {
      const bundle = await getOverviewBundle(dateRange, apiFilters);
      return bundle?.demographics ?? null;
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries: demographicsQueries },
      formatDemographicsResponse,
      errorLabel
    )
  });
};
const fetchDevicesData = async (dateRange, apiFilters = null) => {
  const devicesQueries = DEVICES_QUERIES.map((q) => applyFiltersToQuery({ ...q }, apiFilters));
  const errorLabel = __("Error loading devices data", "google-analytics-for-wordpress");
  return fetchOverviewSection({
    dateRange,
    apiFilters,
    errorLabel,
    onBearer: async () => {
      const bundle = await getOverviewBundle(dateRange, apiFilters);
      return bundle?.devices ?? null;
    },
    onFallback: ({ start, end }) => relayFallbackFetch(
      "api/v3/reporting/query",
      { start, end, queries: devicesQueries },
      formatDevicesResponse,
      errorLabel
    )
  });
};
const dimensionValuesCache = /* @__PURE__ */ new Map();
async function fetchDimensionValues(dimension, dateRange, apiFilters = null) {
  if (!dimension || !dateRange?.start || !dateRange?.end) {
    return [];
  }
  const cacheKey = `${dimension}|${dateRange.start}|${dateRange.end}|${JSON.stringify(apiFilters ?? "")}`;
  if (dimensionValuesCache.has(cacheKey)) {
    return dimensionValuesCache.get(cacheKey);
  }
  if (isSampleDataEnabled()) {
    return [];
  }
  const sanitizedDimension = dimension.replace(/[^a-zA-Z0-9_-]/g, "_");
  const queryId = `dimension_values_${sanitizedDimension}`;
  const query = {
    id: queryId,
    dimensions: [dimension],
    metrics: ["sessions"],
    compare: false,
    limit: DEFAULT_ROW_LIMIT
  };
  const queryWithFilters = applyFiltersToQuery(query, apiFilters);
  try {
    const canUseBearer = await ensureBearerToken() || !!getMiGlobal("bearer_token");
    if (!canUseBearer) {
      return [];
    }
    const body = {
      start: dateRange.start,
      end: dateRange.end,
      queries: [queryWithFilters]
    };
    const decodedBody = await relayReportingQuery(body);
    let data = null;
    if (decodedBody?.success && decodedBody?.data) {
      data = decodedBody.data?.data ?? decodedBody.data;
    } else if (decodedBody?.data) {
      data = decodedBody.data?.data ?? decodedBody.data;
    }
    const queryResult = data?.[queryId];
    const rows = queryResult?.rows ?? [];
    const seen = /* @__PURE__ */ new Set();
    const values = [];
    for (const row of rows) {
      const val = row?.d?.[0];
      if (val != null && String(val).trim() !== "" && !seen.has(String(val))) {
        seen.add(String(val));
        values.push({ value: String(val), label: String(val) });
      }
    }
    values.sort((a, b) => a.label.localeCompare(b.label));
    dimensionValuesCache.set(cacheKey, values);
    return values;
  } catch {
    return [];
  }
}
const DIMENSION_STORE_MAP = {
  // Marketing Campaigns
  sessionCampaignName: { storeKey: "marketingCampaigns", tabKey: "campaign" },
  sessionSource: { storeKey: "marketingCampaigns", tabKey: "source" },
  sessionMedium: { storeKey: "marketingCampaigns", tabKey: "medium" },
  sessionManualTerm: { storeKey: "marketingCampaigns", tabKey: "term" },
  sessionManualAdContent: { storeKey: "marketingCampaigns", tabKey: "content" },
  // Pages
  landingPagePlusQueryString: { storeKey: "pages", tabKey: "landingPage" },
  pageTitle: { storeKey: "pages", tabKey: "pageTitle" },
  // Custom Dimensions
  "customUser:logged_in": { storeKey: "customDimensions", tabKey: "loggedIn" },
  "customEvent:post_type": { storeKey: "customDimensions", tabKey: "postType" },
  "customEvent:author": { storeKey: "customDimensions", tabKey: "author" },
  "customEvent:category": { storeKey: "customDimensions", tabKey: "category" },
  "customEvent:tags": { storeKey: "customDimensions", tabKey: "tags" },
  "customEvent:focus_keyword": { storeKey: "customDimensions", tabKey: "focusKeyword" },
  dayOfWeek: { storeKey: "customDimensions", tabKey: "dayOfWeek" },
  "customEvent:seo_score": { storeKey: "customDimensions", tabKey: "seoScore" },
  "customEvent:focus_keyphrase": { storeKey: "customDimensions", tabKey: "focusKeyphrase" },
  // Demographics
  country: { storeKey: "demographics", tabKey: "country" },
  region: { storeKey: "demographics", tabKey: "state" },
  // Devices
  browser: { storeKey: "devices", tabKey: "browser" },
  operatingSystem: { storeKey: "devices", tabKey: "os" },
  deviceCategory: { storeKey: "devices", tabKey: "size" }
};
const FORM_SUBMISSIONS_DIMENSION_TAB = {
  dateHour: "sourceMedium",
  sessionCampaignName: "campaign"
};
function getValuesForDimension(dimensionKey, storeData) {
  if (!dimensionKey || !storeData) {
    return [];
  }
  const mapping = DIMENSION_STORE_MAP[dimensionKey];
  if (!mapping) {
    return [];
  }
  const sourceData = storeData[mapping.storeKey];
  if (!sourceData) {
    return [];
  }
  const tabData = sourceData[mapping.tabKey];
  if (!tabData) {
    return [];
  }
  const rows = Array.isArray(tabData?.rows) ? tabData.rows : Array.isArray(tabData) ? tabData : [];
  if (rows.length === 0) {
    return [];
  }
  const tabToQueryId = STORE_TAB_TO_QUERY_ID[mapping.storeKey];
  const queryId = tabToQueryId?.[mapping.tabKey];
  const dimensionsOrder = queryId ? QUERY_DIMENSIONS[queryId] : null;
  const responseOrder = dimensionsOrder ? getResponseDimensionOrder(dimensionsOrder) : [];
  const dimIndex = responseOrder.length ? responseOrder.indexOf(dimensionKey) : 0;
  const useIndex = dimIndex >= 0 ? dimIndex : 0;
  const uniqueValues = /* @__PURE__ */ new Set();
  rows.forEach((row) => {
    const val = row?.d?.[useIndex];
    if (val !== void 0 && val !== null && String(val).trim() !== "") {
      uniqueValues.add(String(val));
    }
  });
  return Array.from(uniqueValues).sort((a, b) => a.localeCompare(b)).map((val) => ({ value: val, label: val }));
}
const MC_DIMENSION_TAB = {
  sessionCampaignName: "campaign",
  sessionSource: "source",
  sessionMedium: "medium",
  sessionManualTerm: "term",
  sessionManualAdContent: "content"
};
const PAGES_DIMENSION_TAB = {
  landingPagePlusQueryString: "landingPage",
  pageLocation: "pageLocation",
  pageTitle: "pageTitle",
  pagePathPlusQueryString: "queryString"
};
const CUSTOM_DIMENSIONS_DIMENSION_TAB = {
  "customUser:logged_in": "loggedIn",
  "customEvent:post_type": "postType",
  "customEvent:author": "author",
  "customEvent:category": "category",
  "customEvent:tags": "tags",
  "customEvent:focus_keyword": "focusKeyword",
  dayOfWeek: "dayOfWeek",
  "customEvent:seo_score": "seoScore",
  "customEvent:focus_keyphrase": "focusKeyphrase"
};
const DEMOGRAPHICS_DIMENSION_TAB = {
  country: "country",
  region: "state",
  newVsReturning: "newVsReturning"
};
const DEVICES_DIMENSION_TAB = {
  browser: "browser",
  operatingSystem: "os",
  deviceCategory: "size"
};
function getResponseDimensionOrder(dimensionsOrder) {
  if (!dimensionsOrder || dimensionsOrder.length === 0) {
    return [];
  }
  return [...dimensionsOrder].sort();
}
function aggregateRowsByPrimaryDimension(rows, primaryIndexInResponse) {
  if (!rows || rows.length === 0) {
    return rows;
  }
  const byPrimary = /* @__PURE__ */ new Map();
  for (const row of rows) {
    const d = row?.d ?? [];
    const primaryValue = d[primaryIndexInResponse];
    const primaryKey = primaryValue !== void 0 && primaryValue !== null ? String(primaryValue) : "";
    const m0 = row?.m?.[0];
    const metrics = Array.isArray(m0) ? m0.map((v) => parseFloat(v) || 0) : [];
    if (!byPrimary.has(primaryKey)) {
      byPrimary.set(primaryKey, { d: [primaryValue], m: [metrics] });
    } else {
      const existing = byPrimary.get(primaryKey);
      const existingMetrics = existing.m[0];
      for (let i = 0; i < metrics.length; i++) {
        existingMetrics[i] = (existingMetrics[i] || 0) + (metrics[i] || 0);
      }
    }
  }
  return Array.from(byPrimary.values());
}
function filterByDimensionsOrder(rawTabData, dimensionsOrder, activeFilters, primaryDimensionKey) {
  if (!rawTabData) {
    return rawTabData;
  }
  if (!dimensionsOrder || dimensionsOrder.length === 0) {
    return rawTabData;
  }
  const rows = Array.isArray(rawTabData?.rows) ? rawTabData.rows : Array.isArray(rawTabData) ? rawTabData : [];
  if (rows.length === 0) {
    return rawTabData;
  }
  const responseOrder = getResponseDimensionOrder(dimensionsOrder);
  let resultRows = rows;
  if (activeFilters && activeFilters.length > 0) {
    const applicableFilters = activeFilters.filter((f) => responseOrder.includes(f.type)).map((f) => ({
      ...f,
      dIndex: responseOrder.indexOf(f.type)
    }));
    if (applicableFilters.length > 0) {
      resultRows = rows.filter((row) => {
        const d = row?.d ?? [];
        return applicableFilters.every((filter) => {
          const dimVal = String(d[filter.dIndex] ?? "");
          if (filter.condition === "is") {
            return dimVal === filter.value;
          }
          if (filter.condition === "is_not") {
            return dimVal !== filter.value;
          }
          return true;
        });
      });
    }
  }
  if (dimensionsOrder.length > 1 && primaryDimensionKey && responseOrder.includes(primaryDimensionKey)) {
    const primaryIndexInResponse = responseOrder.indexOf(primaryDimensionKey);
    resultRows = aggregateRowsByPrimaryDimension(resultRows, primaryIndexInResponse);
  }
  if (rawTabData?.rows) {
    return { ...rawTabData, rows: resultRows };
  }
  return resultRows;
}
const MC_TAB_TO_QUERY_ID = {
  campaign: "marketing_campaigns_campaign",
  source: "marketing_campaigns_source",
  medium: "marketing_campaigns_medium",
  term: "marketing_campaigns_term",
  content: "marketing_campaigns_content"
};
const PAGES_TAB_TO_QUERY_ID = {
  landingPage: "pages_landing_page",
  pageLocation: "pages_page_location",
  pageTitle: "pages_page_title",
  queryString: "pages_query_string"
};
const CUSTOM_DIMENSIONS_TAB_TO_QUERY_ID = {
  loggedIn: "custom_dimensions_logged_in",
  postType: "custom_dimensions_post_type",
  author: "custom_dimensions_author",
  category: "custom_dimensions_category",
  tags: "custom_dimensions_tags",
  focusKeyword: "custom_dimensions_focus_keyword",
  dayOfWeek: "custom_dimensions_day_of_week",
  seoScore: "custom_dimensions_seo_score",
  focusKeyphrase: "custom_dimensions_focus_keyphrase"
};
const DEMOGRAPHICS_TAB_TO_QUERY_ID = {
  country: "demographics_country",
  state: "demographics_state",
  newVsReturning: "demographics_new_vs_returning"
};
const DEVICES_TAB_TO_QUERY_ID = {
  browser: "devices_browser",
  os: "devices_os",
  size: "devices_size"
};
const FORM_SUBMISSIONS_TAB_TO_QUERY_ID = {
  sourceMedium: "form_submissions_source_medium",
  campaign: "form_submissions_campaign"
};
const STORE_TAB_TO_QUERY_ID = {
  marketingCampaigns: MC_TAB_TO_QUERY_ID,
  pages: PAGES_TAB_TO_QUERY_ID,
  customDimensions: CUSTOM_DIMENSIONS_TAB_TO_QUERY_ID,
  demographics: DEMOGRAPHICS_TAB_TO_QUERY_ID,
  devices: DEVICES_TAB_TO_QUERY_ID,
  formSubmissions: FORM_SUBMISSIONS_TAB_TO_QUERY_ID
};
function filterFormSubmissionsData(rawTabbedData, activeFilters) {
  if (!rawTabbedData || !activeFilters || activeFilters.length === 0) {
    return rawTabbedData;
  }
  const result = { ...rawTabbedData };
  for (const tabKey of Object.values(FORM_SUBMISSIONS_DIMENSION_TAB)) {
    if (!result[tabKey]) {
      continue;
    }
    const queryId = FORM_SUBMISSIONS_TAB_TO_QUERY_ID[tabKey];
    const dimensionsOrder = queryId ? QUERY_DIMENSIONS[queryId] : null;
    if (!dimensionsOrder) {
      continue;
    }
    const responseOrder = getResponseDimensionOrder(dimensionsOrder);
    const rows = Array.isArray(result[tabKey]?.rows) ? result[tabKey].rows : [];
    if (rows.length === 0) {
      continue;
    }
    const applicableFilters = activeFilters.filter((f) => responseOrder.includes(f.type)).map((f) => ({ ...f, dIndex: responseOrder.indexOf(f.type) }));
    if (applicableFilters.length === 0) {
      continue;
    }
    const filteredRows = rows.filter((row) => {
      const d = row?.d ?? [];
      return applicableFilters.every((filter) => {
        const dimVal = String(d[filter.dIndex] ?? "");
        if (filter.condition === "is") {
          return dimVal === filter.value;
        }
        if (filter.condition === "is_not") {
          return dimVal !== filter.value;
        }
        return true;
      });
    });
    result[tabKey] = { ...result[tabKey], rows: filteredRows };
  }
  return result;
}
function filterTabbedData(rawTabbedData, dimensionTabMap, activeFilters, tabToQueryId) {
  if (!rawTabbedData) {
    return rawTabbedData;
  }
  const result = { ...rawTabbedData };
  for (const [primaryDimensionKey, tabKey] of Object.entries(dimensionTabMap)) {
    if (!result[tabKey]) {
      continue;
    }
    const queryId = tabToQueryId[tabKey];
    const dimensionsOrder = queryId ? QUERY_DIMENSIONS[queryId] : null;
    if (dimensionsOrder) {
      result[tabKey] = filterByDimensionsOrder(
        result[tabKey],
        dimensionsOrder,
        activeFilters,
        primaryDimensionKey
      );
    }
  }
  return result;
}
function dimensionToLabel(dim) {
  if (dim.startsWith("customEvent:")) {
    const suffix = dim.slice("customEvent:".length);
    const label = suffix.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
    return `Custom Event: ${label}`;
  }
  if (dim.includes("CustomChannelGroup:")) {
    const parts = dim.split(":");
    const prefix = camelToWords(parts[0]);
    return `${prefix}: ${parts[1]}`;
  }
  return camelToWords(dim);
}
function camelToWords(str) {
  const abbreviations = {
    cm360: "CM360",
    dv360: "DV360",
    sa360: "SA360",
    id: "ID",
    url: "URL",
    os: "OS",
    ip: "IP",
    api: "API",
    aioseo: "AIOSEO",
    seo: "SEO",
    utm: "UTM",
    wp: "WP"
  };
  let result = str.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2");
  result = result.split(" ").map((word) => {
    const lower = word.toLowerCase();
    if (abbreviations[lower]) {
      return abbreviations[lower];
    }
    return word.charAt(0).toUpperCase() + word.slice(1);
  }).join(" ");
  return result;
}
const ALL_DIMENSIONS = [
  "achievementId",
  "adFormat",
  "adSourceName",
  "adUnitName",
  "appVersion",
  "audienceId",
  "audienceName",
  "audienceResourceName",
  "brandingInterest",
  "browser",
  "character",
  "city",
  "cityId",
  "cohort",
  "comparison",
  "contentGroup",
  "contentId",
  "contentType",
  "continent",
  "continentId",
  "country",
  "countryId",
  "currencyCode",
  "customEvent:action",
  "customEvent:affiliate_label",
  "customEvent:aioseo_focus_keyphrase",
  "customEvent:aioseo_truseo_score",
  "customEvent:author",
  "customEvent:category",
  "customEvent:email_address",
  "customEvent:event_label",
  "customEvent:focus_keyword",
  "customEvent:form_id",
  "customEvent:is_affiliate_link",
  "customEvent:link_action",
  "customEvent:link_label",
  "customEvent:link_text",
  "customEvent:link_type",
  "customEvent:logged_in",
  "customEvent:modified_at",
  "customEvent:outbound",
  "customEvent:percentage",
  "customEvent:post_type",
  "customEvent:publish_day_of_week",
  "customEvent:published_at",
  "customEvent:rankmath_focus_keyword",
  "customEvent:rankmath_seo_score",
  "customEvent:scroll_depth",
  "customEvent:scroll_timing",
  "customEvent:search_term",
  "customEvent:seo_score",
  "customEvent:seopress_keywords",
  "customEvent:seopress_seo_score",
  "customEvent:tags",
  "customEvent:tel_number",
  "customEvent:video_provider",
  "customEvent:video_title",
  "customEvent:video_url",
  "customEvent:wp_user_id",
  "date",
  "dateHour",
  "dateHourMinute",
  "day",
  "dayOfWeek",
  "dayOfWeekName",
  "deviceCategory",
  "deviceModel",
  "eventName",
  "fileExtension",
  "fileName",
  "firstSessionDate",
  "firstUserCampaignId",
  "firstUserCampaignName",
  "firstUserCm360AccountId",
  "firstUserCm360AccountName",
  "firstUserCm360AdvertiserId",
  "firstUserCm360AdvertiserName",
  "firstUserCm360CampaignId",
  "firstUserCm360CampaignName",
  "firstUserCm360CreativeFormat",
  "firstUserCm360CreativeId",
  "firstUserCm360CreativeName",
  "firstUserCm360CreativeType",
  "firstUserCm360CreativeTypeId",
  "firstUserCm360CreativeVersion",
  "firstUserCm360Medium",
  "firstUserCm360PlacementCostStructure",
  "firstUserCm360PlacementId",
  "firstUserCm360PlacementName",
  "firstUserCm360RenderingId",
  "firstUserCm360SiteId",
  "firstUserCm360SiteName",
  "firstUserCm360Source",
  "firstUserCm360SourceMedium",
  "firstUserCustomChannelGroup:5074227271",
  "firstUserDefaultChannelGroup",
  "firstUserDv360AdvertiserId",
  "firstUserDv360AdvertiserName",
  "firstUserDv360CampaignId",
  "firstUserDv360CampaignName",
  "firstUserDv360CreativeFormat",
  "firstUserDv360CreativeId",
  "firstUserDv360CreativeName",
  "firstUserDv360ExchangeId",
  "firstUserDv360ExchangeName",
  "firstUserDv360InsertionOrderId",
  "firstUserDv360InsertionOrderName",
  "firstUserDv360LineItemId",
  "firstUserDv360LineItemName",
  "firstUserDv360Medium",
  "firstUserDv360PartnerId",
  "firstUserDv360PartnerName",
  "firstUserDv360Source",
  "firstUserDv360SourceMedium",
  "firstUserGoogleAdsAccountName",
  "firstUserGoogleAdsAdGroupId",
  "firstUserGoogleAdsAdGroupName",
  "firstUserGoogleAdsAdNetworkType",
  "firstUserGoogleAdsCampaignId",
  "firstUserGoogleAdsCampaignName",
  "firstUserGoogleAdsCampaignType",
  "firstUserGoogleAdsCreativeId",
  "firstUserGoogleAdsCustomerId",
  "firstUserGoogleAdsKeyword",
  "firstUserGoogleAdsQuery",
  "firstUserManualAdContent",
  "firstUserManualCampaignId",
  "firstUserManualCampaignName",
  "firstUserManualCreativeFormat",
  "firstUserManualMarketingTactic",
  "firstUserManualMedium",
  "firstUserManualSource",
  "firstUserManualSourceMedium",
  "firstUserManualSourcePlatform",
  "firstUserManualTerm",
  "firstUserMedium",
  "firstUserPrimaryChannelGroup",
  "firstUserSa360AdGroupId",
  "firstUserSa360AdGroupName",
  "firstUserSa360CampaignId",
  "firstUserSa360CampaignName",
  "firstUserSa360CreativeFormat",
  "firstUserSa360EngineAccountId",
  "firstUserSa360EngineAccountName",
  "firstUserSa360EngineAccountType",
  "firstUserSa360KeywordText",
  "firstUserSa360ManagerAccountId",
  "firstUserSa360ManagerAccountName",
  "firstUserSa360Medium",
  "firstUserSa360Query",
  "firstUserSa360Source",
  "firstUserSa360SourceMedium",
  "firstUserSource",
  "firstUserSourceMedium",
  "firstUserSourcePlatform",
  "fullPageUrl",
  "groupId",
  "hostName",
  "hour",
  "isKeyEvent",
  "isoWeek",
  "isoYear",
  "isoYearIsoWeek",
  "landingPage",
  "landingPagePlusQueryString",
  "language",
  "languageCode",
  "level",
  "linkClasses",
  "linkDomain",
  "linkId",
  "linkText",
  "linkUrl",
  "method",
  "minute",
  "mobileDeviceBranding",
  "mobileDeviceMarketingName",
  "mobileDeviceModel",
  "month",
  "newVsReturning",
  "nthDay",
  "nthHour",
  "nthMinute",
  "nthMonth",
  "nthWeek",
  "nthYear",
  "operatingSystem",
  "operatingSystemVersion",
  "operatingSystemWithVersion",
  "orderCoupon",
  "outbound",
  "pageLocation",
  "pagePath",
  "pagePathPlusQueryString",
  "pageReferrer",
  "pageTitle",
  "percentScrolled",
  "platform",
  "platformDeviceCategory",
  "region",
  "screenResolution",
  "searchTerm",
  "sessionCampaignId",
  "sessionCampaignName",
  "sessionCm360AccountId",
  "sessionCm360AccountName",
  "sessionCm360AdvertiserId",
  "sessionCm360AdvertiserName",
  "sessionCm360CampaignId",
  "sessionCm360CampaignName",
  "sessionCm360CreativeFormat",
  "sessionCm360CreativeId",
  "sessionCm360CreativeName",
  "sessionCm360CreativeType",
  "sessionCm360CreativeTypeId",
  "sessionCm360CreativeVersion",
  "sessionCm360Medium",
  "sessionCm360PlacementCostStructure",
  "sessionCm360PlacementId",
  "sessionCm360PlacementName",
  "sessionCm360RenderingId",
  "sessionCm360SiteId",
  "sessionCm360SiteName",
  "sessionCm360Source",
  "sessionCm360SourceMedium",
  "sessionCustomChannelGroup:5074227271",
  "sessionDefaultChannelGroup",
  "sessionDv360AdvertiserId",
  "sessionDv360AdvertiserName",
  "sessionDv360CampaignId",
  "sessionDv360CampaignName",
  "sessionDv360CreativeFormat",
  "sessionDv360CreativeId",
  "sessionDv360CreativeName",
  "sessionDv360ExchangeId",
  "sessionDv360ExchangeName",
  "sessionDv360InsertionOrderId",
  "sessionDv360InsertionOrderName",
  "sessionDv360LineItemId",
  "sessionDv360LineItemName",
  "sessionDv360Medium",
  "sessionDv360PartnerId",
  "sessionDv360PartnerName",
  "sessionDv360Source",
  "sessionDv360SourceMedium",
  "sessionGoogleAdsAccountName",
  "sessionGoogleAdsAdGroupId",
  "sessionGoogleAdsAdGroupName",
  "sessionGoogleAdsAdNetworkType",
  "sessionGoogleAdsCampaignId",
  "sessionGoogleAdsCampaignName",
  "sessionGoogleAdsCampaignType",
  "sessionGoogleAdsCreativeId",
  "sessionGoogleAdsCustomerId",
  "sessionGoogleAdsKeyword",
  "sessionGoogleAdsQuery",
  "sessionManualAdContent",
  "sessionManualCampaignId",
  "sessionManualCampaignName",
  "sessionManualCreativeFormat",
  "sessionManualMarketingTactic",
  "sessionManualMedium",
  "sessionManualSource",
  "sessionManualSourceMedium",
  "sessionManualSourcePlatform",
  "sessionManualTerm",
  "sessionMedium",
  "sessionPrimaryChannelGroup",
  "sessionSa360AdGroupId",
  "sessionSa360AdGroupName",
  "sessionSa360CampaignId",
  "sessionSa360CampaignName",
  "sessionSa360CreativeFormat",
  "sessionSa360EngineAccountId",
  "sessionSa360EngineAccountName",
  "sessionSa360EngineAccountType",
  "sessionSa360Keyword",
  "sessionSa360ManagerAccountId",
  "sessionSa360ManagerAccountName",
  "sessionSa360Medium",
  "sessionSa360Query",
  "sessionSa360Source",
  "sessionSa360SourceMedium",
  "sessionSource",
  "sessionSourceMedium",
  "sessionSourcePlatform",
  "shippingTier",
  "signedInWithUserId",
  "streamId",
  "streamName",
  "testDataFilterId",
  "testDataFilterName",
  "transactionId",
  "unifiedPagePathScreen",
  "unifiedPageScreen",
  "unifiedScreenClass",
  "unifiedScreenName",
  "userAgeBracket",
  "userGender",
  "videoProvider",
  "videoTitle",
  "videoUrl",
  "virtualCurrencyName",
  "visible",
  "week",
  "year",
  "yearMonth",
  "yearWeek"
];
const GA4_DIMENSION_OPTIONS = ALL_DIMENSIONS.map((dim) => ({ value: dim, label: dimensionToLabel(dim) })).sort((a, b) => a.label.localeCompare(b.label));
const _hoisted_1$3 = ["aria-label"];
const _hoisted_2$3 = { class: "monsterinsights-filter-modal__header" };
const _hoisted_3$3 = {
  id: "filter-modal-title",
  class: "monsterinsights-filter-modal__title"
};
const _hoisted_4$3 = { class: "monsterinsights-filter-modal__body" };
const _hoisted_5$2 = { class: "monsterinsights-filter-modal__rows" };
const _hoisted_6$2 = { class: "monsterinsights-filter-modal__rows-list" };
const _hoisted_7$2 = { class: "monsterinsights-filter-modal__select-group" };
const _hoisted_8$2 = { class: "monsterinsights-filter-modal__field" };
const _hoisted_9$2 = { class: "monsterinsights-filter-modal__field-label" };
const _hoisted_10$2 = { class: "monsterinsights-filter-modal__field" };
const _hoisted_11$1 = { class: "monsterinsights-filter-modal__field-label" };
const _hoisted_12$1 = { class: "monsterinsights-filter-modal__select-wrapper" };
const _hoisted_13$1 = ["onUpdate:modelValue"];
const _hoisted_14$1 = ["value"];
const _hoisted_15$1 = { class: "monsterinsights-filter-modal__field monsterinsights-filter-modal__field--value" };
const _hoisted_16$1 = { class: "monsterinsights-filter-modal__field-label" };
const _hoisted_17$1 = ["onClick"];
const _hoisted_18$1 = ["disabled"];
const _hoisted_19$1 = { class: "monsterinsights-filter-modal__device-section" };
const _hoisted_20 = { class: "monsterinsights-filter-modal__section-title" };
const _hoisted_21 = { class: "monsterinsights-filter-modal__device-options" };
const _hoisted_22 = ["onClick"];
const _hoisted_23 = { class: "monsterinsights-filter-modal__actions" };
const _hoisted_24 = {
  key: 0,
  class: "monsterinsights-filter-modal__save-as"
};
const _hoisted_25 = { class: "monsterinsights-filter-modal__section-title" };
const _hoisted_26 = { class: "monsterinsights-filter-modal__save-as-form" };
const _hoisted_27 = ["placeholder"];
const _hoisted_28 = { class: "monsterinsights-filter-modal__save-as-actions" };
const _hoisted_29 = ["disabled"];
const _hoisted_30 = { class: "monsterinsights-filter-modal__saved-filters" };
const _hoisted_31 = { class: "monsterinsights-filter-modal__section-title" };
const _hoisted_32 = {
  key: 0,
  class: "monsterinsights-filter-modal__empty-state"
};
const _hoisted_33 = {
  key: 1,
  class: "monsterinsights-filter-modal__saved-list"
};
const _hoisted_34 = ["onMouseenter"];
const _hoisted_35 = { class: "monsterinsights-filter-modal__saved-item-header" };
const _hoisted_36 = { class: "monsterinsights-filter-modal__saved-item-info" };
const _hoisted_37 = { class: "monsterinsights-filter-modal__saved-item-name" };
const _hoisted_38 = {
  key: 0,
  class: "monsterinsights-filter-modal__saved-item-status monsterinsights-filter-modal__saved-item-status--applied"
};
const _hoisted_39 = ["onClick"];
const _hoisted_40 = { class: "monsterinsights-filter-modal__saved-item-actions" };
const _hoisted_41 = ["onClick"];
const _hoisted_42 = ["onClick"];
const _hoisted_43 = {
  key: 0,
  class: "monsterinsights-filter-modal__saved-item-edit"
};
const _hoisted_44 = { class: "monsterinsights-filter-modal__select-group" };
const _hoisted_45 = { class: "monsterinsights-filter-modal__field" };
const _hoisted_46 = { class: "monsterinsights-filter-modal__field" };
const _hoisted_47 = { class: "monsterinsights-filter-modal__select-wrapper" };
const _hoisted_48 = ["onUpdate:modelValue"];
const _hoisted_49 = ["value"];
const _hoisted_50 = { class: "monsterinsights-filter-modal__field monsterinsights-filter-modal__field--value" };
const _hoisted_51 = ["onClick"];
const _hoisted_52 = { class: "monsterinsights-filter-modal__device-section monsterinsights-filter-modal__device-section--compact" };
const _hoisted_53 = { class: "monsterinsights-filter-modal__section-title" };
const _hoisted_54 = { class: "monsterinsights-filter-modal__device-options" };
const _hoisted_55 = ["onClick"];
const _hoisted_56 = { class: "monsterinsights-filter-modal__edit-actions" };
const _hoisted_57 = ["disabled", "onClick"];
const _hoisted_58 = ["disabled"];
const MAX_FILTER_ROWS = 3;
const _sfc_main$3 = {
  __name: "FilterModal",
  props: {
    isOpen: {
      type: Boolean,
      default: false
    }
  },
  emits: ["close", "apply-filter"],
  setup(__props, { emit: __emit }) {
    const overviewStore = useOverviewReportStore();
    const props = __props;
    const emit = __emit;
    watch(
      () => props.isOpen,
      (isOpen) => {
        if (isOpen) {
          syncFromStore();
        }
      },
      { immediate: true }
    );
    function syncFromStore() {
      const storeFilters = overviewStore.activeFilters;
      const storeDevice = overviewStore.activeDevice;
      if (Array.isArray(storeFilters) && storeFilters.length > 0) {
        filterRows.value = storeFilters.map((f) => ({ ...f }));
        storeFilters.forEach((f) => {
          if (f.type) loadDimensionValues(f.type);
        });
      } else {
        filterRows.value = [{ type: "", condition: "is", value: "" }];
      }
      selectedDevice.value = storeDevice || "";
      if (appliedFilterId.value) {
        const appliedSaved = savedFilters.value.find((f) => f.id === appliedFilterId.value);
        if (appliedSaved) {
          const savedFilterStr = JSON.stringify(
            (appliedSaved.filters || []).map((f) => ({ type: f.type, condition: f.condition, value: f.value }))
          );
          const currentFilterStr = JSON.stringify(
            storeFilters.map((f) => ({ type: f.type, condition: f.condition, value: f.value }))
          );
          if (savedFilterStr !== currentFilterStr || (appliedSaved.device || "") !== (storeDevice || "")) {
            appliedFilterId.value = null;
          }
        }
      }
    }
    const { successToast, errorToast } = useToast();
    const showSuccessToast = ({ message }) => successToast({ title: message, text: "" });
    const showErrorToast = ({ message }) => errorToast({ title: message, text: "" });
    const CHANNEL_GROUP_OPTIONS = [
      "Organic Search",
      "Direct",
      "Referral",
      "Paid Search",
      "Organic Social",
      "Paid Social",
      "Email",
      "Display",
      "Organic Shopping",
      "Paid Shopping",
      "Unassigned"
    ].map((v) => ({ value: v, label: v }));
    const filterTypeOptions = ref(GA4_DIMENSION_OPTIONS);
    const valueOptionsCache = /* @__PURE__ */ Object.create(null);
    const dimensionValuesLoading = ref({});
    const fetchedDimensionValues = ref({});
    async function loadDimensionValues(dimensionKey) {
      if (!dimensionKey) return;
      if (fetchedDimensionValues.value[dimensionKey]) return;
      dimensionValuesLoading.value[dimensionKey] = true;
      try {
        const dateRange = overviewStore.dateRange;
        const values = await fetchDimensionValues(dimensionKey, dateRange);
        if (values && values.length > 0) {
          fetchedDimensionValues.value[dimensionKey] = values;
        }
      } finally {
        dimensionValuesLoading.value[dimensionKey] = false;
      }
    }
    const getValueOptions = (dimensionKey) => {
      if (!dimensionKey) return [];
      let fromStore = [];
      if (dimensionKey === "sessionDefaultChannelGroup") {
        fromStore = getValuesForDimension(dimensionKey, overviewStore.$state);
        if (!fromStore.length) fromStore = CHANNEL_GROUP_OPTIONS;
      } else {
        fromStore = getValuesForDimension(dimensionKey, overviewStore.$state);
      }
      const fromApi = fetchedDimensionValues.value[dimensionKey] || [];
      const selectedValues = /* @__PURE__ */ new Set();
      filterRows.value.forEach((r) => {
        if (r.type === dimensionKey && r.value) selectedValues.add(r.value);
      });
      editFilterRows.value.forEach((r) => {
        if (r.type === dimensionKey && r.value) selectedValues.add(r.value);
      });
      const combined = /* @__PURE__ */ new Map();
      const cached = valueOptionsCache[dimensionKey] || [];
      [...cached, ...fromApi, ...fromStore].forEach((opt) => {
        const v = opt.value ?? opt;
        const label = opt.label ?? opt;
        if (v) combined.set(String(v), { value: String(v), label: label || String(v) });
      });
      selectedValues.forEach((v) => {
        if (v && !combined.has(v)) combined.set(v, { value: v, label: v });
      });
      const result = Array.from(combined.values()).sort((a, b) => (a.label || a.value).localeCompare(b.label || b.value));
      valueOptionsCache[dimensionKey] = result;
      return result;
    };
    const conditionOptions = [
      { value: "is", label: __$2("Is", "google-analytics-for-wordpress") },
      { value: "is_not", label: __$2("Is Not", "google-analytics-for-wordpress") }
    ];
    const filterRows = ref([
      { type: "", condition: "is", value: "" }
    ]);
    const getFilterTypeOptionsForRow = (rowIndex) => {
      const currentType = filterRows.value[rowIndex]?.type || "";
      const usedTypes = new Set(
        filterRows.value.map((r, idx) => idx === rowIndex ? null : r.type).filter((t) => !!t)
      );
      return filterTypeOptions.value.filter(
        (opt) => opt.value === currentType || !usedTypes.has(opt.value)
      );
    };
    function onFilterTypeChange(index) {
      const row = filterRows.value[index];
      if (!row) {
        return;
      }
      row.value = "";
      if (row.type) {
        loadDimensionValues(row.type);
      }
    }
    const deviceOptions = [
      { value: "desktop", label: __$2("Desktop", "google-analytics-for-wordpress"), icon: "desktop" },
      { value: "mobile", label: __$2("Mobile", "google-analytics-for-wordpress"), icon: "smartphone" },
      { value: "tablet", label: __$2("Tablet", "google-analytics-for-wordpress"), icon: "tablet" }
    ];
    const selectedDevice = ref("");
    const showSaveAs = ref(false);
    const saveFilterName = ref("");
    const isSaving = ref(false);
    const savedFilters = ref([]);
    const appliedFilterId = ref(null);
    const hoveredFilterId = ref(null);
    const editingFilterId = ref(null);
    const editFilterRows = ref([]);
    const editSelectedDevice = ref("");
    const getEditFilterTypeOptionsForRow = (rowIndex) => {
      const currentType = editFilterRows.value[rowIndex]?.type || "";
      const usedTypes = new Set(
        editFilterRows.value.map((r, idx) => idx === rowIndex ? null : r.type).filter((t) => !!t)
      );
      return filterTypeOptions.value.filter(
        (opt) => opt.value === currentType || !usedTypes.has(opt.value)
      );
    };
    function onEditFilterTypeChange(index) {
      const row = editFilterRows.value[index];
      if (!row) {
        return;
      }
      row.value = "";
      if (row.type) {
        loadDimensionValues(row.type);
      }
    }
    const closeModal = () => {
      showSaveAs.value = false;
      saveFilterName.value = "";
      emit("close");
    };
    const canAddMoreFilterRows = () => {
      if (filterRows.value.length >= MAX_FILTER_ROWS) {
        return false;
      }
      const usedTypes = new Set(filterRows.value.map((r) => r.type).filter((t) => !!t));
      return filterTypeOptions.value.some((opt) => !usedTypes.has(opt.value));
    };
    const addFilterRow = () => {
      if (!canAddMoreFilterRows()) {
        return;
      }
      filterRows.value.push({ type: "", condition: "is", value: "" });
    };
    const removeFilterRow = (index) => {
      if (filterRows.value.length > 1) {
        filterRows.value.splice(index, 1);
      } else {
        filterRows.value[0] = { type: "", condition: "is", value: "" };
      }
    };
    const selectDevice = (device) => {
      selectedDevice.value = selectedDevice.value === device ? "" : device;
    };
    const clearAllFilters = () => {
      filterRows.value = [{ type: "", condition: "is", value: "" }];
      selectedDevice.value = "";
      showSaveAs.value = false;
      saveFilterName.value = "";
      appliedFilterId.value = null;
      editingFilterId.value = null;
      editFilterRows.value = [];
      editSelectedDevice.value = "";
      emit("apply-filter", {
        filters: [],
        device: ""
      });
      closeModal();
    };
    const applyFilter = () => {
      const activeFilters = filterRows.value.filter((row) => row.type && row.value).map((row) => ({ ...row }));
      if (activeFilters.length === 0 && !selectedDevice.value) {
        showErrorToast({
          message: __$2("Please select at least one dimension with a value.", "google-analytics-for-wordpress")
        });
        return;
      }
      appliedFilterId.value = null;
      emit("apply-filter", {
        filters: activeFilters,
        device: selectedDevice.value
      });
      closeModal();
    };
    const onSaveFilterClick = () => {
      showSaveAs.value = true;
      saveFilterName.value = "";
    };
    const cancelSaveAs = () => {
      showSaveAs.value = false;
      saveFilterName.value = "";
    };
    const saveFilter = () => {
      if (isSaving.value) return;
      if (!saveFilterName.value.trim()) {
        showErrorToast({
          message: __$2("Please enter a name for this filter.", "google-analytics-for-wordpress")
        });
        return;
      }
      const validFilters = filterRows.value.filter((row) => row.type && row.value);
      if (validFilters.length === 0 && !selectedDevice.value) {
        showErrorToast({
          message: __$2("Please select at least one dimension with a value.", "google-analytics-for-wordpress")
        });
        return;
      }
      const filterData = {
        name: saveFilterName.value.trim(),
        filters: validFilters,
        device: selectedDevice.value
      };
      const ajaxData = {
        action: "monsterinsights_save_report_filter",
        nonce: getMiGlobal("nonce", ""),
        filter: JSON.stringify(filterData)
      };
      isSaving.value = true;
      wp.ajax.post(ajaxData).done((response) => {
        if (response && response.id) {
          savedFilters.value.push({
            id: response.id,
            ...filterData
          });
          showSaveAs.value = false;
          saveFilterName.value = "";
          showSuccessToast({
            message: sprintf(
              /* translators: %s - filter name */
              __$2('Filter "%s" has been saved successfully.', "google-analytics-for-wordpress"),
              filterData.name
            )
          });
        }
      }).fail(() => {
        showErrorToast({
          message: __$2("Failed to save filter. Please try again.", "google-analytics-for-wordpress")
        });
      }).always(() => {
        isSaving.value = false;
      });
    };
    const applySavedFilter = (savedFilter) => {
      appliedFilterId.value = savedFilter.id;
      if (savedFilter.filters && savedFilter.filters.length > 0) {
        filterRows.value = savedFilter.filters.map((f) => ({ ...f }));
      }
      if (savedFilter.device) {
        selectedDevice.value = savedFilter.device;
      }
      emit("apply-filter", {
        filters: (savedFilter.filters || []).map((f) => ({ ...f })),
        device: savedFilter.device || ""
      });
      closeModal();
    };
    const toggleEditFilter = (savedFilter) => {
      if (editingFilterId.value === savedFilter.id) {
        editingFilterId.value = null;
        editFilterRows.value = [];
        editSelectedDevice.value = "";
      } else {
        editingFilterId.value = savedFilter.id;
        editFilterRows.value = savedFilter.filters ? savedFilter.filters.map((f) => ({ ...f })) : [{ type: "", condition: "is", value: "" }];
        editSelectedDevice.value = savedFilter.device || "";
        editFilterRows.value.forEach((f) => {
          if (f.type) loadDimensionValues(f.type);
        });
      }
    };
    const addEditFilterRow = () => {
      if (!canAddMoreEditFilterRows()) {
        return;
      }
      editFilterRows.value.push({ type: "", condition: "is", value: "" });
    };
    const removeEditFilterRow = (index) => {
      if (editFilterRows.value.length > 1) {
        editFilterRows.value.splice(index, 1);
      } else {
        editFilterRows.value[0] = { type: "", condition: "is", value: "" };
      }
    };
    const selectEditDevice = (device) => {
      editSelectedDevice.value = editSelectedDevice.value === device ? "" : device;
    };
    const canAddMoreEditFilterRows = () => {
      if (editFilterRows.value.length >= MAX_FILTER_ROWS) {
        return false;
      }
      const usedTypes = new Set(editFilterRows.value.map((r) => r.type).filter((t) => !!t));
      return filterTypeOptions.value.some((opt) => !usedTypes.has(opt.value));
    };
    const saveEditFilter = (filterId) => {
      if (isSaving.value) return;
      const filterIndex = savedFilters.value.findIndex((f) => f.id === filterId);
      if (filterIndex === -1) return;
      const validEditFilters = editFilterRows.value.filter((row) => row.type && row.value);
      if (validEditFilters.length === 0) {
        showErrorToast({
          message: __$2("Please select at least one dimension with a value.", "google-analytics-for-wordpress")
        });
        return;
      }
      const updatedFilter = {
        ...savedFilters.value[filterIndex],
        filters: validEditFilters,
        device: editSelectedDevice.value
      };
      const ajaxData = {
        action: "monsterinsights_update_report_filter",
        nonce: getMiGlobal("nonce", ""),
        filter_id: filterId,
        filter: JSON.stringify(updatedFilter)
      };
      isSaving.value = true;
      wp.ajax.post(ajaxData).done(() => {
        savedFilters.value[filterIndex] = updatedFilter;
        editingFilterId.value = null;
        editFilterRows.value = [];
        editSelectedDevice.value = "";
        if (appliedFilterId.value === filterId) {
          emit("apply-filter", {
            filters: (updatedFilter.filters || []).map((f) => ({ ...f })),
            device: updatedFilter.device || ""
          });
          filterRows.value = updatedFilter.filters ? updatedFilter.filters.map((f) => ({ ...f })) : [{ type: "", condition: "is", value: "" }];
          selectedDevice.value = updatedFilter.device || "";
        }
        showSuccessToast({
          message: sprintf(
            /* translators: %s - filter name */
            __$2('Filter "%s" has been updated successfully.', "google-analytics-for-wordpress"),
            updatedFilter.name
          )
        });
      }).fail(() => {
        showErrorToast({
          message: __$2("Failed to update filter. Please try again.", "google-analytics-for-wordpress")
        });
      }).always(() => {
        isSaving.value = false;
      });
    };
    const deleteSavedFilter = (filterId) => {
      const ajaxData = {
        action: "monsterinsights_delete_report_filter",
        nonce: getMiGlobal("nonce", ""),
        filter_id: filterId
      };
      wp.ajax.post(ajaxData).done(() => {
        savedFilters.value = savedFilters.value.filter((f) => f.id !== filterId);
        if (appliedFilterId.value === filterId) {
          clearAllFilters();
        }
        if (editingFilterId.value === filterId) {
          editingFilterId.value = null;
          editFilterRows.value = [];
          editSelectedDevice.value = "";
        }
        showSuccessToast({
          message: __$2("Filter deleted successfully.", "google-analytics-for-wordpress")
        });
      }).fail(() => {
        showErrorToast({
          message: __$2("Failed to delete filter. Please try again.", "google-analytics-for-wordpress")
        });
      });
    };
    const fetchSavedFilters = () => {
      const ajaxData = {
        action: "monsterinsights_get_report_filters",
        nonce: getMiGlobal("nonce", "")
      };
      wp.ajax.post(ajaxData).done((response) => {
        if (response && response.filters) {
          savedFilters.value = response.filters;
        }
      }).fail(() => {
        savedFilters.value = [];
      });
    };
    onMounted(() => {
      fetchSavedFilters();
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$9, {
        open: __props.isOpen,
        "overlay-class": "monsterinsights-filter-modal-overlay",
        "panel-class": "monsterinsights-filter-modal",
        labelledby: "filter-modal-title",
        onClose: closeModal
      }, {
        default: withCtx(() => [
          createBaseVNode("button", {
            type: "button",
            class: "monsterinsights-filter-modal__close",
            "aria-label": unref(__$2)("Close filter panel", "google-analytics-for-wordpress"),
            onClick: closeModal
          }, [
            createVNode(Icon, {
              name: "close",
              size: 16
            })
          ], 8, _hoisted_1$3),
          createBaseVNode("div", _hoisted_2$3, [
            createBaseVNode("h2", _hoisted_3$3, toDisplayString(unref(__$2)("Filter", "google-analytics-for-wordpress")), 1),
            createBaseVNode("button", {
              type: "button",
              class: "monsterinsights-filter-modal__clear-all",
              onClick: clearAllFilters
            }, toDisplayString(unref(__$2)("Clear All", "google-analytics-for-wordpress")), 1)
          ]),
          createBaseVNode("div", _hoisted_4$3, [
            createBaseVNode("div", _hoisted_5$2, [
              createBaseVNode("div", _hoisted_6$2, [
                (openBlock(true), createElementBlock(Fragment, null, renderList(filterRows.value, (row, index) => {
                  return openBlock(), createElementBlock("div", {
                    key: index,
                    class: "monsterinsights-filter-modal__row"
                  }, [
                    createBaseVNode("div", _hoisted_7$2, [
                      createBaseVNode("div", _hoisted_8$2, [
                        createBaseVNode("label", _hoisted_9$2, toDisplayString(unref(__$2)("Choose Type", "google-analytics-for-wordpress")), 1),
                        createVNode(_sfc_main$4, {
                          modelValue: row.type,
                          "onUpdate:modelValue": (val) => {
                            row.type = val;
                            onFilterTypeChange(index);
                          },
                          options: getFilterTypeOptionsForRow(index),
                          placeholder: unref(__$2)("Choose Type", "google-analytics-for-wordpress"),
                          searchPlaceholder: unref(__$2)("Search dimensions...", "google-analytics-for-wordpress")
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "options", "placeholder", "searchPlaceholder"])
                      ]),
                      createBaseVNode("div", _hoisted_10$2, [
                        createBaseVNode("label", _hoisted_11$1, toDisplayString(unref(__$2)("Condition", "google-analytics-for-wordpress")), 1),
                        createBaseVNode("div", _hoisted_12$1, [
                          withDirectives(createBaseVNode("select", {
                            "onUpdate:modelValue": ($event) => row.condition = $event,
                            class: "monsterinsights-filter-modal__select"
                          }, [
                            (openBlock(), createElementBlock(Fragment, null, renderList(conditionOptions, (opt) => {
                              return createBaseVNode("option", {
                                key: opt.value,
                                value: opt.value
                              }, toDisplayString(opt.label), 9, _hoisted_14$1);
                            }), 64))
                          ], 8, _hoisted_13$1), [
                            [vModelSelect, row.condition]
                          ]),
                          createVNode(Icon, {
                            name: "chevron-down",
                            size: 16
                          })
                        ])
                      ]),
                      createBaseVNode("div", _hoisted_15$1, [
                        createBaseVNode("label", _hoisted_16$1, toDisplayString(unref(__$2)("Value", "google-analytics-for-wordpress")), 1),
                        createVNode(_sfc_main$4, {
                          modelValue: row.value,
                          "onUpdate:modelValue": ($event) => row.value = $event,
                          options: getValueOptions(row.type),
                          disabled: !row.type,
                          placeholder: dimensionValuesLoading.value[row.type] ? unref(__$2)("Loading...", "google-analytics-for-wordpress") : unref(__$2)("Select value", "google-analytics-for-wordpress"),
                          searchPlaceholder: unref(__$2)("Search values...", "google-analytics-for-wordpress")
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "options", "disabled", "placeholder", "searchPlaceholder"])
                      ])
                    ]),
                    createBaseVNode("button", {
                      type: "button",
                      class: "monsterinsights-filter-modal__row-delete",
                      onClick: ($event) => removeFilterRow(index)
                    }, [
                      createVNode(Icon, {
                        name: "trash",
                        size: 16
                      })
                    ], 8, _hoisted_17$1)
                  ]);
                }), 128))
              ]),
              createBaseVNode("button", {
                type: "button",
                class: normalizeClass(["monsterinsights-filter-modal__add-btn", { "monsterinsights-filter-modal__add-btn--disabled": !canAddMoreFilterRows() }]),
                disabled: !canAddMoreFilterRows(),
                onClick: addFilterRow
              }, [
                createVNode(Icon, {
                  name: "plus",
                  size: 16
                }),
                createBaseVNode("span", null, toDisplayString(unref(__$2)("Add New Filter", "google-analytics-for-wordpress")), 1)
              ], 10, _hoisted_18$1)
            ]),
            createBaseVNode("div", _hoisted_19$1, [
              createBaseVNode("h3", _hoisted_20, toDisplayString(unref(__$2)("Device", "google-analytics-for-wordpress")), 1),
              createBaseVNode("div", _hoisted_21, [
                (openBlock(), createElementBlock(Fragment, null, renderList(deviceOptions, (device) => {
                  return createBaseVNode("button", {
                    key: device.value,
                    type: "button",
                    class: normalizeClass(["monsterinsights-filter-modal__device-btn", { "monsterinsights-filter-modal__device-btn--active": selectedDevice.value === device.value }]),
                    onClick: ($event) => selectDevice(device.value)
                  }, [
                    createVNode(Icon, {
                      name: device.icon,
                      size: 20
                    }, null, 8, ["name"]),
                    createBaseVNode("span", null, toDisplayString(device.label), 1)
                  ], 10, _hoisted_22);
                }), 64))
              ])
            ]),
            createBaseVNode("div", _hoisted_23, [
              createBaseVNode("button", {
                type: "button",
                class: "monsterinsights-filter-modal__btn monsterinsights-filter-modal__btn--outline",
                onClick: applyFilter
              }, toDisplayString(unref(__$2)("Apply Filter", "google-analytics-for-wordpress")), 1),
              createBaseVNode("button", {
                type: "button",
                class: "monsterinsights-filter-modal__btn monsterinsights-filter-modal__btn--primary",
                onClick: onSaveFilterClick
              }, toDisplayString(unref(__$2)("Save Filter", "google-analytics-for-wordpress")), 1)
            ])
          ]),
          _cache[2] || (_cache[2] = createBaseVNode("div", { class: "monsterinsights-filter-modal__divider" }, null, -1)),
          showSaveAs.value ? (openBlock(), createElementBlock("div", _hoisted_24, [
            createBaseVNode("h3", _hoisted_25, toDisplayString(unref(__$2)("Save Filter As", "google-analytics-for-wordpress")), 1),
            createBaseVNode("div", _hoisted_26, [
              withDirectives(createBaseVNode("input", {
                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => saveFilterName.value = $event),
                type: "text",
                class: "monsterinsights-filter-modal__save-as-input",
                placeholder: unref(__$2)("Name this filter", "google-analytics-for-wordpress")
              }, null, 8, _hoisted_27), [
                [vModelText, saveFilterName.value]
              ]),
              createBaseVNode("div", _hoisted_28, [
                createBaseVNode("button", {
                  type: "button",
                  class: "monsterinsights-filter-modal__btn monsterinsights-filter-modal__btn--primary",
                  disabled: isSaving.value,
                  onClick: saveFilter
                }, toDisplayString(isSaving.value ? unref(__$2)("Saving...", "google-analytics-for-wordpress") : unref(__$2)("Save Filter", "google-analytics-for-wordpress")), 9, _hoisted_29),
                createBaseVNode("button", {
                  type: "button",
                  class: "monsterinsights-filter-modal__btn monsterinsights-filter-modal__btn--cancel",
                  onClick: cancelSaveAs
                }, toDisplayString(unref(__$2)("Cancel", "google-analytics-for-wordpress")), 1)
              ])
            ])
          ])) : createCommentVNode("", true),
          createBaseVNode("div", _hoisted_30, [
            createBaseVNode("h3", _hoisted_31, toDisplayString(savedFilters.value.length > 0 ? unref(__$2)("Your Saved Filters", "google-analytics-for-wordpress") : unref(__$2)("Saved Filters", "google-analytics-for-wordpress")), 1),
            savedFilters.value.length === 0 ? (openBlock(), createElementBlock("div", _hoisted_32, [
              createVNode(Icon, {
                name: "no-saved-filters",
                size: 64
              }),
              createBaseVNode("p", null, toDisplayString(unref(__$2)("No saved filters found", "google-analytics-for-wordpress")), 1)
            ])) : (openBlock(), createElementBlock("div", _hoisted_33, [
              (openBlock(true), createElementBlock(Fragment, null, renderList(savedFilters.value, (savedFilter, index) => {
                return openBlock(), createElementBlock("div", {
                  key: savedFilter.id,
                  class: normalizeClass(["monsterinsights-filter-modal__saved-item", {
                    "monsterinsights-filter-modal__saved-item--applied": savedFilter.id === appliedFilterId.value,
                    "monsterinsights-filter-modal__saved-item--editing": editingFilterId.value === savedFilter.id
                  }]),
                  onMouseenter: ($event) => hoveredFilterId.value = savedFilter.id,
                  onMouseleave: _cache[1] || (_cache[1] = ($event) => hoveredFilterId.value = null)
                }, [
                  createBaseVNode("div", _hoisted_35, [
                    createBaseVNode("div", _hoisted_36, [
                      createBaseVNode("span", _hoisted_37, toDisplayString(savedFilter.name), 1),
                      savedFilter.id === appliedFilterId.value ? (openBlock(), createElementBlock("span", _hoisted_38, toDisplayString(unref(__$2)("Applied", "google-analytics-for-wordpress")), 1)) : hoveredFilterId.value === savedFilter.id && editingFilterId.value !== savedFilter.id ? (openBlock(), createElementBlock("span", {
                        key: 1,
                        class: "monsterinsights-filter-modal__saved-item-status monsterinsights-filter-modal__saved-item-status--apply",
                        onClick: ($event) => applySavedFilter(savedFilter)
                      }, toDisplayString(unref(__$2)("Apply", "google-analytics-for-wordpress")), 9, _hoisted_39)) : createCommentVNode("", true)
                    ]),
                    createBaseVNode("div", _hoisted_40, [
                      createBaseVNode("button", {
                        type: "button",
                        class: "monsterinsights-filter-modal__saved-item-btn",
                        onClick: ($event) => toggleEditFilter(savedFilter)
                      }, [
                        createVNode(Icon, {
                          name: "pencil",
                          size: 16
                        })
                      ], 8, _hoisted_41),
                      createBaseVNode("button", {
                        type: "button",
                        class: "monsterinsights-filter-modal__saved-item-btn",
                        onClick: ($event) => deleteSavedFilter(savedFilter.id)
                      }, [
                        createVNode(Icon, {
                          name: "trash",
                          size: 16
                        })
                      ], 8, _hoisted_42)
                    ])
                  ]),
                  editingFilterId.value === savedFilter.id ? (openBlock(), createElementBlock("div", _hoisted_43, [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(editFilterRows.value, (editRow, editIndex) => {
                      return openBlock(), createElementBlock("div", {
                        key: editIndex,
                        class: "monsterinsights-filter-modal__row monsterinsights-filter-modal__row--compact"
                      }, [
                        createBaseVNode("div", _hoisted_44, [
                          createBaseVNode("div", _hoisted_45, [
                            createVNode(_sfc_main$4, {
                              modelValue: editRow.type,
                              "onUpdate:modelValue": (val) => {
                                editRow.type = val;
                                onEditFilterTypeChange(editIndex);
                              },
                              options: getEditFilterTypeOptionsForRow(editIndex),
                              placeholder: unref(__$2)("Choose Type", "google-analytics-for-wordpress"),
                              searchPlaceholder: unref(__$2)("Search dimensions...", "google-analytics-for-wordpress")
                            }, null, 8, ["modelValue", "onUpdate:modelValue", "options", "placeholder", "searchPlaceholder"])
                          ]),
                          createBaseVNode("div", _hoisted_46, [
                            createBaseVNode("div", _hoisted_47, [
                              withDirectives(createBaseVNode("select", {
                                "onUpdate:modelValue": ($event) => editRow.condition = $event,
                                class: "monsterinsights-filter-modal__select"
                              }, [
                                (openBlock(), createElementBlock(Fragment, null, renderList(conditionOptions, (opt) => {
                                  return createBaseVNode("option", {
                                    key: opt.value,
                                    value: opt.value
                                  }, toDisplayString(opt.label), 9, _hoisted_49);
                                }), 64))
                              ], 8, _hoisted_48), [
                                [vModelSelect, editRow.condition]
                              ]),
                              createVNode(Icon, {
                                name: "chevron-down",
                                size: 16
                              })
                            ])
                          ]),
                          createBaseVNode("div", _hoisted_50, [
                            createVNode(_sfc_main$4, {
                              modelValue: editRow.value,
                              "onUpdate:modelValue": ($event) => editRow.value = $event,
                              options: getValueOptions(editRow.type),
                              disabled: !editRow.type,
                              placeholder: dimensionValuesLoading.value[editRow.type] ? unref(__$2)("Loading...", "google-analytics-for-wordpress") : unref(__$2)("Select value", "google-analytics-for-wordpress"),
                              searchPlaceholder: unref(__$2)("Search values...", "google-analytics-for-wordpress")
                            }, null, 8, ["modelValue", "onUpdate:modelValue", "options", "disabled", "placeholder", "searchPlaceholder"])
                          ])
                        ]),
                        createBaseVNode("button", {
                          type: "button",
                          class: "monsterinsights-filter-modal__row-delete",
                          onClick: ($event) => removeEditFilterRow(editIndex)
                        }, [
                          createVNode(Icon, {
                            name: "trash",
                            size: 16
                          })
                        ], 8, _hoisted_51)
                      ]);
                    }), 128)),
                    createBaseVNode("div", _hoisted_52, [
                      createBaseVNode("h3", _hoisted_53, toDisplayString(unref(__$2)("Device", "google-analytics-for-wordpress")), 1),
                      createBaseVNode("div", _hoisted_54, [
                        (openBlock(), createElementBlock(Fragment, null, renderList(deviceOptions, (device) => {
                          return createBaseVNode("button", {
                            key: device.value,
                            type: "button",
                            class: normalizeClass(["monsterinsights-filter-modal__device-btn", { "monsterinsights-filter-modal__device-btn--active": editSelectedDevice.value === device.value }]),
                            onClick: ($event) => selectEditDevice(device.value)
                          }, [
                            createVNode(Icon, {
                              name: device.icon,
                              size: 20
                            }, null, 8, ["name"]),
                            createBaseVNode("span", null, toDisplayString(device.label), 1)
                          ], 10, _hoisted_55);
                        }), 64))
                      ])
                    ]),
                    createBaseVNode("div", _hoisted_56, [
                      createBaseVNode("button", {
                        type: "button",
                        class: "monsterinsights-filter-modal__btn monsterinsights-filter-modal__btn--primary monsterinsights-filter-modal__btn--sm",
                        disabled: isSaving.value,
                        onClick: ($event) => saveEditFilter(savedFilter.id)
                      }, toDisplayString(isSaving.value ? unref(__$2)("Saving...", "google-analytics-for-wordpress") : unref(__$2)("Save", "google-analytics-for-wordpress")), 9, _hoisted_57),
                      createBaseVNode("button", {
                        type: "button",
                        class: normalizeClass(["monsterinsights-filter-modal__add-btn monsterinsights-filter-modal__add-btn--sm", { "monsterinsights-filter-modal__add-btn--disabled": !canAddMoreEditFilterRows() }]),
                        disabled: !canAddMoreEditFilterRows(),
                        onClick: addEditFilterRow
                      }, [
                        createVNode(Icon, {
                          name: "plus",
                          size: 16
                        }),
                        createBaseVNode("span", null, toDisplayString(unref(__$2)("Add Step", "google-analytics-for-wordpress")), 1)
                      ], 10, _hoisted_58)
                    ])
                  ])) : createCommentVNode("", true)
                ], 42, _hoisted_34);
              }), 128))
            ]))
          ])
        ]),
        _: 1
      }, 8, ["open"]);
    };
  }
};
const _hoisted_1$2 = { class: "monsterinsights-report-header-applied-filters" };
const _hoisted_2$2 = { class: "monsterinsights-report-header-applied-filters__container" };
const _hoisted_3$2 = {
  key: 0,
  class: "monsterinsights-report-header-applied-filters__label"
};
const _hoisted_4$2 = { class: "monsterinsights-filter-tag__text" };
const _hoisted_5$1 = { class: "monsterinsights-filter-tag__name" };
const _hoisted_6$1 = { class: "monsterinsights-filter-tag__value" };
const _hoisted_7$1 = ["aria-label", "onClick"];
const _hoisted_8$1 = { class: "monsterinsights-overview-report-header-right" };
const _hoisted_9$1 = { class: "monsterinsights-header-btn__text" };
const _hoisted_10$1 = {
  key: 0,
  class: "monsterinsights-header-btn__indicator"
};
const MAX_VISIBLE_FILTERS = 3;
const _sfc_main$2 = {
  __name: "OverviewHeader",
  setup(__props) {
    const route = useRoute();
    const shouldBlur = computed(() => !isAuthed());
    const hideFilter = computed(() => ["exceptions", "media"].includes(route.name));
    const allowCompare = computed(() => route.name !== "ecommerce-funnel");
    const overviewStore = useOverviewReportStore();
    const dateRangeModelValue = computed(() => ({
      interval: overviewStore.dateRange.interval ?? "last30days",
      start: overviewStore.dateRange.start ?? "",
      end: overviewStore.dateRange.end ?? "",
      compareReport: overviewStore.dateRange.compareReport ?? false,
      compareStart: overviewStore.dateRange.compareStart ?? "",
      compareEnd: overviewStore.dateRange.compareEnd ?? ""
    }));
    function onDateChange(updates) {
      if (updates?.compareReport === true && true) {
        overviewStore.openProModal();
        return;
      }
      overviewStore.updateDateRange(updates);
    }
    const isFilterModalOpen = ref(false);
    const filterTypeLabels = {
      sessionDefaultChannelGroup: __$2("Channel Group", "google-analytics-for-wordpress"),
      sessionCampaignName: __$2("Campaign - Name", "google-analytics-for-wordpress"),
      sessionSource: __$2("Campaign - Source", "google-analytics-for-wordpress"),
      sessionMedium: __$2("Campaign - Medium", "google-analytics-for-wordpress"),
      sessionManualTerm: __$2("Campaign - Term", "google-analytics-for-wordpress"),
      sessionManualAdContent: __$2("Campaign - Content", "google-analytics-for-wordpress"),
      landingPagePlusQueryString: __$2("Page - Landing Page", "google-analytics-for-wordpress"),
      pageTitle: __$2("Page - Title", "google-analytics-for-wordpress"),
      country: __$2("Country", "google-analytics-for-wordpress"),
      region: __$2("State / Region", "google-analytics-for-wordpress"),
      browser: __$2("Browser", "google-analytics-for-wordpress"),
      operatingSystem: __$2("Operating System", "google-analytics-for-wordpress"),
      deviceCategory: __$2("Device Category", "google-analytics-for-wordpress")
    };
    const appliedFilters = computed(() => {
      const displayFilters = overviewStore.activeFilters.map((f) => ({
        name: filterTypeLabels[f.type] || f.type,
        value: f.value,
        _raw: f
      }));
      if (overviewStore.activeDevice) {
        displayFilters.push({
          name: __$2("Device", "google-analytics-for-wordpress"),
          value: overviewStore.activeDevice.charAt(0).toUpperCase() + overviewStore.activeDevice.slice(1),
          _raw: { type: "__device__", value: overviewStore.activeDevice }
        });
      }
      return displayFilters;
    });
    const filtersExpanded = ref(false);
    const displayedFilters = computed(() => {
      if (filtersExpanded.value) return appliedFilters.value;
      return appliedFilters.value.slice(0, MAX_VISIBLE_FILTERS);
    });
    const additionalFiltersCount = computed(() => {
      return Math.max(0, appliedFilters.value.length - MAX_VISIBLE_FILTERS);
    });
    const hasActiveFilters = computed(() => overviewStore.hasActiveFilters);
    const removeFilter = (index) => {
      const removed = displayedFilters.value[index];
      if (!removed) return;
      if (removed._raw.type === "__device__") {
        overviewStore.setActiveFilters(overviewStore.activeFilters, "");
      } else {
        const raw = removed._raw;
        const newFilters = overviewStore.activeFilters.filter((f) => f !== raw);
        overviewStore.setActiveFilters(newFilters, overviewStore.activeDevice);
      }
      if (appliedFilters.value.length <= MAX_VISIBLE_FILTERS) {
        filtersExpanded.value = false;
      }
    };
    const clearAllFilters = () => {
      overviewStore.setActiveFilters([], "");
      filtersExpanded.value = false;
    };
    const openFilterPanel = () => {
      {
        overviewStore.openProModal();
        return;
      }
    };
    const closeFilterPanel = () => {
      isFilterModalOpen.value = false;
    };
    const onApplyFilter = (filterData) => {
      overviewStore.setActiveFilters(
        filterData.filters || [],
        filterData.device || ""
      );
    };
    const openUpsellModal = () => {
      overviewStore.openProModal();
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(Fragment, null, [
        createBaseVNode("div", {
          class: normalizeClass(["monsterinsights-overview-report-header", {
            "monsterinsights-blur": shouldBlur.value,
            "monsterinsights-toolbar-gated": unref(overviewStore).reportUpsellActive
          }])
        }, [
          createBaseVNode("div", _hoisted_1$2, [
            createBaseVNode("div", _hoisted_2$2, [
              appliedFilters.value.length > 0 ? (openBlock(), createElementBlock("span", _hoisted_3$2, toDisplayString(unref(__$2)("Filters Applied:", "google-analytics-for-wordpress")), 1)) : createCommentVNode("", true),
              (openBlock(true), createElementBlock(Fragment, null, renderList(displayedFilters.value, (filter, index) => {
                return openBlock(), createElementBlock("div", {
                  key: index,
                  class: "monsterinsights-filter-tag"
                }, [
                  createBaseVNode("span", _hoisted_4$2, [
                    createBaseVNode("span", _hoisted_5$1, toDisplayString(filter.name) + ": ", 1),
                    createBaseVNode("span", _hoisted_6$1, toDisplayString(filter.value), 1)
                  ]),
                  createBaseVNode("button", {
                    type: "button",
                    class: "monsterinsights-filter-tag__remove",
                    "aria-label": `Remove ${filter.name} filter`,
                    onClick: ($event) => removeFilter(index)
                  }, [
                    createVNode(Icon, {
                      name: "close",
                      size: 12
                    })
                  ], 8, _hoisted_7$1)
                ]);
              }), 128)),
              additionalFiltersCount.value > 0 && !filtersExpanded.value ? (openBlock(), createElementBlock("button", {
                key: 1,
                type: "button",
                class: "monsterinsights-filter-count",
                onClick: _cache[0] || (_cache[0] = ($event) => filtersExpanded.value = true)
              }, toDisplayString(additionalFiltersCount.value) + "+ ", 1)) : createCommentVNode("", true),
              filtersExpanded.value && appliedFilters.value.length > MAX_VISIBLE_FILTERS ? (openBlock(), createElementBlock("button", {
                key: 2,
                type: "button",
                class: "monsterinsights-filter-collapse",
                onClick: _cache[1] || (_cache[1] = ($event) => filtersExpanded.value = false)
              }, toDisplayString(unref(__$2)("Collapse", "google-analytics-for-wordpress")), 1)) : createCommentVNode("", true),
              filtersExpanded.value && appliedFilters.value.length > MAX_VISIBLE_FILTERS ? (openBlock(), createElementBlock("button", {
                key: 3,
                type: "button",
                class: "monsterinsights-filter-clear-all",
                onClick: clearAllFilters
              }, toDisplayString(unref(__$2)("Clear All Filters", "google-analytics-for-wordpress")), 1)) : createCommentVNode("", true)
            ])
          ]),
          createBaseVNode("div", _hoisted_8$1, [
            createVNode(unref(_sfc_main$a), {
              "model-value": dateRangeModelValue.value,
              "allow-compare": allowCompare.value,
              "onUpdate:modelValue": onDateChange,
              onOpenUpsellModal: openUpsellModal
            }, null, 8, ["model-value", "allow-compare"]),
            !hideFilter.value ? (openBlock(), createElementBlock("button", {
              key: 0,
              type: "button",
              class: normalizeClass(["monsterinsights-header-btn", { "monsterinsights-header-btn--has-indicator": hasActiveFilters.value }]),
              onClick: openFilterPanel
            }, [
              createVNode(Icon, {
                name: "filter",
                size: 20
              }),
              createBaseVNode("span", _hoisted_9$1, toDisplayString(unref(__$2)("Filter", "google-analytics-for-wordpress")), 1),
              hasActiveFilters.value ? (openBlock(), createElementBlock("span", _hoisted_10$1)) : createCommentVNode("", true)
            ], 2)) : createCommentVNode("", true),
            createVNode(_sfc_main$5)
          ])
        ], 2),
        createVNode(_sfc_main$3, {
          "is-open": isFilterModalOpen.value,
          onClose: closeFilterPanel,
          onApplyFilter
        }, null, 8, ["is-open"])
      ], 64);
    };
  }
};
const _hoisted_1$1 = {
  key: 0,
  class: "overview-pro-feature-modal__em-layout"
};
const _hoisted_2$1 = {
  class: "overview-pro-feature-modal__em-icons",
  "aria-hidden": "true"
};
const _hoisted_3$1 = ["src"];
const _hoisted_4$1 = { class: "overview-pro-feature-modal__em-content" };
const _hoisted_5 = {
  id: "overview-pro-feature-modal-title",
  class: "overview-pro-feature-modal__title--em"
};
const _hoisted_6 = { class: "overview-pro-feature-modal__description--em" };
const _hoisted_7 = ["disabled"];
const _hoisted_8 = ["href"];
const _hoisted_9 = {
  key: 2,
  class: "overview-pro-feature-modal__error--em"
};
const _hoisted_10 = ["href"];
const _hoisted_11 = {
  id: "overview-pro-feature-modal-title",
  class: "overview-pro-feature-modal__title"
};
const _hoisted_12 = { class: "overview-pro-feature-modal__description" };
const _hoisted_13 = ["disabled"];
const _hoisted_14 = ["href"];
const _hoisted_15 = {
  key: 2,
  class: "overview-pro-feature-modal__error"
};
const _hoisted_16 = ["href"];
const _hoisted_17 = { class: "overview-pro-feature-modal__bonus" };
const _hoisted_18 = { class: "overview-pro-feature-modal__bonus-text" };
const _hoisted_19 = { class: "overview-pro-feature-modal__bonus-highlight" };
const settingsScreenUrl = "/wp-admin/admin.php?page=monsterinsights_settings";
const _sfc_main$1 = {
  __name: "OverviewProFeatureModal",
  props: {
    modelValue: {
      type: Boolean,
      default: false
    },
    /** Addon slug (e.g. 'page_insights', 'forms', 'ecommerce', 'dimensions'). When set for Pro users, shows addon install/activate UI instead of upgrade. */
    addonSlug: {
      type: String,
      default: ""
    },
    /** Display name for the addon (e.g. 'Page Insights'). */
    addonName: {
      type: String,
      default: ""
    }
  },
  emits: ["update:modelValue", "close", "upgrade", "already-purchased"],
  setup(__props, { emit: __emit }) {
    const dialogRef = ref(null);
    const props = __props;
    const emit = __emit;
    const isExactMetrics = false;
    const emArrowsUrl = new URL("" + new URL("../assets/em-arrows-Dq2c4rA5.jpg", import.meta.url).href, import.meta.url).href;
    const isProAddonMode = computed(() => isPro());
    const addonIsInstalled = computed(() => props.addonSlug ? isAddonInstalled(props.addonSlug) : false);
    const addonsPageUrl = computed(() => getAddonsPageUrl());
    const ADDON_DISPLAY_NAMES = {
      page_insights: __$2("Page Insights", "google-analytics-for-wordpress"),
      forms: __$2("Forms", "google-analytics-for-wordpress"),
      ecommerce: __$2("eCommerce", "google-analytics-for-wordpress"),
      dimensions: __$2("Dimensions", "google-analytics-for-wordpress")
    };
    const addonDisplayName = computed(
      () => props.addonName || ADDON_DISPLAY_NAMES[props.addonSlug] || props.addonSlug
    );
    const addonTitle = computed(() => {
      if (addonIsInstalled.value) {
        return __$2("Activate the %s Addon", "google-analytics-for-wordpress").replace("%s", addonDisplayName.value);
      }
      return __$2("Install the %s Addon", "google-analytics-for-wordpress").replace("%s", addonDisplayName.value);
    });
    const addonDescription = computed(() => {
      if (addonIsInstalled.value) {
        return __$2("The %s addon is installed but not active. Activate it to unlock these insights with your real data.", "google-analytics-for-wordpress").replace("%s", addonDisplayName.value);
      }
      return __$2("The %s addon is required to view this data. Install and activate it from the Addons page to unlock these insights.", "google-analytics-for-wordpress").replace("%s", addonDisplayName.value);
    });
    const isActivating = ref(false);
    const activationError = ref("");
    async function onActivateAddon() {
      if (!props.addonSlug || isActivating.value) return;
      const basename = getAddonBasename(props.addonSlug);
      if (!basename) {
        activationError.value = __$2("Could not find addon to activate.", "google-analytics-for-wordpress");
        return;
      }
      isActivating.value = true;
      activationError.value = "";
      try {
        const nonce = getMiGlobal$1("activate_nonce", "");
        const ajax = getMiGlobal$1("ajax", "");
        const isNetwork = getMiGlobal$1("network", false);
        const formData = new FormData();
        formData.append("action", "monsterinsights_activate_addon");
        formData.append("nonce", nonce);
        formData.append("plugin", basename);
        if (isNetwork) {
          formData.append("isnetwork", "true");
        }
        const response = await fetch(ajax, {
          method: "POST",
          credentials: "same-origin",
          body: formData
        });
        const result = await response.json();
        if (result === true || result?.success) {
          try {
            localStorage.removeItem("mi_cache_registry");
          } catch (e) {
          }
          window.location.reload();
        } else {
          activationError.value = result?.error || result?.data || __$2("Failed to activate addon. Please try from the Addons page.", "google-analytics-for-wordpress");
          isActivating.value = false;
        }
      } catch {
        activationError.value = __$2("Failed to activate addon. Please try from the Addons page.", "google-analytics-for-wordpress");
        isActivating.value = false;
      }
    }
    function onInstallAddon() {
      close();
    }
    const title = computed(
      () => __$2("This is a Pro Feature", "google-analytics-for-wordpress")
    );
    const description = computed(
      () => __$2(
        "We're sorry, this feature is not available on your plan. Please upgrade to the Pro plan to unlock all these awesome features.",
        "google-analytics-for-wordpress"
      )
    );
    const ctaText = computed(
      () => __$2("Upgrade to Pro", "google-analytics-for-wordpress")
    );
    const bonusLabel = computed(() => __$2("Bonus:", "google-analytics-for-wordpress"));
    const bonusText = computed(
      () => __$2("MonsterInsights Lite users get ", "google-analytics-for-wordpress")
    );
    const bonusHighlight = computed(() => __$2("50% off", "google-analytics-for-wordpress"));
    const bonusSuffix = computed(
      () => __$2("regular price, automatically applied at checkout.", "google-analytics-for-wordpress")
    );
    const alreadyPurchasedText = computed(() => __$2("Already purchased?", "google-analytics-for-wordpress"));
    const upgradeUrl = computed(
      () => getUpgradeUrl(
        "overview-pro-feature-modal",
        "overview-report",
        "https://www.monsterinsights.com/lite/"
      )
    );
    function close() {
      activationError.value = "";
      emit("update:modelValue", false);
      emit("close");
    }
    function onModelValue(value) {
      if (!value) {
        close();
      }
    }
    function handleKeydown(event) {
      if (event.key === "Escape") {
        event.preventDefault();
        close();
      }
    }
    watch(
      () => props.modelValue,
      (isOpen) => {
        if (isOpen) {
          document.addEventListener("keydown", handleKeydown);
          setTimeout(() => {
            const focusable = dialogRef.value?.querySelector?.('a[href], button, [tabindex]:not([tabindex="-1"])');
            focusable?.focus?.();
          }, 0);
        } else {
          document.removeEventListener("keydown", handleKeydown);
        }
      },
      { immediate: true }
    );
    onUnmounted(() => {
      document.removeEventListener("keydown", handleKeydown);
    });
    function onUpgradeClick() {
      emit("upgrade", upgradeUrl.value);
    }
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$b, {
        "model-value": __props.modelValue,
        mode: "dialog",
        "content-class": "monsterinsights-dialog-shell",
        "overlay-class": "monsterinsights-dialog-shell-overlay",
        dismissable: true,
        "onUpdate:modelValue": onModelValue
      }, {
        default: withCtx(() => [
          createBaseVNode("div", {
            class: normalizeClass(["overview-pro-feature-modal", { "overview-pro-feature-modal--exactmetrics": isExactMetrics }]),
            ref_key: "dialogRef",
            ref: dialogRef,
            role: "dialog",
            "aria-modal": "true",
            "aria-labelledby": "overview-pro-feature-modal-title"
          }, [
            createBaseVNode("button", {
              type: "button",
              class: "overview-pro-feature-modal__close",
              "aria-label": "Close",
              onClick: close
            }, [..._cache[0] || (_cache[0] = [
              createBaseVNode("svg", {
                width: "20",
                height: "20",
                viewBox: "0 0 20 20",
                fill: "none",
                xmlns: "http://www.w3.org/2000/svg",
                "aria-hidden": "true"
              }, [
                createBaseVNode("path", {
                  d: "M16.3333 4.34286L14.9905 3L9.66667 8.32381L4.34286 3L3 4.34286L8.32381 9.66667L3 14.9905L4.34286 16.3333L9.66667 11.0095L14.9905 16.3333L16.3333 14.9905L11.0095 9.66667L16.3333 4.34286Z",
                  fill: "#BDBDBD"
                })
              ], -1)
            ])]),
            isExactMetrics ? (openBlock(), createElementBlock("div", _hoisted_1$1, [
              createBaseVNode("div", _hoisted_2$1, [
                createBaseVNode("img", {
                  src: unref(emArrowsUrl),
                  alt: "",
                  class: "overview-pro-feature-modal__em-icons-img"
                }, null, 8, _hoisted_3$1)
              ]),
              createBaseVNode("div", _hoisted_4$1, [
                createBaseVNode("h2", _hoisted_5, toDisplayString(isProAddonMode.value ? addonTitle.value : title.value), 1),
                createBaseVNode("p", _hoisted_6, toDisplayString(isProAddonMode.value ? addonDescription.value : description.value), 1),
                isProAddonMode.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                  addonIsInstalled.value ? (openBlock(), createElementBlock("button", {
                    key: 0,
                    class: "overview-pro-feature-modal__cta--em overview-pro-feature-modal__cta--em-btn",
                    disabled: isActivating.value,
                    onClick: onActivateAddon
                  }, [
                    createBaseVNode("span", null, toDisplayString(isActivating.value ? unref(__$2)("Activating…", "google-analytics-for-wordpress") : unref(__$2)("Activate Addon", "google-analytics-for-wordpress")), 1)
                  ], 8, _hoisted_7)) : (openBlock(), createElementBlock("a", {
                    key: 1,
                    href: addonsPageUrl.value,
                    class: "overview-pro-feature-modal__cta--em",
                    onClick: onInstallAddon
                  }, [
                    createBaseVNode("span", null, toDisplayString(unref(__$2)("Go to Addons Page", "google-analytics-for-wordpress")), 1),
                    _cache[1] || (_cache[1] = createBaseVNode("svg", {
                      width: "20",
                      height: "20",
                      viewBox: "0 0 20 20",
                      fill: "none",
                      xmlns: "http://www.w3.org/2000/svg",
                      class: "overview-pro-feature-modal__cta-arrow overview-pro-feature-modal__cta-arrow--em",
                      "aria-hidden": "true"
                    }, [
                      createBaseVNode("path", {
                        d: "M4.16675 10H15.8334",
                        stroke: "currentColor",
                        "stroke-width": "2",
                        "stroke-linecap": "round",
                        "stroke-linejoin": "round"
                      }),
                      createBaseVNode("path", {
                        d: "M10 4.16663L15.8333 9.99996L10 15.8333",
                        stroke: "currentColor",
                        "stroke-width": "2",
                        "stroke-linecap": "round",
                        "stroke-linejoin": "round"
                      })
                    ], -1))
                  ], 8, _hoisted_8)),
                  activationError.value ? (openBlock(), createElementBlock("p", _hoisted_9, toDisplayString(activationError.value), 1)) : createCommentVNode("", true)
                ], 64)) : (openBlock(), createElementBlock("a", {
                  key: 1,
                  href: upgradeUrl.value,
                  target: "_blank",
                  rel: "noopener noreferrer",
                  class: "overview-pro-feature-modal__cta--em",
                  onClick: onUpgradeClick
                }, [
                  createBaseVNode("span", null, toDisplayString(ctaText.value), 1),
                  _cache[2] || (_cache[2] = createBaseVNode("svg", {
                    width: "20",
                    height: "20",
                    viewBox: "0 0 20 20",
                    fill: "none",
                    xmlns: "http://www.w3.org/2000/svg",
                    class: "overview-pro-feature-modal__cta-arrow overview-pro-feature-modal__cta-arrow--em",
                    "aria-hidden": "true"
                  }, [
                    createBaseVNode("path", {
                      d: "M4.16675 10H15.8334",
                      stroke: "currentColor",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    }),
                    createBaseVNode("path", {
                      d: "M10 4.16663L15.8333 9.99996L10 15.8333",
                      stroke: "currentColor",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    })
                  ], -1))
                ], 8, _hoisted_10))
              ])
            ])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
              _cache[6] || (_cache[6] = createBaseVNode("div", { class: "overview-pro-feature-modal__lock" }, [
                createBaseVNode("svg", {
                  width: "40",
                  height: "40",
                  viewBox: "0 0 40 40",
                  fill: "none",
                  xmlns: "http://www.w3.org/2000/svg",
                  "aria-hidden": "true"
                }, [
                  createBaseVNode("path", {
                    d: "M30.0269 15.7465V11.0267C30.0269 5.50008 25.5336 1 20.0002 1C14.4735 1 9.97344 5.50008 9.97344 11.0267V15.7465C7.66009 15.9399 5.84009 17.8932 5.84009 20.253V25.8799C5.84009 33.1132 11.72 39 18.9533 39H21.0467C28.28 39 34.1599 33.1132 34.1599 25.8799V20.253C34.1599 17.893 32.3402 15.9398 30.0269 15.7465ZM14.3135 11.0267C14.6252 3.49175 25.3753 3.49345 25.6868 11.0267V15.7269H14.3135L14.3135 11.0267ZM18.4136 27.887C16.0735 26.3603 17.2152 22.6287 20.0003 22.6535C22.7853 22.6301 23.9286 26.3585 21.587 27.887C21.4069 28.007 21.2936 28.2203 21.2936 28.4403V30.7803C21.2503 32.4837 18.7519 32.487 18.7069 30.7803V28.4403C18.7069 28.2203 18.5936 28.007 18.4136 27.887Z",
                    fill: "#777777"
                  })
                ])
              ], -1)),
              createBaseVNode("h2", _hoisted_11, toDisplayString(isProAddonMode.value ? addonTitle.value : title.value), 1),
              createBaseVNode("p", _hoisted_12, toDisplayString(isProAddonMode.value ? addonDescription.value : description.value), 1),
              isProAddonMode.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                addonIsInstalled.value ? (openBlock(), createElementBlock("button", {
                  key: 0,
                  class: "overview-pro-feature-modal__cta overview-pro-feature-modal__cta--btn",
                  disabled: isActivating.value,
                  onClick: onActivateAddon
                }, [
                  createBaseVNode("span", null, toDisplayString(isActivating.value ? unref(__$2)("Activating…", "google-analytics-for-wordpress") : unref(__$2)("Activate Addon", "google-analytics-for-wordpress")), 1)
                ], 8, _hoisted_13)) : (openBlock(), createElementBlock("a", {
                  key: 1,
                  href: addonsPageUrl.value,
                  class: "overview-pro-feature-modal__cta",
                  onClick: onInstallAddon
                }, [
                  createBaseVNode("span", null, toDisplayString(unref(__$2)("Go to Addons Page", "google-analytics-for-wordpress")), 1),
                  _cache[3] || (_cache[3] = createBaseVNode("svg", {
                    width: "20",
                    height: "20",
                    viewBox: "0 0 20 20",
                    fill: "none",
                    xmlns: "http://www.w3.org/2000/svg",
                    class: "overview-pro-feature-modal__cta-arrow",
                    "aria-hidden": "true"
                  }, [
                    createBaseVNode("path", {
                      d: "M4.16675 10H15.8334",
                      stroke: "white",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    }),
                    createBaseVNode("path", {
                      d: "M10 4.16663L15.8333 9.99996L10 15.8333",
                      stroke: "white",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    })
                  ], -1))
                ], 8, _hoisted_14)),
                activationError.value ? (openBlock(), createElementBlock("p", _hoisted_15, toDisplayString(activationError.value), 1)) : createCommentVNode("", true)
              ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
                createBaseVNode("a", {
                  href: upgradeUrl.value,
                  target: "_blank",
                  rel: "noopener noreferrer",
                  class: "overview-pro-feature-modal__cta",
                  onClick: onUpgradeClick
                }, [
                  createBaseVNode("span", null, toDisplayString(ctaText.value), 1),
                  _cache[4] || (_cache[4] = createBaseVNode("svg", {
                    width: "20",
                    height: "20",
                    viewBox: "0 0 20 20",
                    fill: "none",
                    xmlns: "http://www.w3.org/2000/svg",
                    class: "overview-pro-feature-modal__cta-arrow",
                    "aria-hidden": "true"
                  }, [
                    createBaseVNode("path", {
                      d: "M4.16675 10H15.8334",
                      stroke: "white",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    }),
                    createBaseVNode("path", {
                      d: "M10 4.16663L15.8333 9.99996L10 15.8333",
                      stroke: "white",
                      "stroke-width": "2",
                      "stroke-linecap": "round",
                      "stroke-linejoin": "round"
                    })
                  ], -1))
                ], 8, _hoisted_16),
                createBaseVNode("div", _hoisted_17, [
                  _cache[5] || (_cache[5] = createBaseVNode("span", {
                    class: "overview-pro-feature-modal__bonus-check",
                    "aria-hidden": "true"
                  }, [
                    createBaseVNode("svg", {
                      width: "29",
                      height: "31",
                      viewBox: "0 0 29 31",
                      fill: "none",
                      xmlns: "http://www.w3.org/2000/svg"
                    }, [
                      createBaseVNode("g", { "clip-path": "url(#clip0_bonus_check_modal)" }, [
                        createBaseVNode("path", {
                          d: "M14.4595 1.96826C14.6331 1.96837 14.8972 2.09466 15.4517 2.54443C15.6798 2.72949 15.9791 2.98518 16.2671 3.19287C16.5246 3.37856 16.8399 3.57738 17.2026 3.70654L17.3608 3.75732C17.7954 3.88135 18.2296 3.88536 18.5952 3.86084C18.9522 3.8369 19.3343 3.77666 19.6206 3.73877C20.3144 3.64697 20.5774 3.67853 20.7124 3.76221C20.8769 3.86412 21.053 4.13848 21.3247 4.82959C21.4382 5.11834 21.5762 5.49494 21.73 5.82959C21.8864 6.16984 22.0968 6.55449 22.4019 6.88135C22.7095 7.2109 23.0751 7.44094 23.4009 7.61279C23.7175 7.77984 24.0752 7.93063 24.3403 8.05029C24.9694 8.33418 25.2187 8.51344 25.3208 8.70264C25.4276 8.90041 25.4459 9.25006 25.3608 9.98779C25.2932 10.5742 25.1363 11.5163 25.3384 12.3296V12.3306C25.4464 12.764 25.6514 13.1457 25.8491 13.4604C26.0415 13.7666 26.2776 14.0843 26.4517 14.3306C26.8589 14.9068 27.015 15.2297 27.0151 15.4917C27.0151 15.7537 26.859 16.0764 26.4517 16.6528C26.2776 16.8992 26.0416 17.2176 25.8491 17.5239C25.6761 17.7994 25.4975 18.1258 25.3833 18.4937L25.3384 18.6538C25.1362 19.4671 25.2932 20.4091 25.3608 20.9956C25.4459 21.7332 25.4274 22.0829 25.3208 22.2808C25.2187 22.47 24.9694 22.6492 24.3403 22.9331C24.0751 23.0528 23.7176 23.2045 23.4009 23.3716C23.0753 23.5434 22.7094 23.7727 22.4019 24.1021C22.0967 24.429 21.8864 24.8145 21.73 25.1548C21.5763 25.4893 21.4382 25.8651 21.3247 26.1538C21.0869 26.7588 20.9225 27.045 20.7749 27.1753L20.7124 27.2222C20.5773 27.3058 20.3142 27.3364 19.6206 27.2446C19.3343 27.2067 18.9521 27.1475 18.5952 27.1235C18.2296 27.099 17.7954 27.1021 17.3608 27.2261V27.2271C16.9311 27.35 16.5613 27.5793 16.2671 27.7915C15.9791 27.9992 15.6797 28.2549 15.4517 28.4399C14.8972 28.8897 14.6331 29.016 14.4595 29.0161C14.2859 29.0161 14.0218 28.8897 13.4673 28.4399C13.2391 28.2549 12.939 27.9993 12.6509 27.7915C12.3568 27.5794 11.9876 27.35 11.5581 27.2271L11.5571 27.2261C11.1228 27.1021 10.6893 27.099 10.3237 27.1235C9.96688 27.1475 9.58462 27.2067 9.29834 27.2446C8.6051 27.3364 8.34171 27.3056 8.20654 27.2222H8.20557C8.04114 27.1202 7.86588 26.8448 7.59424 26.1538C7.48073 25.8651 7.34176 25.4894 7.18799 25.1548C7.0316 24.8145 6.82222 24.429 6.51709 24.1021C6.20948 23.7725 5.84282 23.5434 5.51709 23.3716C5.20033 23.2045 4.84279 23.0528 4.57764 22.9331C3.94874 22.6493 3.70026 22.4699 3.59814 22.2808C3.49144 22.0829 3.47305 21.7334 3.55811 20.9956C3.62573 20.4091 3.7818 19.4671 3.57959 18.6538L3.53467 18.4937C3.42049 18.1259 3.24283 17.7993 3.06982 17.5239C2.87732 17.2175 2.64044 16.8993 2.46631 16.6528C2.05906 16.0765 1.90381 15.7537 1.90381 15.4917C1.90391 15.2297 2.05911 14.9068 2.46631 14.3306C2.64038 14.0842 2.87739 13.7667 3.06982 13.4604C3.26751 13.1458 3.47155 12.764 3.57959 12.3306V12.3296C3.78175 11.5163 3.62572 10.5743 3.55811 9.98779C3.47308 9.25003 3.49137 8.90041 3.59814 8.70264C3.70031 8.51349 3.94873 8.33411 4.57764 8.05029C4.84274 7.93066 5.20038 7.77984 5.51709 7.61279C5.84287 7.44092 6.20945 7.21097 6.51709 6.88135C6.82205 6.55457 7.03164 6.16975 7.18799 5.82959C7.34178 5.49494 7.48072 5.11834 7.59424 4.82959C7.8657 4.13912 8.04122 3.8643 8.20557 3.76221H8.20654C8.34164 3.67864 8.60474 3.64698 9.29834 3.73877C9.58463 3.77666 9.96685 3.83691 10.3237 3.86084C10.6893 3.88533 11.1228 3.88128 11.5571 3.75732H11.5581C11.9875 3.63444 12.3568 3.40494 12.6509 3.19287C12.939 2.98511 13.2391 2.72952 13.4673 2.54443C14.022 2.09449 14.2859 1.96826 14.4595 1.96826Z",
                          fill: "#219653",
                          stroke: "white",
                          "stroke-width": "2"
                        }),
                        createBaseVNode("path", {
                          d: "M18.3768 11.1638L13.2167 16.6925L10.5418 13.8289C9.96113 13.2068 9.01902 13.2068 8.4384 13.8289C7.85777 14.451 7.85777 15.4604 8.4384 16.0825L12.191 20.1032C12.7558 20.7083 13.6731 20.7083 14.2379 20.1032L20.4779 13.4174C21.0585 12.7953 21.0585 11.7859 20.4779 11.1638C19.8973 10.5417 18.9574 10.5417 18.3768 11.1638Z",
                          fill: "#FFFCEE"
                        })
                      ]),
                      createBaseVNode("defs", null, [
                        createBaseVNode("clipPath", { id: "clip0_bonus_check_modal" }, [
                          createBaseVNode("rect", {
                            width: "28.9183",
                            height: "30.9839",
                            fill: "white"
                          })
                        ])
                      ])
                    ])
                  ], -1)),
                  createBaseVNode("p", _hoisted_18, [
                    createBaseVNode("strong", null, toDisplayString(bonusLabel.value), 1),
                    createTextVNode(" " + toDisplayString(bonusText.value) + " ", 1),
                    createBaseVNode("strong", _hoisted_19, toDisplayString(bonusHighlight.value), 1),
                    createTextVNode(" " + toDisplayString(bonusSuffix.value), 1)
                  ])
                ]),
                createBaseVNode("a", {
                  href: settingsScreenUrl,
                  class: "overview-pro-feature-modal__already-purchased"
                }, toDisplayString(alreadyPurchasedText.value), 1)
              ], 64))
            ], 64))
          ], 2)
        ]),
        _: 1
      }, 8, ["model-value"]);
    };
  }
};
const OverviewProFeatureModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-f2f0143a"]]);
const _hoisted_1 = { class: "monsterinsights-report-content" };
const _hoisted_2 = {
  key: 0,
  class: "monsterinsights-license-notice"
};
const _hoisted_3 = ["href"];
const _hoisted_4 = { class: "monsterinsights-report-notices" };
const _sfc_main = {
  __name: "App",
  setup(__props) {
    const route = useRoute();
    const overviewStore = useOverviewReportStore();
    const { isAuthenticated } = useAuthGate();
    const isLicenseExpired = computed(() => getMiGlobal$1("license_expired", false));
    const licenseRenewalUrl = computed(() => getUrl("admin-notices", "license-expired", "https://www.monsterinsights.com/my-account/"));
    const hideReportNav = computed(() => route.meta?.hideNav === true);
    const navStuck = ref(false);
    const headerStuck = ref(false);
    const appRoot = ref(null);
    const stickyNav = ref(null);
    const stickyHeader = ref(null);
    const adminBarOffset = () => window.innerWidth <= 782 ? 46 : 32;
    const showUniversally = computed(
      () => ["countries", "ecommerce-purchases-by-location"].includes(route.name) && isAuthenticated.value && !overviewStore.reportUpsellActive
    );
    function updateGateOffset() {
      const root = appRoot.value;
      if (!root) {
        return;
      }
      const nav = stickyNav.value;
      if (nav) {
        root.style.setProperty("--mi-report-nav-height", `${Math.round(nav.getBoundingClientRect().height)}px`);
      }
      const bottomBar = stickyHeader.value || nav;
      const offset = bottomBar ? Math.max(0, Math.round(bottomBar.getBoundingClientRect().bottom)) : 0;
      root.style.setProperty("--mi-report-gate-top", `${offset}px`);
    }
    function onScroll() {
      updateGateOffset();
      const topOffset = adminBarOffset();
      const nav = stickyNav.value;
      const header = stickyHeader.value;
      navStuck.value = nav ? Math.round(nav.getBoundingClientRect().top) <= topOffset + 1 : false;
      const navHeight = nav ? nav.getBoundingClientRect().height : 0;
      headerStuck.value = header ? Math.round(header.getBoundingClientRect().top) <= topOffset + navHeight + 1 : false;
    }
    let resizeObserver = null;
    onMounted(() => {
      window.addEventListener("scroll", onScroll, { passive: true });
      window.addEventListener("resize", onScroll, { passive: true });
      if (typeof ResizeObserver !== "undefined") {
        resizeObserver = new ResizeObserver(() => onScroll());
        if (stickyNav.value) {
          resizeObserver.observe(stickyNav.value);
        }
        if (stickyHeader.value) {
          resizeObserver.observe(stickyHeader.value);
        }
      }
      onScroll();
    });
    onUnmounted(() => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
      if (resizeObserver) {
        resizeObserver.disconnect();
        resizeObserver = null;
      }
    });
    watch(() => route.name, () => {
      nextTick(onScroll);
    });
    const REPORT_SUBMENU_MAP = [
      { match: "user-journey-report", selector: '.wp-submenu [href*="monsterinsights_reports#/user-journey-report"]' }
    ];
    let cached_reports_link = null;
    let cached_report_submenu_links = [];
    function updateReportsMenuHighlight(name) {
      const matched = name ? REPORT_SUBMENU_MAP.find(({ match }) => name.indexOf(match) >= 0) : null;
      const submenu_link = matched ? cached_report_submenu_links.find((x) => x.match === matched.match)?.el : null;
      cached_report_submenu_links.forEach(({ el }) => {
        if (el) el.parentElement.classList.remove("current");
      });
      if (cached_reports_link) cached_reports_link.parentElement.classList.remove("current");
      if (submenu_link) {
        submenu_link.parentElement.classList.add("current");
      } else if (cached_reports_link) {
        cached_reports_link.parentElement.classList.add("current");
      }
    }
    watch(() => route.name, (name) => updateReportsMenuHighlight(name));
    onMounted(() => {
      cached_reports_link = document.querySelector('a[href="admin.php?page=monsterinsights_reports"]') || null;
      cached_report_submenu_links = REPORT_SUBMENU_MAP.map(({ match, selector }) => ({
        match,
        el: document.querySelector(selector)
      }));
      updateReportsMenuHighlight(route.name);
    });
    return (_ctx, _cache) => {
      const _component_RouterView = resolveComponent("RouterView");
      return openBlock(), createElementBlock("div", {
        ref_key: "appRoot",
        ref: appRoot,
        class: normalizeClass(["monsterinsights-admin-page monsterinsights-reports-page monsterinsights-overview-report-app monsterinsights-app-surface", unref(route).name && `monsterinsights-${unref(route).name}-report-page`])
      }, [
        createBaseVNode("div", _hoisted_1, [
          createVNode(_sfc_main$c),
          isLicenseExpired.value ? (openBlock(), createElementBlock("div", _hoisted_2, [
            createBaseVNode("p", null, [
              createTextVNode(toDisplayString(unref(__$2)("Your MonsterInsights license has expired or has an error. Some reports may not load correctly.", "google-analytics-for-wordpress")) + " ", 1),
              createBaseVNode("a", {
                href: licenseRenewalUrl.value,
                target: "_blank"
              }, toDisplayString(unref(__$2)("Renew your license", "google-analytics-for-wordpress")), 9, _hoisted_3)
            ])
          ])) : createCommentVNode("", true),
          !hideReportNav.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
            createBaseVNode("div", {
              ref_key: "stickyNav",
              ref: stickyNav,
              class: normalizeClass(["monsterinsights-sticky-bar monsterinsights-sticky-bar--nav", { "is-scrolled": navStuck.value }])
            }, [
              createVNode(_sfc_main$6)
            ], 2),
            showUniversally.value ? (openBlock(), createBlock(UniversallyPromo, {
              key: 0,
              class: "monsterinsights-report__universally-promo",
              "promo-id": `universally_${unref(route).name}`,
              text: unref(__$2)("Reach more of your global audience by translating your website with Universally. ", "google-analytics-for-wordpress"),
              "show-info": ""
            }, null, 8, ["promo-id", "text"])) : createCommentVNode("", true),
            createBaseVNode("div", _hoisted_4, [
              createVNode(_sfc_main$d)
            ]),
            !unref(route).meta?.hideDateControls && unref(route).name !== "user-journey-report" ? (openBlock(), createElementBlock("div", {
              key: 1,
              ref_key: "stickyHeader",
              ref: stickyHeader,
              class: normalizeClass(["monsterinsights-sticky-bar monsterinsights-sticky-bar--header", { "is-scrolled": headerStuck.value }])
            }, [
              createVNode(_sfc_main$2)
            ], 2)) : createCommentVNode("", true)
          ], 64)) : (openBlock(), createBlock(_sfc_main$d, { key: 2 })),
          createBaseVNode("div", {
            class: normalizeClass(hideReportNav.value ? "" : "monsterinsights-container")
          }, [
            createVNode(_component_RouterView)
          ], 2)
        ]),
        createVNode(OverviewProFeatureModal, {
          modelValue: unref(overviewStore).showProModal,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(overviewStore).showProModal = $event)
        }, null, 8, ["modelValue"]),
        createVNode(_sfc_main$e)
      ], 2);
    };
  }
};
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // Reset scroll to the top when navigating between reports; restore the
  // previous position on browser back/forward.
  scrollBehavior(_to, _from, savedPosition) {
    return savedPosition || { top: 0 };
  }
});
const app = createApp(_sfc_main);
setupPinia(app);
app.use(router);
installOverlays(app);
router.beforeEach(() => {
  useOverviewReportStore().reportUpsellActive = false;
});
app.mount("#monsterinsights-overview-report-app");
export {
  applyFiltersToQuery as A,
  relayReportingQuery as B,
  CUSTOM_DIMENSIONS_DIMENSION_TAB as C,
  DEMOGRAPHICS_TAB_TO_QUERY_ID as D,
  relayFallbackFetch as E,
  isSampleDataEnabled$1 as F,
  rejectReport as G,
  createRequestQueue as H,
  DEFAULT_ECOMMERCE_FUNNEL as I,
  useCachedFetch as J,
  getBackfillCache as K,
  fetchOverviewSection as L,
  MC_TAB_TO_QUERY_ID as M,
  backfillToWp as N,
  OverviewProFeatureModal as O,
  PAGES_TAB_TO_QUERY_ID as P,
  QUERY_DIMENSIONS as Q,
  buildCacheKey as R,
  _sfc_main$5 as _,
  getTabMetricsForQuery as a,
  buildApiFilters as b,
  generateSampleCustomDimensionsData as c,
  fetchCustomDimensionsData as d,
  fetchCustomDimensionsDeferredData as e,
  fetchOverviewData as f,
  getInjectedMetricNames as g,
  filterTabbedData as h,
  CUSTOM_DIMENSIONS_TAB_TO_QUERY_ID as i,
  fetchFunnelData as j,
  getResponseDimensionOrder as k,
  generateSampleBundleData as l,
  fetchFormSubmissionsData as m,
  filterFormSubmissionsData as n,
  fetchEcommerceOverviewData as o,
  fetchMarketingCampaignsData as p,
  fetchPagesData as q,
  fetchTopPagesData as r,
  fetchDemographicsData as s,
  fetchDevicesData as t,
  useOverviewReportStore as u,
  MC_DIMENSION_TAB as v,
  PAGES_DIMENSION_TAB as w,
  DEMOGRAPHICS_DIMENSION_TAB as x,
  DEVICES_TAB_TO_QUERY_ID as y,
  DEVICES_DIMENSION_TAB as z
};
