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 w, renderList as O, normalizeClass as E, createElementVNode as R, toDisplayString as v, 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-row-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) => ({
      d3e7b97c: e.basicOption.css.table.borderWidth + "px",
      "1afb3254": e.basicOption.css.table.borderStyle,
      "1cc30ef0": e.basicOption.css.table.borderColor,
      "8f0e5278": e.basicOption.css.table.paddingLeft + "px",
      "4b2887aa": e.basicOption.css.table.alignItems,
      "295a5c38": e.basicOption.css.table.justifyContent,
      ce1ea980: e.basicOption.css.header.background,
      81733398: e.basicOption.css.header.height + "px",
      "08f1d611": e.basicOption.css.header.color,
      "283e3ecb": e.basicOption.css.header.fontSize + "px",
      "86dc4c8e": e.basicOption.css.header.fontWeight,
      "1eaa1a50": e.basicOption.css.header.fontStyle,
      "12327c49": e.basicOption.css.body.height + "px",
      "7751554b": e.basicOption.css.body.background,
      "1ab1644e": e.basicOption.css.oddBackground,
      bb285db4: e.basicOption.css.body.color,
      "707d23a0": e.basicOption.css.body.fontSize + "px",
      ca1af878: e.basicOption.css.body.fontWeight,
      "25d682e5": 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), c.value = [], m.value = g(), 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(w, null, O(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, v(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(w, null, O(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(w, null, O(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, v(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
                })
              }, v(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
};
