import { defineComponent as x, computed as C, resolveComponent as g, openBlock as a, createElementBlock as l, Fragment as f, renderList as _, normalizeClass as h, toDisplayString as A, createBlock as E, withCtx as S, createTextVNode as b } from "vue";
import { APPS as r } from "./constants.js";
import { setPersistentItem as T, getPersistentItem as v, removePersistentItem as R } from "./utils/storage.js";
const N = {
  class: "stash-context-switcher mx-auto flex w-64 rounded-full border border-white/10 bg-purple-700 p-1.5 text-center",
  "data-test": "stash-context-switcher"
}, B = ["href", "onClick"], y = "-last-session", L = /* @__PURE__ */ x({
  name: "ll-context-switcher",
  __name: "ContextSwitcher",
  props: {
    activeApp: {},
    portalAccess: { default: () => ({
      commercePortal: !1,
      paymentsPortal: !1
    }) },
    limitedAccessUrl: {},
    routeQuery: { default: () => ({}) }
  },
  emits: ["click", "switch"],
  setup(i, { emit: w }) {
    const t = i, m = w, P = C(() => [
      {
        app: r.MARKETPLACE,
        name: t.portalAccess.commercePortal ? "dashboard" : t.limitedAccessUrl,
        hasBaseRoute: t.portalAccess.commercePortal
      },
      {
        app: r.PAYMENTS,
        name: t.portalAccess.paymentsPortal ? "payments" : t.limitedAccessUrl,
        hasBaseRoute: !1
      }
    ]);
    function u(s, n) {
      if (n === t.activeApp)
        return;
      const o = window.location.href;
      let e = s.target.href;
      if (t.portalAccess.paymentsPortal && t.portalAccess.commercePortal) {
        const k = `${n === r.PAYMENTS ? r.MARKETPLACE : r.PAYMENTS}${y}`, d = `${n}${y}`;
        T(k, o, { global: !0 });
        const p = v(d, { global: !0 });
        p && (s.preventDefault(), e = p, window.location.href = p, R(d, { global: !0 }));
      }
      m("click", { from: o, to: e }), m("switch", s, { from: o, to: e });
    }
    return (s, n) => {
      const o = g("router-link");
      return a(), l("div", N, [
        (a(!0), l(f, null, _(P.value, (e) => (a(), l(f, {
          key: e.app
        }, [
          e.hasBaseRoute ? (a(), l("a", {
            key: 0,
            class: h(["w-1/2 cursor-pointer rounded-full py-2.5 font-semibold !capitalize leading-none !no-underline", t.activeApp === e.app ? "text-white bg-royal-500" : "text-ice-500"]),
            href: `/${e.name}`,
            onClick: (c) => u(c, e.app)
          }, A(e.app), 11, B)) : (a(), E(o, {
            key: 1,
            class: h(["w-1/2 cursor-pointer rounded-full py-2.5 font-semibold !capitalize leading-none !no-underline", t.activeApp === e.app ? "text-white bg-royal-500" : "text-ice-500"]),
            to: { name: e.name, query: i.routeQuery },
            "data-test-route": JSON.stringify({ name: e.name, query: i.routeQuery }),
            onClick: (c) => u(c, e.app)
          }, {
            default: S(() => [
              b(A(e.app), 1)
            ]),
            _: 2
          }, 1032, ["class", "to", "data-test-route", "onClick"]))
        ], 64))), 128))
      ]);
    };
  }
});
export {
  L as default
};
//# sourceMappingURL=ContextSwitcher.js.map
