import { ref as y, reactive as _, watch as v, onMounted as w, openBlock as E, createElementBlock as M, createElementVNode as g, createVNode as k } from "vue";
import { l as $, aE as S, aF as h, aG as O } from "./index2.js";
import { c as T } from "./index20.js";
function U(c) {
  if (!c) return null;
  c = T(c);
  let l = Array.isArray(c) ? c.concat() : [c];
  for (; l.length; ) {
    const p = l.length;
    for (let r = 0; r < p; r++) {
      const e = l.shift();
      !e.children || !e.children.length || (e.children.forEach((a) => {
        a.path[0] !== "/" && !a.path.startsWith("http") && (a.path = e.path.replace(/(\w*)[/]*$/, `$1/${a.path}`));
      }), l = l.concat(e.children));
    }
  }
  return c;
}
const x = { class: "s-menu-top-common" }, A = { class: "menu-wrap" }, N = {
  __name: "STopMenu",
  setup(c) {
    const l = S(), p = y([]), r = y(""), e = _({
      collapsed: !1,
      selectedKeys: [],
      openKeys: [],
      preOpenKeys: []
    });
    v(
      () => e.openKeys,
      (n, s) => {
        e.preOpenKeys = s;
      }
    );
    const a = (n) => n.map((t) => {
      const o = {
        key: t.path,
        // icon: item.icon ? () => h(item.icon) : null,
        icon: null,
        label: t.name || t.meta.title,
        title: t.name || t,
        path: t.path
      };
      return t.children && (o.children = a(t.children)), o;
    }), K = (n) => {
      l.push(n.key), e.selectedKeys = [n.key], window.$utils.ls.set("selectedKeys", e.selectedKeys);
    }, m = (n) => {
      const s = n.filter((i) => !e.preOpenKeys.includes(i)), t = s[s.length - 1];
      e.openKeys = [t], h().setMenuOpenKeys(e.openKeys);
    };
    return w(() => {
      r.value = window.$utils.env.VITE_APP_MENU_THEME || "dark";
      const n = h(), s = n.dynamics, t = U(s.find((u) => u.path === "/")), o = t && t.children || [];
      p.value = a([...o].filter((u) => {
        var d;
        return !((d = u.meta) != null && d.hidden);
      }));
      const i = location.pathname;
      window.$utils.ls.set("selectedKeys", [i]), e.selectedKeys = window.$utils.ls.get("selectedKeys") || [];
      const f = n.openKeys || [];
      e.openKeys = f;
    }), (n, s) => {
      const t = O;
      return E(), M("div", x, [
        g("div", A, [
          k(t, {
            openKeys: e.openKeys,
            "onUpdate:openKeys": s[0] || (s[0] = (o) => e.openKeys = o),
            selectedKeys: e.selectedKeys,
            "onUpdate:selectedKeys": s[1] || (s[1] = (o) => e.selectedKeys = o),
            mode: "horizontal",
            theme: r.value,
            items: p.value,
            onSelect: K,
            onOpenChange: m
          }, null, 8, ["openKeys", "selectedKeys", "theme", "items"])
        ])
      ]);
    };
  }
}, B = /* @__PURE__ */ $(N, [["__scopeId", "data-v-ad258b82"]]);
export {
  B as default
};
