import { jsx as t, jsxs as i, Fragment as R } from "react/jsx-runtime";
import { c as B, u as N, B as _, aA as dt, E as Vt, L as jr, a2 as qr, a as te, aB as Hr, aC as Vr, aD as rt, aE as me, aF as ct, aG as Kt, f as $e, X as Qt, aH as Wt, aI as Kr, G as Rt, Z as Qr, _ as Wr, $ as Jr, a1 as Xr, S as Ut, j as Yr, aJ as Zr } from "./switch-xcWLtWs0.js";
import { bg as ea, u as G, c as Jt, bh as ta, aI as re, d as Xt, e as ra, f as at, g as nt, o as aa, bi as ue, aV as Fe, bj as na, bk as Tt, bl as Yt, bm as Zt, bn as sa, b9 as lt, bo as oa, bp as ia, bq as da, br as ca, bs as la, bt as ua, ae as pe, bu as he, p as C, bv as ma, bw as er, az as ut, be as pa, bx as ha, by as fa, aU as tr, aX as rr, ay as ga, aM as ba, bz as xa, bA as va, z as ya, y as Ue, K as wa, A as Xe, bB as Na, bC as Sa, bD as Da, _ as ka, bE as Ca, I as Ye, bF as Ea, bG as La, bH as Ia, bI as Aa, aN as Ma, aO as Pa, aP as Oa, aQ as _a, aR as $, bJ as Ra, aS as Ft, bK as Ua, bL as Ta, bM as Fa, J as $a, bN as Ga, b0 as Ba, b1 as za, b2 as ja, b3 as qa, b4 as Ha, b5 as Va, b6 as Ka, b7 as $t, w as st } from "./index-DZ3lq1Pk.js";
import "./index-CuHybtft.js";
import * as I from "react";
import ar, { useState as w, useMemo as K, useEffect as Ge, useRef as Gt, useLayoutEffect as Qa, useCallback as Wa } from "react";
import "./index-CJdxSyQq.js";
import "react-dom/client";
import { createPortal as Ja } from "react-dom";
import { L as Xa, b as Ya, u as Za, A as en, V as tn, K as rn, e as an, M as nn, N as sn, U as on } from "./dashboard-briefing-launcher-gm3YPxOh.js";
import { d as nr } from "./index-DFOb_6HB.js";
import { C as dn } from "./calendar-preferences-dialog-BeZvsJV0.js";
import { u as cn } from "./use-debounced-dirty-check-BwAbnX_5.js";
import { s as Ze } from "./normalize-dashboard-for-dirty-check-5KpZN8xr.js";
import { P as ln } from "./palette-DPuAc82h.js";
import { B as un } from "./braces-CXvY9MwQ.js";
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const mn = B("Glasses", [
  ["circle", { cx: "6", cy: "15", r: "4", key: "vux9w4" }],
  ["circle", { cx: "18", cy: "15", r: "4", key: "18o8ve" }],
  ["path", { d: "M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2", key: "1ag4bs" }],
  ["path", { d: "M2.5 13 5 7c.7-1.3 1.4-2 3-2", key: "1hm1gs" }],
  ["path", { d: "M21.5 13 19 7c-.7-1.3-1.5-2-3-2", key: "1r31ai" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const pn = B("Menu", [
  ["line", { x1: "4", x2: "20", y1: "12", y2: "12", key: "1e0a9i" }],
  ["line", { x1: "4", x2: "20", y1: "6", y2: "6", key: "1owob3" }],
  ["line", { x1: "4", x2: "20", y1: "18", y2: "18", key: "yk5zj1" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const hn = B("Monitor", [
  ["rect", { width: "20", height: "14", x: "2", y: "3", rx: "2", key: "48i651" }],
  ["line", { x1: "8", x2: "16", y1: "21", y2: "21", key: "1svkeh" }],
  ["line", { x1: "12", x2: "12", y1: "17", y2: "21", key: "vw1qmm" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const fn = B("Moon", [
  ["path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z", key: "a7tn18" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const gn = B("ShieldX", [
  [
    "path",
    {
      d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
      key: "oel41y"
    }
  ],
  ["path", { d: "m14.5 9.5-5 5", key: "17q4r4" }],
  ["path", { d: "m9.5 9.5 5 5", key: "18nt4w" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const bn = B("Sun", [
  ["circle", { cx: "12", cy: "12", r: "4", key: "4exip2" }],
  ["path", { d: "M12 2v2", key: "tus03m" }],
  ["path", { d: "M12 20v2", key: "1lh1kg" }],
  ["path", { d: "m4.93 4.93 1.41 1.41", key: "149t6j" }],
  ["path", { d: "m17.66 17.66 1.41 1.41", key: "ptbguv" }],
  ["path", { d: "M2 12h2", key: "1t8f8n" }],
  ["path", { d: "M20 12h2", key: "1q8mjw" }],
  ["path", { d: "m6.34 17.66-1.41 1.41", key: "1m8zz5" }],
  ["path", { d: "m19.07 4.93-1.41 1.41", key: "1shlcs" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const xn = B("UserPlus", [
  ["path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", key: "1yyitq" }],
  ["circle", { cx: "9", cy: "7", r: "4", key: "nufk8" }],
  ["line", { x1: "19", x2: "19", y1: "8", y2: "14", key: "1bvyxn" }],
  ["line", { x1: "22", x2: "16", y1: "11", y2: "11", key: "1shjgl" }]
]);
/**
 * @license lucide-react v0.453.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const sr = B("UserRound", [
  ["circle", { cx: "12", cy: "8", r: "5", key: "1hypcn" }],
  ["path", { d: "M20 21a8 8 0 0 0-16 0", key: "rfgkzh" }]
]);
var ot = { exports: {} }, et = {};
/**
 * @license React
 * use-sync-external-store-shim.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Bt;
function vn() {
  if (Bt) return et;
  Bt = 1;
  var e = ar;
  function n(c, h) {
    return c === h && (c !== 0 || 1 / c === 1 / h) || c !== c && h !== h;
  }
  var a = typeof Object.is == "function" ? Object.is : n, r = e.useState, s = e.useEffect, u = e.useLayoutEffect, f = e.useDebugValue;
  function l(c, h) {
    var m = h(), g = r({ inst: { value: m, getSnapshot: h } }), o = g[0].inst, y = g[1];
    return u(
      function() {
        o.value = m, o.getSnapshot = h, b(o) && y({ inst: o });
      },
      [c, m, h]
    ), s(
      function() {
        return b(o) && y({ inst: o }), c(function() {
          b(o) && y({ inst: o });
        });
      },
      [c]
    ), f(m), m;
  }
  function b(c) {
    var h = c.getSnapshot;
    c = c.value;
    try {
      var m = h();
      return !a(c, m);
    } catch {
      return !0;
    }
  }
  function x(c, h) {
    return h();
  }
  var p = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? x : l;
  return et.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : p, et;
}
var tt = {};
/**
 * @license React
 * use-sync-external-store-shim.development.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var zt;
function yn() {
  return zt || (zt = 1, process.env.NODE_ENV !== "production" && function() {
    function e(m, g) {
      return m === g && (m !== 0 || 1 / m === 1 / g) || m !== m && g !== g;
    }
    function n(m, g) {
      p || s.startTransition === void 0 || (p = !0, console.error(
        "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
      ));
      var o = g();
      if (!c) {
        var y = g();
        u(o, y) || (console.error(
          "The result of getSnapshot should be cached to avoid an infinite loop"
        ), c = !0);
      }
      y = f({
        inst: { value: o, getSnapshot: g }
      });
      var S = y[0].inst, k = y[1];
      return b(
        function() {
          S.value = o, S.getSnapshot = g, a(S) && k({ inst: S });
        },
        [m, o, g]
      ), l(
        function() {
          return a(S) && k({ inst: S }), m(function() {
            a(S) && k({ inst: S });
          });
        },
        [m]
      ), x(o), o;
    }
    function a(m) {
      var g = m.getSnapshot;
      m = m.value;
      try {
        var o = g();
        return !u(m, o);
      } catch {
        return !0;
      }
    }
    function r(m, g) {
      return g();
    }
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
    var s = ar, u = typeof Object.is == "function" ? Object.is : e, f = s.useState, l = s.useEffect, b = s.useLayoutEffect, x = s.useDebugValue, p = !1, c = !1, h = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : n;
    tt.useSyncExternalStore = s.useSyncExternalStore !== void 0 ? s.useSyncExternalStore : h, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
  }()), tt;
}
process.env.NODE_ENV === "production" ? ot.exports = vn() : ot.exports = yn();
var wn = ot.exports;
const Te = ["light", "dark", "system"];
function Nn() {
  const { theme: e, setTheme: n } = ea(), a = N(
    (f) => f.actions.setDashboardTheme
  );
  function r() {
    const f = Te.includes(e) ? e : "system", l = Te[(Te.indexOf(f) + 1) % Te.length];
    n(l), a(l);
  }
  const s = e === "light" ? bn : e === "dark" ? fn : hn, u = e === "light" ? "Theme: light (click for dark)" : e === "dark" ? "Theme: dark (click for system)" : "Theme: system (click for light)";
  return /* @__PURE__ */ t(
    _,
    {
      type: "button",
      variant: "ghost",
      size: "xs",
      className: "h-7 w-7 p-0 text-muted-foreground hover:text-foreground",
      onClick: r,
      "aria-label": u,
      title: u,
      children: /* @__PURE__ */ t(s, { className: "h-3.5 w-3.5", strokeWidth: 1.5 })
    }
  );
}
async function Sn(e, n, a, r, s) {
  if (!s)
    return null;
  const u = JSON.stringify(a), f = `${e}/v1/lens`;
  return await dt(f, s, {
    name: n,
    template: u,
    filterValues: r,
    operation: "create"
  });
}
async function it(e, n, a) {
  if (!a)
    return null;
  const { id: r, template: s, filterValues: u, isDefault: f, shared: l } = n, b = `${e}/v1/lens`;
  return await dt(b, a, {
    lensId: r,
    template: s,
    filterValues: u,
    isDefault: f,
    shared: l,
    operation: "update"
  });
}
async function Dn(e, n, a) {
  if (!a)
    return null;
  const r = `${e}/v1/lens`;
  return await dt(r, a, {
    operation: "delete",
    lensId: n
  });
}
const kn = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
function Cn({
  open: e,
  onOpenChange: n
} = {}) {
  const [a, r] = w(""), [s, u] = w(!1), f = N((D) => D.lenses), { setLenses: l, setSelectedLensId: b } = Vt(), [x, p] = w(!1), [c, h] = w(!1), m = e !== void 0, g = m ? e : c, o = (D) => {
    m || h(D), n == null || n(D);
  }, y = N((D) => D.dashboard), S = N((D) => D.filterValues), { authToken: k, tokenProps: L } = G();
  async function E() {
    p(!0);
    const D = await Sn(
      L.apiServiceUrl,
      a,
      y,
      S,
      k == null ? void 0 : k.accessToken
    );
    D && (l([...f || [], D]), b(D.id), o(!1)), p(!1);
  }
  return /* @__PURE__ */ i(Jt, { open: g, onOpenChange: o, children: [
    m ? null : /* @__PURE__ */ t(ta, { asChild: !0, children: /* @__PURE__ */ i(_, { variant: "secondary", size: "xs", children: [
      /* @__PURE__ */ t(re, { className: "h-3.5 w-3.5" }),
      "Lens"
    ] }) }),
    /* @__PURE__ */ i(Xt, { className: "rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control", children: [
      /* @__PURE__ */ i(ra, { children: [
        /* @__PURE__ */ t(at, { className: "text-[15px]", children: "Create lens" }),
        /* @__PURE__ */ t(nt, { className: "text-[13px] leading-5", children: "Lenses are private by default and are only visible to you." })
      ] }),
      /* @__PURE__ */ i("div", { className: "space-y-1.5 py-1", children: [
        /* @__PURE__ */ t(jr, { htmlFor: "lens-name", className: kn, children: "Name" }),
        /* @__PURE__ */ t(
          qr,
          {
            id: "lens-name",
            size: "xs",
            value: a,
            placeholder: "Monthly review, West region, …",
            onChange: (D) => r(D.target.value)
          }
        ),
        s && /* @__PURE__ */ t("p", { className: "text-[12px] text-destructive", children: "A lens with this name already exists. Pick a different one." })
      ] }),
      /* @__PURE__ */ i(aa, { children: [
        /* @__PURE__ */ t(_, { variant: "outline", size: "xs", onClick: () => o(!1), children: "Cancel" }),
        /* @__PURE__ */ t(
          _,
          {
            size: "xs",
            type: "submit",
            onClick: E,
            disabled: x || !a.trim(),
            children: x ? "Creating…" : "Create"
          }
        )
      ] })
    ] })
  ] });
}
function En({ includeLabel: e = !1 } = {}) {
  const n = N((p) => p.lenses), a = N((p) => p.selectedLensId), { setLenses: r, setSelectedLensId: s } = Vt(), { authToken: u, tokenProps: f } = G();
  async function l(p) {
    s(p);
  }
  async function b(p) {
    if (await Dn(f.apiServiceUrl, p, u == null ? void 0 : u.accessToken)) {
      const h = n == null ? void 0 : n.filter((m) => m.id !== p);
      r(h || []), s("original");
    }
  }
  async function x(p) {
    const c = n == null ? void 0 : n.map((g) => g.id === p.id ? {
      ...g,
      isDefault: !p.isDefault
    } : {
      ...g,
      isDefault: !1
    });
    r(c || []);
    const h = {
      ...p,
      isDefault: !p.isDefault
    };
    await it(f.apiServiceUrl, h, u == null ? void 0 : u.accessToken);
    const m = n == null ? void 0 : n.find((g) => g.isDefault);
    if (m && m.id !== p.id) {
      const g = {
        ...m,
        isDefault: !1
      };
      await it(f.apiServiceUrl, g, u == null ? void 0 : u.accessToken);
    }
  }
  return /* @__PURE__ */ i(R, { children: [
    e ? /* @__PURE__ */ i(R, { children: [
      /* @__PURE__ */ t(ue, { className: "px-3", children: "Lenses" }),
      /* @__PURE__ */ t(Fe, {})
    ] }) : null,
    /* @__PURE__ */ i(
      na,
      {
        value: a,
        onValueChange: l,
        children: [
          /* @__PURE__ */ t(Tt, { value: "original", children: "Original" }),
          n == null ? void 0 : n.map((p) => /* @__PURE__ */ i(
            Tt,
            {
              className: "group flex justify-between gap-2",
              value: p.id,
              children: [
                /* @__PURE__ */ t("p", { children: p.name }),
                /* @__PURE__ */ i("span", { className: "flex items-center gap-3", children: [
                  /* @__PURE__ */ t(
                    Yt,
                    {
                      onClick: (c) => {
                        c.preventDefault(), x(p);
                      },
                      className: te(
                        "size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
                        {
                          invisible: !p.isDefault,
                          "text-green-500": p.isDefault
                        }
                      ),
                      strokeWidth: 1.5
                    }
                  ),
                  /* @__PURE__ */ t(
                    Zt,
                    {
                      onClick: (c) => {
                        c.preventDefault(), b(p.id);
                      },
                      className: "invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",
                      strokeWidth: 1.5
                    }
                  )
                ] })
              ]
            },
            p.id
          ))
        ]
      }
    )
  ] });
}
function Ln() {
  const { displayPreferences: e, shouldShowElement: n } = sa(), { currentUser: a, userContext: r } = lt(), s = K(
    () => oa(a),
    [a]
  ), u = K(() => (l) => s && s[l] !== void 0 && s[l] === !1 ? !1 : n(l), [s, n, e]), f = K(
    () => {
      var l, b, x, p, c;
      return {
        canEdit: ((l = r == null ? void 0 : r.permissions) == null ? void 0 : l.canEdit) ?? ua(a),
        canUseFilters: ((b = r == null ? void 0 : r.permissions) == null ? void 0 : b.canEdit) ?? la(a),
        canManageDashboards: ((x = r == null ? void 0 : r.permissions) == null ? void 0 : x.canCreateDashboard) ?? ca(a),
        canCreateDashboards: ((p = r == null ? void 0 : r.permissions) == null ? void 0 : p.canCreateDashboard) ?? da(a),
        canAccessVisuals: ((c = r == null ? void 0 : r.permissions) == null ? void 0 : c.canEdit) ?? ia(a)
      };
    },
    [a, r]
  );
  return {
    displayPreferences: e,
    shouldShowElement: u,
    permissions: f,
    currentUser: a
  };
}
function In(e, n = []) {
  let a = [];
  function r(u, f) {
    const l = I.createContext(f);
    l.displayName = u + "Context";
    const b = a.length;
    a = [...a, f];
    const x = (c) => {
      var S;
      const { scope: h, children: m, ...g } = c, o = ((S = h == null ? void 0 : h[e]) == null ? void 0 : S[b]) || l, y = I.useMemo(() => g, Object.values(g));
      return /* @__PURE__ */ t(o.Provider, { value: y, children: m });
    };
    x.displayName = u + "Provider";
    function p(c, h) {
      var o;
      const m = ((o = h == null ? void 0 : h[e]) == null ? void 0 : o[b]) || l, g = I.useContext(m);
      if (g) return g;
      if (f !== void 0) return f;
      throw new Error(`\`${c}\` must be used within \`${u}\``);
    }
    return [x, p];
  }
  const s = () => {
    const u = a.map((f) => I.createContext(f));
    return function(l) {
      const b = (l == null ? void 0 : l[e]) || u;
      return I.useMemo(
        () => ({ [`__scope${e}`]: { ...l, [e]: b } }),
        [l, b]
      );
    };
  };
  return s.scopeName = e, [r, An(s, ...n)];
}
function An(...e) {
  const n = e[0];
  if (e.length === 1) return n;
  const a = () => {
    const r = e.map((s) => ({
      useScope: s(),
      scopeName: s.scopeName
    }));
    return function(u) {
      const f = r.reduce((l, { useScope: b, scopeName: x }) => {
        const c = b(u)[`__scope${x}`];
        return { ...l, ...c };
      }, {});
      return I.useMemo(() => ({ [`__scope${n.scopeName}`]: f }), [f]);
    };
  };
  return a.scopeName = n.scopeName, a;
}
var Mn = [
  "a",
  "button",
  "div",
  "form",
  "h2",
  "h3",
  "img",
  "input",
  "label",
  "li",
  "nav",
  "ol",
  "p",
  "select",
  "span",
  "svg",
  "ul"
], mt = Mn.reduce((e, n) => {
  const a = Hr(`Primitive.${n}`), r = I.forwardRef((s, u) => {
    const { asChild: f, ...l } = s, b = f ? a : n;
    return typeof window < "u" && (window[Symbol.for("radix-ui")] = !0), /* @__PURE__ */ t(b, { ...l, ref: u });
  });
  return r.displayName = `Primitive.${n}`, { ...e, [n]: r };
}, {});
function Pn() {
  return wn.useSyncExternalStore(
    On,
    () => !0,
    () => !1
  );
}
function On() {
  return () => {
  };
}
var pt = "Avatar", [_n] = In(pt), [Rn, or] = _n(pt), ir = I.forwardRef(
  (e, n) => {
    const { __scopeAvatar: a, ...r } = e, [s, u] = I.useState("idle");
    return /* @__PURE__ */ t(
      Rn,
      {
        scope: a,
        imageLoadingStatus: s,
        onImageLoadingStatusChange: u,
        children: /* @__PURE__ */ t(mt.span, { ...r, ref: n })
      }
    );
  }
);
ir.displayName = pt;
var dr = "AvatarImage", cr = I.forwardRef(
  (e, n) => {
    const { __scopeAvatar: a, src: r, onLoadingStatusChange: s = () => {
    }, ...u } = e, f = or(dr, a), l = Un(r, u), b = Vr((x) => {
      s(x), f.onImageLoadingStatusChange(x);
    });
    return rt(() => {
      l !== "idle" && b(l);
    }, [l, b]), l === "loaded" ? /* @__PURE__ */ t(mt.img, { ...u, ref: n, src: r }) : null;
  }
);
cr.displayName = dr;
var lr = "AvatarFallback", ur = I.forwardRef(
  (e, n) => {
    const { __scopeAvatar: a, delayMs: r, ...s } = e, u = or(lr, a), [f, l] = I.useState(r === void 0);
    return I.useEffect(() => {
      if (r !== void 0) {
        const b = window.setTimeout(() => l(!0), r);
        return () => window.clearTimeout(b);
      }
    }, [r]), f && u.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ t(mt.span, { ...s, ref: n }) : null;
  }
);
ur.displayName = lr;
function jt(e, n) {
  return e ? n ? (e.src !== n && (e.src = n), e.complete && e.naturalWidth > 0 ? "loaded" : "loading") : "error" : "idle";
}
function Un(e, { referrerPolicy: n, crossOrigin: a }) {
  const r = Pn(), s = I.useRef(null), u = r ? (s.current || (s.current = new window.Image()), s.current) : null, [f, l] = I.useState(
    () => jt(u, e)
  );
  return rt(() => {
    l(jt(u, e));
  }, [u, e]), rt(() => {
    const b = (c) => () => {
      l(c);
    };
    if (!u) return;
    const x = b("loaded"), p = b("error");
    return u.addEventListener("load", x), u.addEventListener("error", p), n && (u.referrerPolicy = n), typeof a == "string" && (u.crossOrigin = a), () => {
      u.removeEventListener("load", x), u.removeEventListener("error", p);
    };
  }, [u, a, n]), f;
}
var mr = ir, pr = cr, hr = ur;
const fr = I.forwardRef(({ className: e, ...n }, a) => /* @__PURE__ */ t(
  mr,
  {
    ref: a,
    className: te(
      "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
      e
    ),
    ...n
  }
));
fr.displayName = mr.displayName;
const Tn = I.forwardRef(({ className: e, ...n }, a) => /* @__PURE__ */ t(
  pr,
  {
    ref: a,
    className: te("aspect-square h-full w-full", e),
    ...n
  }
));
Tn.displayName = pr.displayName;
const gr = I.forwardRef(({ className: e, ...n }, a) => /* @__PURE__ */ t(
  hr,
  {
    ref: a,
    className: te(
      "flex h-full w-full items-center justify-center rounded-full bg-muted",
      e
    ),
    ...n
  }
));
gr.displayName = hr.displayName;
const Fn = async (e, n, a) => {
  const r = `${e}/management/v1/groups`;
  return await Kt(r, n, a);
}, $n = async (e, n, a, r) => {
  const s = `${e}/management/v1/groups/${a}`;
  return ct(s, n, "PATCH", r);
}, Gn = async (e, n, a) => {
  const r = `${e}/management/v1/groups/${a}`;
  await ct(r, n, "DELETE");
}, Bn = async (e, n, a, r) => {
  const s = `${e}/management/v1/groups/${a}/members`;
  return await Kt(s, n, r);
}, zn = async (e, n, a, r) => {
  const s = `${e}/management/v1/groups/${a}/members`;
  await ct(s, n, "DELETE", r);
};
function jn() {
  const { authToken: e, tokenProps: n } = G(), a = pe();
  return he({
    mutationFn: (r) => Fn(n.apiServiceUrl, (e == null ? void 0 : e.accessToken) || "", r),
    onSuccess: () => {
      a.invalidateQueries({ queryKey: ["groups"] }), C.success("Group created successfully");
    },
    onError: (r) => {
      console.error("Failed to create group:", r), C.error("Failed to create group", {
        description: me(r, "Failed to create group")
      });
    }
  });
}
function qn() {
  const { authToken: e, tokenProps: n } = G(), a = pe();
  return he({
    mutationFn: ({
      groupId: r,
      data: s
    }) => $n(n.apiServiceUrl, (e == null ? void 0 : e.accessToken) || "", r, s),
    onSuccess: (r, s) => {
      a.invalidateQueries({ queryKey: ["group", s.groupId] }), a.invalidateQueries({ queryKey: ["groups"] }), C.success("Group updated successfully");
    },
    onError: (r) => {
      console.error("Failed to update group:", r), C.error("Failed to update group", {
        description: me(r, "Failed to update group")
      });
    }
  });
}
function Hn() {
  const { authToken: e, tokenProps: n } = G(), a = pe();
  return he({
    mutationFn: (r) => Gn(n.apiServiceUrl, (e == null ? void 0 : e.accessToken) || "", r),
    onSuccess: (r, s) => {
      a.invalidateQueries({ queryKey: ["groups"] }), a.removeQueries({ queryKey: ["group", s] }), C.success("Group deleted successfully");
    },
    onError: (r) => {
      console.error("Failed to delete group:", r), C.error("Failed to delete group", {
        description: me(r, "Failed to delete group")
      });
    }
  });
}
function Vn() {
  const { authToken: e, tokenProps: n } = G(), a = pe();
  return he({
    mutationFn: ({
      groupId: r,
      data: s
    }) => Bn(n.apiServiceUrl, (e == null ? void 0 : e.accessToken) || "", r, s),
    onSuccess: (r, s) => {
      a.invalidateQueries({ queryKey: ["group", s.groupId] }), a.invalidateQueries({
        queryKey: ["group-members", s.groupId]
      }), a.invalidateQueries({ queryKey: ["groups"] }), C.success("Members added successfully");
    },
    onError: (r) => {
      console.error("Failed to add group members:", r), C.error("Failed to add members", {
        description: me(r, "Failed to add members")
      });
    }
  });
}
function Kn() {
  const { authToken: e, tokenProps: n } = G(), a = pe();
  return he({
    mutationFn: ({
      groupId: r,
      data: s
    }) => zn(n.apiServiceUrl, (e == null ? void 0 : e.accessToken) || "", r, s),
    onSuccess: (r, s) => {
      a.invalidateQueries({ queryKey: ["group", s.groupId] }), a.invalidateQueries({
        queryKey: ["group-members", s.groupId]
      }), a.invalidateQueries({ queryKey: ["groups"] }), C.success("Members removed successfully");
    },
    onError: (r) => {
      console.error("Failed to remove group members:", r), C.error("Failed to remove members", {
        description: me(r, "Failed to remove members")
      });
    }
  });
}
const Qn = [];
function Wn({
  open: e,
  onOpenChange: n
}) {
  var k, L, E;
  const { tokenProps: a } = G(), { currentUser: r } = lt(), s = (r == null ? void 0 : r.type) === "tenant", u = a == null ? void 0 : a.tenantId, {
    groups: f,
    isLoading: l,
    error: b,
    refetch: x
  } = ma({
    type: s ? "TENANT_GROUP" : "all",
    tenantId: s ? u : void 0,
    includeMembers: !1
  }), p = b ? br(b, "Unable to load groups.") : null, [c, h] = w({ kind: "list" }), [m, g] = w(null), o = Hn();
  Ge(() => {
    e || (h({ kind: "list" }), g(null));
  }, [e]);
  const y = c.kind === "members" && f.find((D) => D.id === c.groupId) || null, S = async () => {
    if (m)
      try {
        await o.mutateAsync(m.id), g(null), h({ kind: "list" }), x();
      } catch {
      }
  };
  return /* @__PURE__ */ t(Jt, { open: e, onOpenChange: n, children: /* @__PURE__ */ i(Xt, { className: "flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0", children: [
    c.kind === "list" ? /* @__PURE__ */ i("div", { className: "shrink-0 border-b border-border px-5 pt-4 pb-3.5", children: [
      /* @__PURE__ */ t(at, { className: "text-[15px] font-semibold tracking-tight", children: "Group management" }),
      /* @__PURE__ */ t(nt, { className: "mt-1 text-[12px] leading-[1.5] text-muted-foreground", children: "Organize people into groups for shared access." })
    ] }) : c.kind === "create" ? /* @__PURE__ */ i("div", { className: "flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5", children: [
      /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          onClick: () => h({ kind: "list" }),
          "aria-label": "Back",
          className: "-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",
          children: /* @__PURE__ */ t(er, { className: "h-3.5 w-3.5" })
        }
      ),
      /* @__PURE__ */ t(at, { className: "truncate text-[13px] font-medium", children: "New group" }),
      /* @__PURE__ */ t(nt, { className: "sr-only", children: "Create a new group to organize members." })
    ] }) : null,
    c.kind === "list" && /* @__PURE__ */ t(
      Jn,
      {
        groups: f,
        isLoading: l,
        errorMessage: p,
        onRetry: () => x(),
        currentUserId: r == null ? void 0 : r.id,
        onOpenGroup: (D) => h({ kind: "members", groupId: D }),
        onCreate: () => h({ kind: "create" }),
        onDeleteRequest: (D) => g(D)
      }
    ),
    c.kind === "members" && y && /* @__PURE__ */ t(
      Zn,
      {
        group: y,
        isTenantViewer: s,
        canEdit: ((k = y.permissions) == null ? void 0 : k.canEdit) ?? y.createdBy === (r == null ? void 0 : r.id),
        canDelete: ((L = y.permissions) == null ? void 0 : L.canDelete) ?? y.createdBy === (r == null ? void 0 : r.id),
        canManageMembers: ((E = y.permissions) == null ? void 0 : E.canManageMembers) ?? y.createdBy === (r == null ? void 0 : r.id),
        onBack: () => h({ kind: "list" }),
        onMembersChanged: x,
        onUpdated: x,
        onRequestDelete: () => g(y)
      },
      y.id
    ),
    c.kind === "create" && /* @__PURE__ */ t(
      es,
      {
        isTenantUser: s,
        tenantId: u,
        onCancel: () => h({ kind: "list" }),
        onCreated: (D) => {
          x(), h({ kind: "members", groupId: D });
        }
      }
    ),
    m && /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5", children: [
      /* @__PURE__ */ i("div", { className: "min-w-0 text-[12px] text-foreground", children: [
        "Delete ",
        /* @__PURE__ */ t("span", { className: "font-medium", children: m.name }),
        "?",
        /* @__PURE__ */ t("span", { className: "ml-2 text-muted-foreground", children: "Members lose any access granted via this group." })
      ] }),
      /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center gap-1.5", children: [
        /* @__PURE__ */ t(
          "button",
          {
            type: "button",
            onClick: () => g(null),
            disabled: o.isPending,
            className: "h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",
            children: "Cancel"
          }
        ),
        /* @__PURE__ */ i(
          "button",
          {
            type: "button",
            onClick: S,
            disabled: o.isPending,
            className: "inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",
            children: [
              o.isPending ? /* @__PURE__ */ t($e, { className: "h-3 w-3 animate-spin" }) : /* @__PURE__ */ t(ut, { className: "h-3 w-3" }),
              "Delete group"
            ]
          }
        )
      ] })
    ] })
  ] }) });
}
function Jn({
  groups: e,
  isLoading: n,
  errorMessage: a,
  onRetry: r,
  currentUserId: s,
  onOpenGroup: u,
  onCreate: f,
  onDeleteRequest: l
}) {
  const [b, x] = w(""), p = K(
    () => e.filter(
      (c) => !b.trim() || c.name.toLowerCase().includes(b.toLowerCase()) || (c.description || "").toLowerCase().includes(b.toLowerCase())
    ),
    [e, b]
  );
  return /* @__PURE__ */ i("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
    /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5", children: [
      /* @__PURE__ */ i("div", { className: "flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40", children: [
        /* @__PURE__ */ t(pa, { className: "h-3 w-3 text-muted-foreground" }),
        /* @__PURE__ */ t(
          "input",
          {
            value: b,
            onChange: (c) => x(c.target.value),
            placeholder: "Search groups…",
            className: "h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"
          }
        ),
        b && /* @__PURE__ */ t(
          "button",
          {
            type: "button",
            onClick: () => x(""),
            className: "flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",
            children: /* @__PURE__ */ t(Qt, { className: "h-2.5 w-2.5" })
          }
        )
      ] }),
      /* @__PURE__ */ i(
        "button",
        {
          type: "button",
          onClick: f,
          className: "inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",
          children: [
            /* @__PURE__ */ t(re, { className: "h-3 w-3" }),
            "New group"
          ]
        }
      )
    ] }),
    /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto", children: n ? /* @__PURE__ */ t("div", { className: "space-y-px p-3", children: [1, 2, 3].map((c) => /* @__PURE__ */ t(
      "div",
      {
        className: "h-12 animate-pulse rounded-[4px] bg-muted/60"
      },
      c
    )) }) : a ? /* @__PURE__ */ t(
      xr,
      {
        title: "Can't load groups",
        message: a,
        onRetry: r
      }
    ) : p.length === 0 && e.length === 0 ? /* @__PURE__ */ t(Yn, { onCreate: f }) : p.length === 0 ? /* @__PURE__ */ i("div", { className: "flex h-full flex-col items-center justify-center gap-1 py-10 text-center", children: [
      /* @__PURE__ */ i("div", { className: "text-[12px] text-foreground", children: [
        'No groups match "',
        b,
        '"'
      ] }),
      /* @__PURE__ */ t("div", { className: "text-[11px] text-muted-foreground", children: "Try a different search." })
    ] }) : p.map((c) => {
      var h;
      return /* @__PURE__ */ t(
        Xn,
        {
          group: c,
          canDelete: ((h = c.permissions) == null ? void 0 : h.canDelete) ?? c.createdBy === s,
          onClick: () => u(c.id),
          onDelete: () => l(c)
        },
        c.id
      );
    }) })
  ] });
}
function Xn({
  group: e,
  canDelete: n,
  onClick: a,
  onDelete: r
}) {
  let s = "";
  try {
    s = nr(new Date(e.createdAt), "MMM d, yyyy");
  } catch {
    s = "";
  }
  return /* @__PURE__ */ i(
    "button",
    {
      type: "button",
      onClick: a,
      className: "group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",
      children: [
        /* @__PURE__ */ t("div", { className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground", children: /* @__PURE__ */ t(Xa, { className: "h-3.5 w-3.5" }) }),
        /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
          /* @__PURE__ */ t("div", { className: "truncate text-[13px] font-medium text-foreground", children: e.name }),
          /* @__PURE__ */ i("div", { className: "mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground", children: [
            /* @__PURE__ */ i("span", { className: "inline-flex items-center gap-1", children: [
              /* @__PURE__ */ t(sr, { className: "h-2.5 w-2.5" }),
              e.memberCount,
              " member",
              e.memberCount === 1 ? "" : "s"
            ] }),
            s && /* @__PURE__ */ i(R, { children: [
              /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
              /* @__PURE__ */ i("span", { className: "inline-flex items-center gap-1", children: [
                /* @__PURE__ */ t(rr, { className: "h-2.5 w-2.5" }),
                s
              ] })
            ] }),
            e.description && /* @__PURE__ */ i(R, { children: [
              /* @__PURE__ */ t("span", { className: "text-border", children: "·" }),
              /* @__PURE__ */ t("span", { className: "truncate text-muted-foreground", children: e.description })
            ] })
          ] })
        ] }),
        /* @__PURE__ */ i("div", { className: "flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100", children: [
          n && /* @__PURE__ */ t(
            "span",
            {
              role: "button",
              tabIndex: 0,
              onClick: (u) => {
                u.stopPropagation(), r();
              },
              onKeyDown: (u) => {
                (u.key === "Enter" || u.key === " ") && (u.preventDefault(), u.stopPropagation(), r());
              },
              "aria-label": `Delete ${e.name}`,
              className: "flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",
              children: /* @__PURE__ */ t(ut, { className: "h-3 w-3" })
            }
          ),
          /* @__PURE__ */ t(ga, { className: "h-3.5 w-3.5 text-muted-foreground" })
        ] })
      ]
    }
  );
}
function Yn({ onCreate: e }) {
  return /* @__PURE__ */ i("div", { className: "flex h-full flex-col items-center justify-center gap-2 py-12 text-center", children: [
    /* @__PURE__ */ t("div", { className: "flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground", children: /* @__PURE__ */ t(tr, { className: "h-4 w-4" }) }),
    /* @__PURE__ */ t("div", { className: "text-[13px] font-medium text-foreground", children: "No groups yet" }),
    /* @__PURE__ */ t("div", { className: "max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground", children: "Groups let you grant shared access to dashboards. Create one and add members." }),
    /* @__PURE__ */ i(
      "button",
      {
        type: "button",
        onClick: e,
        className: "mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",
        children: [
          /* @__PURE__ */ t(re, { className: "h-3 w-3" }),
          "New group"
        ]
      }
    )
  ] });
}
function Zn({
  group: e,
  isTenantViewer: n,
  canEdit: a,
  canDelete: r,
  canManageMembers: s,
  onBack: u,
  onMembersChanged: f,
  onUpdated: l,
  onRequestDelete: b
}) {
  const {
    data: x,
    isLoading: p,
    error: c,
    refetch: h
  } = ha(e.id), m = (x == null ? void 0 : x.members) ?? Qn, g = c ? br(c, "Unable to load members for this group.") : null, o = e.type === "TENANT_GROUP" ? "tenant" : "organization", { users: y } = fa({
    type: o,
    tenantId: e.tenantId || void 0,
    active: !0,
    limit: 200
  }), S = K(
    () => new Set(m.map((v) => v.userId)),
    [m]
  ), k = Vn(), L = Kn(), E = qn(), [D, ae] = w(!1), [Q, ne] = w(e.name), [fe, W] = w(!1), [J, X] = w(e.description || ""), [Y, ge] = w(""), [be, xe] = w(!1), ve = K(() => {
    const v = Y.trim().toLowerCase();
    return y.filter((U) => !S.has(U.id)).filter(
      (U) => !v || (U.name || "").toLowerCase().includes(v) || (U.email || "").toLowerCase().includes(v)
    ).slice(0, 50);
  }, [y, S, Y]), ye = async () => {
    const v = Q.trim();
    if (ae(!1), v.length >= 3 && v !== e.name)
      try {
        await E.mutateAsync({
          groupId: e.id,
          data: { name: v }
        }), l();
      } catch {
      }
  }, z = async () => {
    const v = J.trim();
    if (W(!1), v !== (e.description || ""))
      try {
        await E.mutateAsync({
          groupId: e.id,
          data: { description: v }
        }), l();
      } catch {
      }
  }, Z = async (v) => {
    if (s) {
      ge(""), xe(!1);
      try {
        await k.mutateAsync({
          groupId: e.id,
          data: {
            userIds: [v.id],
            userType: o === "tenant" ? "tenant" : "org"
          }
        }), h(), f();
      } catch {
      }
    }
  }, ee = async (v) => {
    if (s)
      try {
        await L.mutateAsync({
          groupId: e.id,
          data: { userIds: [v] }
        }), h(), f();
      } catch {
      }
  };
  let j = "";
  try {
    j = nr(new Date(e.createdAt), "MMM d, yyyy");
  } catch {
    j = "";
  }
  return /* @__PURE__ */ i("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
    /* @__PURE__ */ i("div", { className: "flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5", children: [
      /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          onClick: u,
          "aria-label": "Back",
          className: "-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",
          children: /* @__PURE__ */ t(er, { className: "h-3.5 w-3.5" })
        }
      ),
      D ? /* @__PURE__ */ t(
        "input",
        {
          autoFocus: !0,
          value: Q,
          onChange: (v) => ne(v.target.value),
          onBlur: ye,
          onKeyDown: (v) => {
            v.key === "Enter" && ye(), v.key === "Escape" && (ne(e.name), ae(!1));
          },
          className: "h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"
        }
      ) : /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          onClick: () => {
            a && (ne(e.name), ae(!0));
          },
          title: a ? "Click to rename" : e.name,
          disabled: !a,
          className: "truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",
          children: e.name
        }
      ),
      /* @__PURE__ */ i("span", { className: "ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground", children: [
        /* @__PURE__ */ t(sr, { className: "h-2.5 w-2.5" }),
        m.length,
        " member",
        m.length === 1 ? "" : "s"
      ] })
    ] }),
    /* @__PURE__ */ t("div", { className: "shrink-0 border-b border-border px-5 py-2.5", children: fe ? /* @__PURE__ */ i("div", { children: [
      /* @__PURE__ */ t(
        "textarea",
        {
          autoFocus: !0,
          rows: 2,
          value: J,
          onChange: (v) => X(v.target.value),
          maxLength: 200,
          onKeyDown: (v) => {
            v.key === "Escape" && (X(e.description || ""), W(!1)), v.key === "Enter" && (v.metaKey || v.ctrlKey) && z();
          },
          placeholder: "What is this group for?",
          className: "block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"
        }
      ),
      /* @__PURE__ */ i("div", { className: "mt-1.5 flex items-center justify-between", children: [
        /* @__PURE__ */ i("span", { className: "text-[10.5px] text-muted-foreground", children: [
          J.length,
          "/200 · Esc to cancel · ⌘↩ to save"
        ] }),
        /* @__PURE__ */ i("div", { className: "flex items-center gap-1.5", children: [
          /* @__PURE__ */ t(
            "button",
            {
              type: "button",
              onClick: () => {
                X(e.description || ""), W(!1);
              },
              className: "h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",
              children: "Cancel"
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              type: "button",
              onClick: z,
              className: "inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",
              children: "Save"
            }
          )
        ] })
      ] })
    ] }) : /* @__PURE__ */ i(
      "button",
      {
        type: "button",
        onClick: () => {
          a && (X(e.description || ""), W(!0));
        },
        disabled: !a,
        title: a ? "Click to edit description" : void 0,
        className: "block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",
        children: [
          e.description ? /* @__PURE__ */ t("p", { className: "text-[12px] leading-[1.55] text-foreground/90", children: e.description }) : /* @__PURE__ */ t("p", { className: "text-[12px] leading-[1.55] text-muted-foreground", children: a ? "Add a description…" : "No description" }),
          /* @__PURE__ */ i("p", { className: "mt-1 text-[10.5px] text-muted-foreground", children: [
            j ? `Created ${j}` : "Recently created",
            a ? " · You can edit this group" : ""
          ] })
        ]
      }
    ) }),
    s && /* @__PURE__ */ t(
      ts,
      {
        query: Y,
        setQuery: ge,
        open: be,
        setOpen: xe,
        candidates: ve,
        showKindChip: !n,
        onAdd: Z,
        busy: k.isPending
      }
    ),
    /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto", children: p ? /* @__PURE__ */ t("div", { className: "space-y-px p-3", children: [1, 2, 3].map((v) => /* @__PURE__ */ t(
      "div",
      {
        className: "h-10 animate-pulse rounded-[4px] bg-muted/60"
      },
      v
    )) }) : g ? /* @__PURE__ */ t(
      xr,
      {
        title: "Can't load members",
        message: g,
        onRetry: () => h()
      }
    ) : m.length === 0 ? /* @__PURE__ */ i("div", { className: "flex h-full flex-col items-center justify-center gap-1 py-10 text-center", children: [
      /* @__PURE__ */ t("div", { className: "text-[12px] text-foreground", children: "No members yet" }),
      /* @__PURE__ */ t("div", { className: "text-[11px] text-muted-foreground", children: s ? "Search above to add people to this group." : "This group does not have any members." })
    ] }) : m.map((v) => {
      var U, q, we, Ne, Se, A;
      return /* @__PURE__ */ i(
        "div",
        {
          className: "group flex items-center gap-2 border-b border-border/60 px-5 py-2",
          children: [
            /* @__PURE__ */ t(vr, { name: ((U = v.user) == null ? void 0 : U.name) || ((q = v.user) == null ? void 0 : q.email) || "?" }),
            /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
              /* @__PURE__ */ t("div", { className: "truncate text-[12.5px] font-medium text-foreground", children: ((we = v.user) == null ? void 0 : we.name) || ((Ne = v.user) == null ? void 0 : Ne.email) || "Unknown" }),
              ((Se = v.user) == null ? void 0 : Se.email) && v.user.name && /* @__PURE__ */ t("div", { className: "truncate text-[10.5px] text-muted-foreground", children: v.user.email })
            ] }),
            !n && /* @__PURE__ */ t("span", { className: "text-[10px] uppercase tracking-[0.06em] text-muted-foreground", children: v.userType }),
            /* @__PURE__ */ t(
              "button",
              {
                type: "button",
                onClick: () => ee(v.userId),
                disabled: !s || L.isPending,
                "aria-label": `Remove ${((A = v.user) == null ? void 0 : A.name) || "member"}`,
                className: "flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",
                children: /* @__PURE__ */ t(Qt, { className: "h-3 w-3" })
              }
            )
          ]
        },
        v.id
      );
    }) }),
    r && /* @__PURE__ */ t("div", { className: "flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5", children: /* @__PURE__ */ i(
      "button",
      {
        type: "button",
        onClick: b,
        className: "inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",
        children: [
          /* @__PURE__ */ t(ut, { className: "h-3 w-3" }),
          "Delete group"
        ]
      }
    ) })
  ] });
}
function es({
  isTenantUser: e,
  tenantId: n,
  onCancel: a,
  onCreated: r
}) {
  const [s, u] = w(""), [f, l] = w(""), [b, x] = w(null), p = jn(), c = s.trim().length >= 3 && s.trim().length <= 50, h = async () => {
    if (!c) return;
    x(null);
    const m = {
      name: s.trim(),
      description: f.trim() || void 0,
      type: e ? "TENANT_GROUP" : "ORG_GROUP",
      ...e && n ? { tenantId: n } : {}
    };
    try {
      const g = await p.mutateAsync(m), o = g == null ? void 0 : g.id;
      o ? r(o) : a();
    } catch (g) {
      x(g instanceof Error ? g.message : "Failed to create group");
    }
  };
  return /* @__PURE__ */ i("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
    /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto px-5 py-4", children: [
      /* @__PURE__ */ t(qt, { children: "Name" }),
      /* @__PURE__ */ t(
        "input",
        {
          autoFocus: !0,
          value: s,
          onChange: (m) => u(m.target.value),
          placeholder: "Marketing leads, North America sales, …",
          maxLength: 50,
          className: "mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"
        }
      ),
      /* @__PURE__ */ t("div", { className: "mt-1 text-[10.5px] text-muted-foreground", children: "3–50 characters." }),
      /* @__PURE__ */ i("div", { className: "mt-4", children: [
        /* @__PURE__ */ t(qt, { children: "Description (optional)" }),
        /* @__PURE__ */ t(
          "textarea",
          {
            rows: 2,
            value: f,
            onChange: (m) => l(m.target.value),
            maxLength: 200,
            placeholder: "What is this group for?",
            className: "mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"
          }
        ),
        /* @__PURE__ */ i("div", { className: "mt-1 flex justify-end text-[10.5px] text-muted-foreground", children: [
          f.length,
          "/200"
        ] })
      ] }),
      b && /* @__PURE__ */ t("div", { className: "mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300", children: b })
    ] }),
    /* @__PURE__ */ i("div", { className: "flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5", children: [
      /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          onClick: a,
          disabled: p.isPending,
          className: "h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",
          children: "Cancel"
        }
      ),
      /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          onClick: h,
          disabled: !c || p.isPending,
          className: "inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",
          children: p.isPending ? /* @__PURE__ */ i(R, { children: [
            /* @__PURE__ */ t($e, { className: "h-3 w-3 animate-spin" }),
            "Creating…"
          ] }) : /* @__PURE__ */ i(R, { children: [
            /* @__PURE__ */ t(re, { className: "h-3 w-3" }),
            "Create group"
          ] })
        }
      )
    ] })
  ] });
}
function ts({
  query: e,
  setQuery: n,
  open: a,
  setOpen: r,
  candidates: s,
  showKindChip: u,
  onAdd: f,
  busy: l
}) {
  const b = Gt(null), x = Gt(null), [p, c] = w(null);
  Qa(() => {
    if (!a) {
      c(null);
      return;
    }
    const m = () => {
      const g = b.current;
      if (!g) return;
      const o = g.getBoundingClientRect(), y = 240, k = window.innerHeight - o.bottom < y + 16 && o.top > y;
      c({
        left: o.left,
        top: k ? o.top - 6 : o.bottom + 6,
        width: o.width,
        above: k
      });
    };
    return m(), window.addEventListener("resize", m), window.addEventListener("scroll", m, !0), () => {
      window.removeEventListener("resize", m), window.removeEventListener("scroll", m, !0);
    };
  }, [a, s.length]), Ge(() => {
    if (!a) return;
    const m = (g) => {
      var y, S;
      const o = g.target;
      (y = b.current) != null && y.contains(o) || (S = x.current) != null && S.contains(o) || r(!1);
    };
    return document.addEventListener("mousedown", m), () => document.removeEventListener("mousedown", m);
  }, [a, r]);
  const h = a && s.length > 0 && p;
  return /* @__PURE__ */ i("div", { className: "shrink-0 border-b border-border px-5 py-2.5", children: [
    /* @__PURE__ */ i(
      "div",
      {
        ref: b,
        className: "flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",
        children: [
          /* @__PURE__ */ t(xn, { className: "h-3 w-3 text-muted-foreground" }),
          /* @__PURE__ */ t(
            "input",
            {
              value: e,
              onChange: (m) => {
                n(m.target.value), r(!0);
              },
              onFocus: () => r(!0),
              placeholder: "Add a member by name or email…",
              disabled: l,
              className: "h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"
            }
          )
        ]
      }
    ),
    h && typeof document < "u" && Ja(
      /* @__PURE__ */ t(
        "div",
        {
          ref: x,
          style: {
            position: "fixed",
            left: p.left,
            top: p.top,
            width: p.width,
            transform: p.above ? "translateY(-100%)" : void 0
          },
          className: "z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",
          children: s.map((m) => /* @__PURE__ */ i(
            "button",
            {
              type: "button",
              onClick: () => f(m),
              className: "flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",
              children: [
                /* @__PURE__ */ t(vr, { name: m.name || m.email || "?" }),
                /* @__PURE__ */ i("div", { className: "min-w-0 flex-1", children: [
                  /* @__PURE__ */ t("div", { className: "truncate text-[12px] font-medium text-foreground", children: m.name || m.email || "Unknown" }),
                  m.email && m.name && /* @__PURE__ */ t("div", { className: "truncate text-[10.5px] text-muted-foreground", children: m.email })
                ] }),
                u && m.type && /* @__PURE__ */ t("span", { className: "text-[10px] uppercase tracking-[0.06em] text-muted-foreground", children: m.type === "tenant" ? "tenant" : "org" })
              ]
            },
            m.id
          ))
        }
      ),
      document.body
    )
  ] });
}
function br(e, n) {
  if (!e) return n;
  if (e instanceof Error) {
    const a = e.message || "", r = a.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);
    return r ? r[1] : a || n;
  }
  return typeof e == "string" ? e : n;
}
function xr({
  title: e,
  message: n,
  onRetry: a
}) {
  return /* @__PURE__ */ i("div", { className: "flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center", children: [
    /* @__PURE__ */ t("div", { className: "text-[12.5px] font-medium text-foreground", children: e }),
    /* @__PURE__ */ t("div", { className: "max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground", children: n }),
    a && /* @__PURE__ */ t(
      "button",
      {
        type: "button",
        onClick: a,
        className: "mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",
        children: "Try again"
      }
    )
  ] });
}
function qt({ children: e }) {
  return /* @__PURE__ */ t("label", { className: "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground", children: e });
}
function vr({ name: e }) {
  const n = e.split(" ").map((a) => a[0]).filter(Boolean).slice(0, 2).join("").toUpperCase();
  return /* @__PURE__ */ t(fr, { className: "h-6 w-6 shrink-0", children: /* @__PURE__ */ t(gr, { className: "text-[9px] font-semibold", children: n || "?" }) });
}
function ce(e, n, a) {
  var u, f;
  const r = (e.controls || []).find(
    (l) => l.id === a
  );
  if (r)
    return r.label;
  const s = (f = (u = Wt(e, n)) == null ? void 0 : u.controls) == null ? void 0 : f.find(
    (l) => l.id === a
  );
  return (s == null ? void 0 : s.label) || a;
}
function le(e, n) {
  var a;
  return ((a = Wt(e, n)) == null ? void 0 : a.title) || n;
}
function rs(e) {
  const { errors: n, dashboard: a } = e;
  if (!a)
    return n;
  const r = /* @__PURE__ */ new Map();
  for (const s of n) {
    const u = s.match(
      /^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/
    );
    if (u) {
      const [, p, c] = u, h = `${p}:${c}:missing-metric`;
      r.has(h) || r.set(
        h,
        `"${le(a, p)}" has an outdated "${ce(
          a,
          p,
          c
        )}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`
      );
      continue;
    }
    const f = s.match(
      /^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/
    );
    if (f) {
      const [, p, c] = f, h = `${p}:${c}:missing-group-by`;
      r.has(h) || r.set(
        h,
        `"${le(a, p)}" has an outdated "${ce(
          a,
          p,
          c
        )}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`
      );
      continue;
    }
    const l = s.match(
      /^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/
    );
    if (l) {
      const [, p, c] = l, h = `${p}:${c}:invalid-metric`;
      r.has(h) || r.set(
        h,
        `"${le(a, p)}" has an invalid "${ce(
          a,
          p,
          c
        )}" metric mapping. Open the card controls and choose a valid metric for each option.`
      );
      continue;
    }
    const b = s.match(
      /^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/
    );
    if (b) {
      const [, p, c] = b, h = `${p}:${c}:invalid-group-by`;
      r.has(h) || r.set(
        h,
        `"${le(a, p)}" has an invalid "${ce(
          a,
          p,
          c
        )}" field mapping. Open the card controls and choose a valid field for each option.`
      );
      continue;
    }
    const x = s.match(
      /^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/
    );
    if (x) {
      const [, p, c] = x, h = `${p}:${c}:missing-temporal-group-by`;
      r.has(h) || r.set(
        h,
        `"${le(a, p)}" can no longer use "${ce(
          a,
          p,
          c
        )}" for time grain because the card does not currently group by a date field.`
      );
      continue;
    }
    r.set(s, s);
  }
  return Array.from(r.values());
}
function as(e, n) {
  return typeof e == "boolean" ? e : typeof n == "boolean" ? n : !0;
}
function Ht(e, n) {
  return {
    dashboard: st(e),
    semanticExecutionPayload: st(n)
  };
}
function ys() {
  var Et, Lt, It, At, Mt, Pt, Ot;
  Ya(), Za();
  const {
    authToken: e,
    tokenProps: n,
    id: a,
    showBriefings: r
  } = G(), { isLocalDev: s } = ba(), { openBrandStudioPreview: u } = xa(), { permissions: f } = Ln(), l = va(), { isLoading: b } = ya(), x = N((d) => d.theme), p = N((d) => d.isDownloadingPdf), c = N(
    (d) => d.dashboardAssistantDraftScopeKey
  ), h = N((d) => d.lenses), m = N((d) => d.selectedLensId), g = h == null ? void 0 : h.find((d) => d.id === m), o = N((d) => d.dashboard), y = N((d) => d.selectedSheetId), S = (Et = o == null ? void 0 : o.sheets) == null ? void 0 : Et.find(
    (d) => d.id === y
  ), k = Kr(S), L = k ? (Lt = S == null ? void 0 : S.document) == null ? void 0 : Lt.page : void 0, E = N(
    (d) => d.isDashboardEditing
  ), { setDashboardTitle: D } = N((d) => d.actions), [ae, Q] = w(!1), [ne, fe] = w(!1), [W, J] = w(!1), [X, Y] = w(!1), [ge, be] = w(!1), [xe, ve] = w(!1), [ye, z] = w(!1), [Z, ee] = w(null), [j, v] = w([]), [U, q] = w(!1), we = N((d) => d.isDashboardPanelOpen), Ne = N(
    (d) => d.actions.setIsDashboardPanelOpen
  ), Se = N((d) => d.filterValues), A = N((d) => d.isVisualEditing);
  Rt((d) => d.card);
  const se = Ue(
    (d) => d.selectedDashboard
  ), De = Ue(
    (d) => d.initialDashboard
  );
  Ue((d) => d.selectedVisual), N((d) => d.selectedFrameId), Rt((d) => d.frame);
  const ke = se ? (At = se == null ? void 0 : se.permissions) == null ? void 0 : At.canEdit : (It = De == null ? void 0 : De.permissions) == null ? void 0 : It.canEdit, ht = N(
    (d) => d.showDashboardJSON
  ), Be = N((d) => d.onSaveFunction), {
    setIsDashboardEditing: ft,
    setShowDashboardJSON: gt
  } = N((d) => d.actions), { setInitialDashboard: bt, clearSelectedDashboard: ze } = Ue(
    (d) => d.actions
  ), { resources: Ce } = wa(Xe.DASHBOARD), { data: je } = Na(), yr = ((Mt = je == null ? void 0 : je.preference) == null ? void 0 : Mt.defaultDashboardId) || null, { mutate: wr, isPending: Nr } = Sa(), { currentUser: Sr } = lt(), Dr = Da(Sr), T = se || De, xt = T ? {
    id: T.id,
    title: (o == null ? void 0 : o.title) || T.title || "Dashboard"
  } : null, { handleAddNewFrame: kr } = ka(), [qe, He] = w(!1), [Cr, oe] = w(!1), [Ve, Ee] = w("close"), ie = Ca(Xe.DASHBOARD), [O, Le] = w(null), Er = async (d, M) => {
    if (!(o != null && o.id)) {
      console.log("No dashboard ID found");
      return;
    }
    console.log("Updating dashboard title:", {
      dashboardId: o.id,
      newTitle: d,
      previousTitle: M
    }), ie.mutate(
      {
        resourceId: o.id,
        data: { title: d }
      },
      {
        onSuccess: () => {
          console.log("Dashboard title updated successfully"), C.success("Dashboard title updated");
        },
        onError: (F) => {
          console.error("Failed to update dashboard title:", F), C.error("Failed to update dashboard title"), D(M);
        }
      }
    );
  };
  Ge(() => {
    if (Ce && Ce.length > 0) {
      const d = o == null ? void 0 : o.id;
      if (d) {
        const M = Ce.find(
          (F) => F.id === d
        );
        M && bt(M);
      }
    }
  }, [Ce, o == null ? void 0 : o.id, bt]);
  const de = n.orgUserId || n.tenantId, Ke = K(
    () => ns({
      accessToken: e == null ? void 0 : e.accessToken,
      dashboardId: (o == null ? void 0 : o.id) || a || n.dashboard_id,
      selectedSheetId: k ? y : void 0,
      pageSize: L == null ? void 0 : L.size,
      orientation: L == null ? void 0 : L.orientation,
      theme: x
    }),
    [
      e == null ? void 0 : e.accessToken,
      a,
      o == null ? void 0 : o.id,
      k,
      L == null ? void 0 : L.orientation,
      L == null ? void 0 : L.size,
      y,
      x,
      n.dashboard_id
    ]
  ), vt = E && !A && de && ke, { setDashboard: yt } = N((d) => d.actions), wt = N(
    (d) => d.semanticExecutionPayload
  ), Lr = () => {
    ft(!0);
  }, Qe = () => {
    ft(!1), gt(!1), Le(null);
  };
  Ge(() => {
    if (!E) {
      O && Le(null);
      return;
    }
    O || !o || b || Le(
      Ht(
        o,
        wt
      )
    );
  }, [
    o,
    O,
    E,
    b,
    wt
  ]);
  const Ie = (O == null ? void 0 : O.dashboard) ?? null, { isDirty: Nt, isDirtyPending: Ir, resetDirty: Ae } = cn(
    o,
    Ie,
    300,
    1e3,
    Ze
  ), St = Wa(() => Ie ? Ze(o) !== Ze(Ie) : !1, [o, Ie]), Dt = Nt || Ir, Me = qe || ie.isPending, Ar = () => {
    St() ? (Ee("close"), oe(!0)) : (Qe(), Ae());
  }, Mr = async () => {
    await We({
      closeAfterSave: !0,
      navigateHomeAfterSave: Ve === "home"
    });
  }, Pr = () => {
    O && yt(O.dashboard, {
      semanticExecutionPayload: O.semanticExecutionPayload
    }), Qe(), Ve === "home" && ze(), Ee("close"), oe(!1), Ae();
  }, Or = () => {
    O && (yt(O.dashboard, {
      semanticExecutionPayload: O.semanticExecutionPayload
    }), Ae());
  }, _r = () => {
    if (E && St()) {
      Ee("home"), oe(!0);
      return;
    }
    ze();
  };
  async function We(d) {
    const M = N.getState().dashboard;
    if (!M)
      return;
    const F = (d == null ? void 0 : d.closeAfterSave) ?? U, Gr = (d == null ? void 0 : d.navigateHomeAfterSave) ?? !1;
    q(F), F && oe(!1);
    const Br = st(M);
    z(!0), ee(null), v([]), He(!0);
    const zr = {
      template: M
    };
    ie.mutate(
      {
        resourceId: M.id,
        data: zr
      },
      {
        onSuccess: (P) => {
          var Oe, _e, _t;
          const V = (P == null ? void 0 : P.id) || ((Oe = P == null ? void 0 : P.dashboard) == null ? void 0 : Oe.id) || ((_e = P == null ? void 0 : P.resource) == null ? void 0 : _e.id) || ((_t = P == null ? void 0 : P.template) == null ? void 0 : _t.id) || null;
          if (!M.id && V) {
            const Je = Zr.getState(), Re = Je.pendingDashboardDraftMigration;
            (Re == null ? void 0 : Re.scopeKey) === c ? Je.actions.setPendingDashboardDraftMigrationExpectedDashboardId(
              V
            ) : Re && Je.actions.clearPendingDashboardDraftMigration();
          }
          He(!1), C.success("Dashboard saved!"), Le(
            Ht(
              Br,
              N.getState().semanticExecutionPayload
            )
          ), z(!1), q(!1), F && (Qe(), Ae(), Gr && ze()), Ee("close");
        },
        onError: (P) => {
          He(!1), ee("Failed to save dashboard. Please try again.");
          const V = P.details, Oe = Array.isArray(
            V == null ? void 0 : V.errors
          ) ? (V.errors || []).filter(
            (_e) => typeof _e == "string"
          ) : [];
          v(
            rs({
              errors: Oe,
              dashboard: M || void 0
            })
          ), C.error("Failed to save dashboard");
        }
      }
    );
  }
  async function Rr() {
    if (Q(!0), !m || !g) return;
    const d = N.getState().dashboard;
    if (!d) {
      Q(!1);
      return;
    }
    const M = JSON.stringify(d), F = {
      ...g,
      template: M,
      filterValues: Se
    };
    await it(
      n.apiServiceUrl,
      F,
      e == null ? void 0 : e.accessToken
    ), C.success("Lens saved"), Be == null || Be(d), Q(!1);
  }
  const kt = (g == null ? void 0 : g.name) || o.title;
  ie.isPending && console.log("Title during update:", {
    title: kt,
    dashboardStateTitle: o.title,
    dashboardId: o == null ? void 0 : o.id,
    currentLensName: g == null ? void 0 : g.name
  });
  const Ct = n.orgUserId || n.tenantId && n.endUserId && n.endUserEmail, Ur = !!Ct && !!(e != null && e.accessToken) && !!(n != null && n.apiServiceUrl), Tr = l, H = (o == null ? void 0 : o.id) || null, Fr = as(
    (Pt = n.config) == null ? void 0 : Pt.showBriefings,
    r
  ), Pe = !!H && yr === H, $r = () => {
    H && wr({
      dashboardId: Pe ? null : H
    });
  };
  return /* @__PURE__ */ i(
    "div",
    {
      className: "flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",
      role: "dashboard-controls",
      children: [
        /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
          Ct && /* @__PURE__ */ i(R, { children: [
            /* @__PURE__ */ t(
              Ye,
              {
                "aria-label": "Manage Dashboards",
                tooltip: "Manage Dashboards",
                onClick: () => {
                  Ne(!we);
                },
                className: "h-7 w-7 px-0",
                buttonProps: { size: "xs" },
                children: /* @__PURE__ */ t(pn, { className: "h-3.5 w-3.5" })
              }
            ),
            Tr && !A && /* @__PURE__ */ t(
              Ye,
              {
                "aria-label": "Dashboard Hub",
                tooltip: "Dashboard Hub",
                onClick: _r,
                className: "h-7 w-7 px-0",
                buttonProps: { size: "xs" },
                children: /* @__PURE__ */ t(Yt, { className: "h-3.5 w-3.5" })
              }
            )
          ] }),
          !A && l && (b ? /* @__PURE__ */ t(
            "div",
            {
              className: "h-4 w-28 animate-pulse rounded-md bg-muted/70",
              "aria-label": "Loading dashboard title",
              role: "status",
              children: /* @__PURE__ */ t("span", { className: "sr-only", children: "Loading dashboard title" })
            }
          ) : /* @__PURE__ */ i(R, { children: [
            /* @__PURE__ */ t(
              Ea,
              {
                value: kt || "Untitled Dashboard",
                onSave: (d) => {
                  console.log("EditableText onSave called:", {
                    newTitle: d,
                    canEditDashboard: ke,
                    dashboardId: o == null ? void 0 : o.id
                  });
                  const M = (o == null ? void 0 : o.title) || "";
                  D(d), Er(d, M);
                },
                isEditable: ke && !g,
                displayClassName: "text-[13px] font-medium",
                inputClassName: "text-[13px] font-medium",
                placeholder: "Dashboard Title",
                isPending: ie.isPending
              }
            ),
            Ur && H && /* @__PURE__ */ t(Qr, { children: /* @__PURE__ */ i(Wr, { children: [
              /* @__PURE__ */ t(Jr, { asChild: !0, children: /* @__PURE__ */ t(
                _,
                {
                  variant: "ghost",
                  size: "xs",
                  onClick: $r,
                  disabled: Nr || !(e != null && e.accessToken) || !(n != null && n.apiServiceUrl),
                  className: "w-7 px-0",
                  "aria-label": Pe ? "Remove as default dashboard" : "Make this a default dashboard",
                  children: /* @__PURE__ */ t(
                    La,
                    {
                      className: te(
                        "h-3.5 w-3.5 transition-colors",
                        Pe ? "fill-foreground text-foreground" : "text-muted-foreground hover:text-foreground"
                      )
                    }
                  )
                }
              ) }),
              /* @__PURE__ */ t(Xr, { children: /* @__PURE__ */ t("p", { children: Pe ? "Remove as default dashboard" : "Make this a default dashboard" }) })
            ] }) })
          ] }))
        ] }),
        /* @__PURE__ */ i("div", { className: "flex items-center gap-2", children: [
          A && /* @__PURE__ */ i(R, { children: [
            /* @__PURE__ */ t(en, {}),
            /* @__PURE__ */ t(tn, {})
          ] }),
          !A && l && ((Ot = T == null ? void 0 : T.permissions) == null ? void 0 : Ot.canShare) && /* @__PURE__ */ i(
            _,
            {
              variant: "outline",
              size: "xs",
              onClick: () => fe(!0),
              children: [
                /* @__PURE__ */ t(Ia, { className: "h-3.5 w-3.5" }),
                "Share"
              ]
            }
          ),
          !A && !E && l && H && Fr && /* @__PURE__ */ t(
            rn,
            {
              dashboardId: H,
              dashboardTitle: (o == null ? void 0 : o.title) || (T == null ? void 0 : T.title)
            }
          ),
          !A && E && f.canUseFilters && l && /* @__PURE__ */ t(an, {}),
          E && !A && de && g && s && l && /* @__PURE__ */ i(
            _,
            {
              variant: "secondary",
              size: "xs",
              disabled: ae,
              onClick: Rr,
              children: [
                /* @__PURE__ */ t(Ut, { className: "h-3.5 w-3.5" }),
                "Save Lens"
              ]
            }
          ),
          E && !A && l && !k && /* @__PURE__ */ i(
            _,
            {
              variant: "outline",
              size: "xs",
              disabled: !E,
              onClick: () => kr(),
              children: [
                /* @__PURE__ */ t(re, { className: "h-3.5 w-3.5" }),
                "Visual"
              ]
            }
          ),
          !A && !E && ke && l && /* @__PURE__ */ i(_, { size: "xs", onClick: Lr, children: [
            /* @__PURE__ */ t(Aa, { className: "h-3.5 w-3.5" }),
            "Edit"
          ] }),
          vt && l && Nt && /* @__PURE__ */ i(
            _,
            {
              variant: "outline",
              size: "xs",
              onClick: Or,
              disabled: Me,
              children: [
                /* @__PURE__ */ t(nn, { className: "h-3.5 w-3.5" }),
                "Undo"
              ]
            }
          ),
          vt && l && /* @__PURE__ */ i(
            _,
            {
              size: "xs",
              className: te(!Dt && "opacity-60"),
              disabled: Me || !Dt,
              onClick: () => We(),
              children: [
                Me ? /* @__PURE__ */ t($e, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ t(Ut, { className: "h-3.5 w-3.5" }),
                Me ? "Saving..." : "Save"
              ]
            }
          ),
          E && !A && l && /* @__PURE__ */ i(_, { variant: "outline", size: "xs", onClick: Ar, children: [
            /* @__PURE__ */ t(Zt, { className: "h-3.5 w-3.5" }),
            "Close"
          ] }),
          !A && l && /* @__PURE__ */ t("div", { className: "ml-2", children: /* @__PURE__ */ t(sn, {}) }),
          !A && s && /* @__PURE__ */ t(Nn, {}),
          !A && l && /* @__PURE__ */ i(Ma, { children: [
            /* @__PURE__ */ t(Pa, { asChild: !0, children: /* @__PURE__ */ t(
              Ye,
              {
                tooltip: "More Options",
                className: "w-7 px-0 text-muted-foreground hover:text-foreground",
                buttonProps: {
                  size: "xs",
                  variant: "ghost",
                  "aria-label": "More dashboard options"
                },
                children: /* @__PURE__ */ t(Oa, { className: "h-3.5 w-3.5" })
              }
            ) }),
            /* @__PURE__ */ i(
              _a,
              {
                align: "end",
                className: "w-56 rounded-control border border-border/60 p-1 shadow-sm",
                children: [
                  /* @__PURE__ */ t(ue, { children: "Reports" }),
                  /* @__PURE__ */ i(
                    $,
                    {
                      disabled: p,
                      onSelect: () => ve(!0),
                      children: [
                        /* @__PURE__ */ t(Ra, { className: "h-3.5 w-3.5" }),
                        "Export"
                      ]
                    }
                  ),
                  /* @__PURE__ */ t(Fe, {}),
                  Dr && /* @__PURE__ */ i(R, { children: [
                    /* @__PURE__ */ t(ue, { children: "Access" }),
                    /* @__PURE__ */ i(
                      $,
                      {
                        onClick: () => J(!0),
                        children: [
                          /* @__PURE__ */ t(tr, { className: "h-3.5 w-3.5" }),
                          "Manage Groups"
                        ]
                      }
                    ),
                    /* @__PURE__ */ t(Fe, {})
                  ] }),
                  /* @__PURE__ */ t(ue, { children: "Preferences" }),
                  /* @__PURE__ */ i($, { onClick: () => Y(!0), children: [
                    /* @__PURE__ */ t(rr, { className: "h-3.5 w-3.5" }),
                    "Calendar Preferences"
                  ] }),
                  s && l && /* @__PURE__ */ i(R, { children: [
                    /* @__PURE__ */ t(Fe, {}),
                    /* @__PURE__ */ t(ue, { children: "Developer" }),
                    /* @__PURE__ */ i(
                      $,
                      {
                        onSelect: () => {
                          var d;
                          e != null && e.accessToken && ((d = navigator == null ? void 0 : navigator.clipboard) != null && d.writeText ? navigator.clipboard.writeText(e.accessToken).then(
                            () => C.success("Token copied to clipboard")
                          ).catch(() => C.error("Unable to copy token")) : C.error("Clipboard not available"));
                        },
                        children: [
                          /* @__PURE__ */ t(Ft, { className: "h-3.5 w-3.5" }),
                          "Copy token"
                        ]
                      }
                    ),
                    k && /* @__PURE__ */ i(
                      $,
                      {
                        disabled: !Ke,
                        onSelect: () => {
                          var d;
                          if (!Ke) {
                            C.error(
                              "Open a document sheet with a token to copy the local PDF URL"
                            );
                            return;
                          }
                          (d = navigator == null ? void 0 : navigator.clipboard) != null && d.writeText ? navigator.clipboard.writeText(Ke).then(
                            () => C.success(
                              "Local document PDF URL copied to clipboard"
                            )
                          ).catch(
                            () => C.error(
                              "Unable to copy local document PDF URL"
                            )
                          ) : C.error("Clipboard not available");
                        },
                        children: [
                          /* @__PURE__ */ t(Ft, { className: "h-3.5 w-3.5" }),
                          "Copy local document PDF URL"
                        ]
                      }
                    ),
                    /* @__PURE__ */ i(
                      $,
                      {
                        onSelect: () => Yr(n.apiServiceUrl),
                        children: [
                          /* @__PURE__ */ t(gn, { className: "h-3.5 w-3.5" }),
                          "Invalidate token"
                        ]
                      }
                    ),
                    /* @__PURE__ */ i($, { onSelect: u, children: [
                      /* @__PURE__ */ t(ln, { className: "h-3.5 w-3.5" }),
                      "Brand Studio"
                    ] }),
                    E && /* @__PURE__ */ i(
                      $,
                      {
                        onSelect: () => gt(!ht),
                        children: [
                          /* @__PURE__ */ t(un, { className: "h-3.5 w-3.5" }),
                          ht ? "Hide dashboard JSON" : "Show dashboard JSON"
                        ]
                      }
                    ),
                    de && E && /* @__PURE__ */ i($, { onSelect: () => be(!0), children: [
                      /* @__PURE__ */ t(re, { className: "h-3.5 w-3.5" }),
                      "Add lens"
                    ] }),
                    de && /* @__PURE__ */ i(Ua, { children: [
                      /* @__PURE__ */ i(Ta, { children: [
                        /* @__PURE__ */ t(mn, { className: "h-3.5 w-3.5" }),
                        "Lenses"
                      ] }),
                      /* @__PURE__ */ t(Fa, { className: "w-60", children: /* @__PURE__ */ t(En, {}) })
                    ] })
                  ] })
                ]
              }
            )
          ] }),
          ne && xt && /* @__PURE__ */ t(
            $a,
            {
              resource: xt,
              resourceType: Xe.DASHBOARD,
              onClose: () => fe(!1)
            }
          ),
          /* @__PURE__ */ t(
            Wn,
            {
              open: W,
              onOpenChange: J
            }
          ),
          /* @__PURE__ */ t(
            dn,
            {
              open: X,
              onOpenChange: Y
            }
          ),
          s && de && l && /* @__PURE__ */ t(Cn, { open: ge, onOpenChange: be }),
          l && /* @__PURE__ */ t(
            Ga,
            {
              open: xe,
              onOpenChange: ve
            }
          ),
          /* @__PURE__ */ t(
            Ba,
            {
              open: ye,
              onOpenChange: (d) => {
                !d && qe && !Z || (z(d), d || (ee(null), v([]), q(!1)));
              },
              children: /* @__PURE__ */ i(za, { className: "max-w-sm", children: [
                /* @__PURE__ */ i(ja, { children: [
                  /* @__PURE__ */ t(qa, { children: Z ? "Save failed" : "Saving dashboard" }),
                  /* @__PURE__ */ t(Ha, { className: "pt-2", children: Z ? "We could not save the dashboard. Please try again." : "Please wait while we save your changes." }),
                  j.length > 0 && /* @__PURE__ */ i("div", { className: "space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left", children: [
                    /* @__PURE__ */ t("div", { className: "text-sm font-medium text-destructive", children: "What needs attention" }),
                    /* @__PURE__ */ t("ul", { className: "list-disc space-y-1 pl-4 text-xs text-muted-foreground", children: j.slice(0, 5).map((d) => /* @__PURE__ */ t("li", { children: d }, d)) })
                  ] })
                ] }),
                /* @__PURE__ */ t(Va, { className: "flex-col gap-2 sm:flex-row sm:justify-end", children: Z ? /* @__PURE__ */ i(R, { children: [
                  /* @__PURE__ */ t(
                    Ka,
                    {
                      onClick: () => {
                        z(!1), ee(null), v([]), q(!1);
                      },
                      className: "m-0",
                      children: "Close"
                    }
                  ),
                  /* @__PURE__ */ t(
                    $t,
                    {
                      onClick: () => We({
                        closeAfterSave: U,
                        navigateHomeAfterSave: Ve === "home"
                      }),
                      className: "m-0",
                      children: "Retry"
                    }
                  )
                ] }) : /* @__PURE__ */ i($t, { disabled: !0, className: "m-0 cursor-default", children: [
                  /* @__PURE__ */ t($e, { className: "mr-2 h-4 w-4 animate-spin" }),
                  "Saving..."
                ] }) })
              ] })
            }
          ),
          /* @__PURE__ */ t(
            on,
            {
              open: Cr,
              onOpenChange: (d) => {
                oe(d);
              },
              onSave: Mr,
              onDiscard: Pr,
              isSaving: qe,
              saveLabel: "Save",
              discardLabel: "Discard"
            }
          )
        ] })
      ]
    }
  );
}
function ns({
  accessToken: e,
  dashboardId: n,
  selectedSheetId: a,
  pageSize: r,
  orientation: s,
  theme: u
}) {
  if (!e || !a)
    return null;
  const f = new URL("http://localhost:5173/print-document");
  f.searchParams.set("token", e), n && f.searchParams.set("dashboardId", n), f.searchParams.set("selectedSheetId", a), u && f.searchParams.set("theme", u);
  const l = new URL("http://127.0.0.1:3002/");
  return l.searchParams.set("pdfMode", "document"), l.searchParams.set("pageSize", r || "letter"), l.searchParams.set("orientation", s || "portrait"), l.searchParams.set("url", f.toString()), l.toString();
}
export {
  ys as default
};
