import { defineComponent as T, ref as B, watch as N, onMounted as C, openBlock as o, createElementBlock as f, createVNode as x, withCtx as l, Fragment as i, renderList as I, createBlock as p, unref as b, createTextVNode as v, toDisplayString as h } from "vue";
import U from "@leaflink/snitch";
import { kebabCase as r } from "es-toolkit";
import { useRoute as M, useRouter as P } from "vue-router";
import D from "./Badge.js";
import E from "./Menu.js";
import F from "./MenuItem.js";
import L from "./Tab.js";
import { _ as O } from "./Tabs.vue_vue_type_script_setup_true_lang-Swgl9-sG.js";
const R = {
  class: "stash-page-navigation container",
  "data-test": "stash-page-navigation"
}, Q = /* @__PURE__ */ T({
  name: "ll-page-navigation",
  __name: "PageNavigation",
  props: {
    activeIndex: { default: void 0 },
    modelValue: { default: "" },
    items: {}
  },
  emits: ["update:modelValue", "change"],
  setup(k, { emit: V }) {
    const n = k, g = V;
    n.activeIndex && U.info("The `activeIndex` prop is deprecated. Use `v-model` instead.");
    const d = M(), _ = P(), c = B("");
    function s(t) {
      t !== c.value && (c.value = t, g("update:modelValue", t));
    }
    return N(
      () => n.modelValue,
      (t, e) => {
        if (e === t) return;
        const a = n.items.findIndex((u) => r(u.label) === t);
        g("change", a), s(t);
      }
    ), C(() => {
      if (!n.items.length) return;
      if (n.activeIndex !== void 0) {
        const e = n.items[n.activeIndex];
        s(r(e.label));
        return;
      }
      if (n.modelValue !== c.value) {
        s(n.modelValue);
        return;
      }
      if (!_) return;
      const t = n.items.find((e) => {
        if (e != null && e.disabled || !(e != null && e.to) && !(e != null && e.href)) return;
        const { path: a } = _.resolve((e == null ? void 0 : e.to) || (e == null ? void 0 : e.href));
        if (a === d.path)
          return !0;
        if (!d.path.includes(a)) return;
        const u = (d.path.length - d.path.lastIndexOf("/")) * -1, y = d.path.slice(0, u);
        return a === y;
      });
      t && s((t == null ? void 0 : t.value) || r(t.label));
    }), (t, e) => (o(), f("nav", R, [
      x(O, {
        "active-tab": c.value,
        "onUpdate:activeTab": s
      }, {
        "more-actions": l(() => [
          x(E, null, {
            default: l(() => [
              (o(!0), f(i, null, I(n.items, (a) => (o(), p(F, {
                key: a.label,
                "data-action-id": (a == null ? void 0 : a.value) || b(r)(a.label),
                "is-disabled": a.disabled
              }, {
                default: l(() => [
                  a.badge ? (o(), p(D, {
                    key: 0,
                    content: a.badge,
                    position: "inline",
                    color: "red"
                  }, {
                    default: l(() => [
                      v(h(a.label), 1)
                    ]),
                    _: 2
                  }, 1032, ["content"])) : (o(), f(i, { key: 1 }, [
                    v(h(a.label), 1)
                  ], 64))
                ]),
                _: 2
              }, 1032, ["data-action-id", "is-disabled"]))), 128))
            ]),
            _: 1
          })
        ]),
        default: l(() => [
          (o(!0), f(i, null, I(n.items, (a, u) => (o(), p(L, {
            key: a.label,
            value: (a == null ? void 0 : a.value) || b(r)(a.label),
            to: a.to,
            href: a.href,
            badge: a.badge,
            disabled: a.disabled,
            "data-id": u,
            "data-action-id": (a == null ? void 0 : a.value) || b(r)(a.label)
          }, {
            default: l(() => [
              v(h(a.label), 1)
            ]),
            _: 2
          }, 1032, ["value", "to", "href", "badge", "disabled", "data-id", "data-action-id"]))), 128))
        ]),
        _: 1
      }, 8, ["active-tab"])
    ]));
  }
});
export {
  Q as default
};
//# sourceMappingURL=PageNavigation.js.map
