import { defineComponent as z, useCssVars as B, ref as h, onMounted as I, watch as S, createElementBlock as i, createCommentVNode as E, openBlock as r, createVNode as R, normalizeStyle as d, Fragment as O, renderList as v, normalizeClass as V, createElementVNode as j, toDisplayString as w, 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";
import { SHJDatasourceV2 as U } from "../../commons/core/datasource/index.mjs";
const G = ["onClick", "onMouseenter", "onMouseout"], K = ["onClick"], Q = { key: 1 }, X = z({ name: "zv-text-row-scroll" }), te = /* @__PURE__ */ z({
  ...X,
  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) => ({
      "0666b15e": e.basicOption.css.table.borderWidth + "px",
      "5631c5a7": e.basicOption.css.table.borderStyle,
      "554dd759": e.basicOption.css.table.borderColor,
      "1f395ad3": e.basicOption.css.table.paddingLeft + "px",
      "35998ab9": e.basicOption.css.table.alignItems,
      c3358072: e.basicOption.css.table.justifyContent,
      "06bfebde": e.basicOption.css.header.background,
      "345149c3": e.basicOption.css.header.height + "px",
      "33c4b8a0": e.basicOption.css.header.color,
      f3c30acc: e.basicOption.css.header.fontSize + "px",
      "2041388a": e.basicOption.css.header.fontWeight,
      "091b1d5f": e.basicOption.css.header.fontStyle,
      "246ef798": e.basicOption.css.body.height + "px",
      "2b879748": e.basicOption.css.body.background,
      "4a3ad39f": e.basicOption.css.oddBackground,
      "2b37e916": e.basicOption.css.body.color,
      "34eff1a2": e.basicOption.css.body.fontSize + "px",
      "0ddd62d5": e.basicOption.css.body.fontWeight,
      "310a0498": e.basicOption.css.body.fontStyle
    }));
    const b = M, m = h(g()), l = h([]), s = H, p = h(s.basicOption.scroll.start), u = () => {
      U.parse({
        tId: s.uuid,
        sources: s.sources,
        callback: (e) => {
          try {
            window.SHJParseEvent(s.useEvents, "dataListener", l), l.value = y(e.data[0].data) || [], m.value = g(), p.value = s.basicOption.scroll.start;
          } catch {
            window.SHJParseEvent(s.useEvents, "dataListener", null), l.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;
    }, f = (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) => l.value.length > 0 ? (r(), i("div", {
      key: m.value,
      class: "table-scroll"
    }, [
      e.basicOption.css.header.show ? (r(), i("div", {
        key: 0,
        class: "table-header",
        style: d({
          "--header-background-image": `url(${e.basicOption.css.header.backgroundImage})`
        })
      }, [
        (r(!0), i(O, null, v(Object.keys(l.value[0]), (t, a) => (r(), i("div", {
          key: t,
          class: V(["th", { customWidth: !k(a + 1) }]),
          style: d({ "--width": C(a + 1) + "px" })
        }, [
          j("p", null, w(t), 1)
        ], 6))), 128))
      ], 4)) : E("", !0),
      R(A(q), {
        modelValue: p.value,
        "onUpdate:modelValue": o[0] || (o[0] = (t) => p.value = t),
        direction: e.basicOption.scroll.direction,
        list: l.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(() => [
          (r(!0), i(O, null, v(l.value, (t, a) => (r(), i("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)
          }, [
            (r(!0), i(O, null, v(P(t), (n, c) => (r(), i("div", {
              key: n,
              class: V(["td", { customWidth: !k(c + 1) }]),
              style: d({ "--width": C(c + 1) + "px" }),
              onClick: (Y) => N(t, n, a, c)
            }, [
              $(c + 1) ? (r(), i("p", Q, w(n), 1)) : (r(), i("p", {
                key: 0,
                class: "customFont",
                style: d({
                  "--text-color": f(c + 1).color,
                  "--text-font-size": f(c + 1).fontSize + "px",
                  "--text-font-style": f(c + 1).fontStyle
                })
              }, w(n), 5))
            ], 14, K))), 128))
          ], 44, G))), 128))
        ]),
        _: 1
      }, 8, ["modelValue", "direction", "list", "hover", "limit-scroll-num", "single-height", "single-wait-time"])
    ])) : E("", !0);
  }
});
export {
  te as default
};
