import { defineComponent as z, useCssVars as B, ref as f, onMounted as I, watch as S, openBlock as i, createElementBlock as r, normalizeStyle as d, Fragment as O, renderList as v, normalizeClass as E, createElementVNode as R, toDisplayString as w, createCommentVNode as V, createVNode as j, unref as A, withCtx as T } from "vue";
import { cloneDeep as y, isEqual as W } from "lodash";
import { Vue3SeamlessScroll as q } from "vue3-seamless-scroll";
import { nanoid as g } from "nanoid";
const U = ["onClick", "onMouseenter", "onMouseout"], G = ["onClick"], K = { key: 1 }, Q = z({ name: "zv-text-table-scroll" }), ee = /* @__PURE__ */ z({
  ...Q,
  props: {
    basicOption: {},
    useEvents: {},
    sources: {},
    uuid: {}
  },
  emits: ["on-click-item", "on-click-row", "on-mouseenter-row", "on-mouseout-row"],
  setup(H, { expose: J, emit: M }) {
    B((e) => ({
      "7d610320": e.basicOption.css.table.borderWidth + "px",
      "3acc84b8": e.basicOption.css.table.borderStyle,
      "39e8966a": e.basicOption.css.table.borderColor,
      c06492bc: e.basicOption.css.table.paddingLeft + "px",
      bfdbb4f0: e.basicOption.css.table.alignItems,
      db3449d4: e.basicOption.css.table.justifyContent,
      "3d8a6dbc": e.basicOption.css.header.background,
      "2851e512": e.basicOption.css.header.height + "px",
      "18bdda22": e.basicOption.css.header.color,
      "7c657e29": e.basicOption.css.header.fontSize + "px",
      "04dbf79b": e.basicOption.css.header.fontWeight,
      "7393b82e": e.basicOption.css.header.fontStyle,
      "59a7cab2": e.basicOption.css.body.height + "px",
      "1424f8a6": e.basicOption.css.body.background,
      f42c79a0: e.basicOption.css.oddBackground,
      "523ea4f8": e.basicOption.css.body.color,
      "4ceebb04": e.basicOption.css.body.fontSize + "px",
      "198eb226": e.basicOption.css.body.fontWeight,
      "21aa0043": e.basicOption.css.body.fontStyle
    }));
    const b = M, m = f(g()), c = f([]), s = H, p = f(s.basicOption.scroll.start), u = () => {
      window.SHJDatasourceV2({
        tId: s.uuid,
        sources: s.sources,
        callback: (e) => {
          try {
            window.SHJParseEvent(s.useEvents, "dataListener", c), c.value = y(e.data[0].data) || [], m.value = g(), p.value = s.basicOption.scroll.start;
          } catch {
            window.SHJParseEvent(s.useEvents, "dataListener", null), m.value = g(), c.value = [], p.value = s.basicOption.scroll.start;
          }
        }
      });
    }, P = (e) => {
      const o = [];
      for (const t in e)
        o.push(e[t]);
      return o;
    };
    I(() => u()), S(() => y(s.basicOption), (e, o) => {
      W(e, o) || u();
    }, {
      deep: !0
    }), S(() => y(s.sources), (e, o) => {
      W(e, o) || u();
    }, {
      deep: !0
    }), J({
      refresh: () => u(),
      refreshView: () => u(),
      refreshData: () => u()
    });
    const $ = (e) => {
      if (!s.basicOption.columns)
        return !0;
      const o = s.basicOption.columns.find((t) => t.index === e);
      return o ? o.font.auto : !0;
    }, h = (e) => {
      if (!s.basicOption.columns)
        return null;
      const o = s.basicOption.columns.find((t) => t.index === e);
      return o && o.font.auto === !1 ? o.font : null;
    }, k = (e) => {
      if (!s.basicOption.columns)
        return !0;
      const o = s.basicOption.columns.find((t) => t.index === e);
      return o ? o.width.auto : !0;
    }, C = (e) => {
      if (!s.basicOption.columns)
        return null;
      const o = s.basicOption.columns.find((t) => t.index === e);
      return o && o.width.auto === !1 ? o.width.width : null;
    }, D = (e, o) => {
      const t = { row: e, rowIndex: o };
      b("on-click-row", t), window.SHJParseEvent(s.useEvents, "on-click-row", t);
    }, F = (e, o) => {
      const t = { row: e, rowIndex: o };
      b("on-mouseenter-row", t), window.SHJParseEvent(s.useEvents, "on-mouseenter-row", t);
    }, L = (e, o) => {
      const t = { row: e, rowIndex: o };
      b("on-mouseout-row", t), window.SHJParseEvent(s.useEvents, "on-mouseout-row", t);
    }, N = (e, o, t, a) => {
      const n = { row: e, item: o, rowIndex: t, columnIndex: a };
      b("on-click-item", n), window.SHJParseEvent(s.useEvents, "on-click-item", n);
    };
    return (e, o) => c.value.length > 0 ? (i(), r("div", {
      key: m.value,
      class: "table-scroll"
    }, [
      e.basicOption.css.header.show ? (i(), r("div", {
        key: 0,
        class: "table-header",
        style: d({
          "--header-background-image": `url(${e.basicOption.css.header.backgroundImage})`
        })
      }, [
        (i(!0), r(O, null, v(Object.keys(c.value[0]), (t, a) => (i(), r("div", {
          key: t,
          class: E(["th", { customWidth: !k(a + 1) }]),
          style: d({ "--width": C(a + 1) + "px" })
        }, [
          R("p", null, w(t), 1)
        ], 6))), 128))
      ], 4)) : V("", !0),
      j(A(q), {
        modelValue: p.value,
        "onUpdate:modelValue": o[0] || (o[0] = (t) => p.value = t),
        direction: e.basicOption.scroll.direction,
        list: c.value,
        "is-watch": "",
        hover: e.basicOption.scroll.hover,
        "limit-scroll-num": e.basicOption.scroll.limitScrollNum,
        "single-height": e.basicOption.scroll.isSingle ? e.basicOption.css.body.height : 0,
        "single-wait-time": e.basicOption.scroll.singleWaitTime,
        class: "table-body"
      }, {
        default: T(() => [
          (i(!0), r(O, null, v(c.value, (t, a) => (i(), r("div", {
            key: t,
            class: "tr",
            style: d({
              "--row-hover": e.basicOption.css.hoverColor
            }),
            onClick: (n) => D(t, a),
            onMouseenter: (n) => F(t, a),
            onMouseout: (n) => L(t, a)
          }, [
            (i(!0), r(O, null, v(P(t), (n, l) => (i(), r("div", {
              key: n,
              class: E(["td", { customWidth: !k(l + 1) }]),
              style: d({ "--width": C(l + 1) + "px" }),
              onClick: (X) => N(t, n, a, l)
            }, [
              $(l + 1) ? (i(), r("p", K, w(n), 1)) : (i(), r("p", {
                key: 0,
                class: "customFont",
                style: d({
                  "--text-color": h(l + 1).color,
                  "--text-font-size": h(l + 1).fontSize + "px",
                  "--text-font-style": h(l + 1).fontStyle
                })
              }, w(n), 5))
            ], 14, G))), 128))
          ], 44, U))), 128))
        ]),
        _: 1
      }, 8, ["modelValue", "direction", "list", "hover", "limit-scroll-num", "single-height", "single-wait-time"])
    ])) : V("", !0);
  }
});
export {
  ee as default
};
