import { defineComponent as k, ref as i, onMounted as E, createElementBlock as c, openBlock as r, normalizeStyle as u, unref as v, createCommentVNode as b, Fragment as O, renderList as w, withModifiers as L, normalizeClass as V, createVNode as B, nextTick as D } from "vue";
import { useResizeObserver as N } from "@vueuse/core";
import { useTabsWatch as T } from "./hooks/useTabsWatch.mjs";
import { SHJDatasourceV2 as W } from "../../../commons/plugins/datasource/index.mjs";
import { SHJParseEvent as H } from "../../../commons/plugins/event/index.mjs";
import { Utils as f } from "../../../commons/utils/utils.mjs";
import I from "../../../commons/components/text.vue.mjs";
const J = ["onClick"], M = k({ name: "shj-tabs" }), K = /* @__PURE__ */ k({
  ...M,
  props: {
    option: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: ["on-change"],
  setup(x, { expose: g, emit: y }) {
    const e = x, _ = y, l = i([]), o = i(e.option.value), a = () => {
      W.parse({
        tId: e.uuid,
        sources: e.sources,
        callback: ({ data: t }) => {
          if (!t) {
            l.value = [];
            return;
          }
          l.value = t[0].data, !o.value && l.value.length > 0 && (o.value = l.value[0].value), m();
        }
      });
    };
    E(() => a());
    const C = (t) => {
      t.value !== o.value && (_("on-change", t), H.parseEvents(e.useEvents, "on-change", t)), o.value = t.value;
    };
    T(e, a, o, l), g({
      refresh: () => a(),
      refreshView: () => {
      },
      // 刷新视图 无需刷新
      refreshData: () => a()
    });
    const s = i(null), d = 150, p = i(!1), m = () => {
      D(() => {
        if (s.value) {
          const { scrollWidth: t, clientWidth: h } = s.value;
          p.value = t > h;
        }
      });
    }, j = () => {
      s.value && (s.value.scrollLeft -= d);
    }, S = () => {
      s.value && (s.value.scrollLeft += d);
    };
    return N(s, (t) => m()), (t, h) => (r(), c("div", {
      ref_key: "tabsContainer",
      ref: s,
      class: "height-100 flex overflow-hidden scroll-behavior-smooth",
      style: u(v(f).json2cssObject(e.option.css.tab))
    }, [
      p.value ? (r(), c("button", {
        key: 0,
        class: "flex-none cursor-pointer position-absolute translate-center-left-active-scale-095 top-50 background-size-cover",
        style: u(v(f).json2cssObject(e.option.css.nav.left)),
        onClick: j
      }, null, 4)) : b("", !0),
      (r(!0), c(O, null, w(l.value, (n, z) => (r(), c("div", {
        key: z,
        class: V(["flex flex-none cursor-pointer transition-color-background-color background-size-cover", { selected: n.value === o.value }]),
        style: u(v(f).json2cssObject(n.value === o.value ? e.option.css.item.selected : e.option.css.item)),
        onClick: L((R) => C(n), ["stop"])
      }, [
        B(I, {
          "text-style": n.value === o.value ? e.option.css.item.selected.textStyle : e.option.css.item.textStyle,
          text: n.label
        }, null, 8, ["text-style", "text"])
      ], 14, J))), 128)),
      p.value ? (r(), c("button", {
        key: 1,
        class: "flex-none cursor-pointer position-absolute translate-center-right-active-scale-095 top-50 background-size-cover",
        style: u(v(f).json2cssObject(e.option.css.nav.right)),
        onClick: S
      }, null, 4)) : b("", !0)
    ], 4));
  }
});
export {
  K as default
};
