import { defineComponent as W, useCssVars as B, ref as h, onMounted as I, watch as S, createElementBlock as i, createCommentVNode as E, openBlock as r, normalizeStyle as u, createVNode as R, 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 H } 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 = W({ name: "zv-text-table-scroll" }), te = /* @__PURE__ */ W({
  ...X,
  props: {
    basicOption: {},
    useEvents: {},
    sources: {},
    uuid: {}
  },
  emits: ["on-click-item", "on-click-row", "on-mouseenter-row", "on-mouseout-row"],
  setup(z, { expose: J, emit: M }) {
    B((e) => ({
      c8ab01be: e.basicOption.css.table.borderWidth + "px",
      "16a7d052": e.basicOption.css.table.borderStyle,
      "186facee": e.basicOption.css.table.borderColor,
      "83d19aba": e.basicOption.css.table.paddingLeft + "px",
      32743289: e.basicOption.css.table.alignItems,
      "49f100d2": e.basicOption.css.table.justifyContent,
      c9cb477e: e.basicOption.css.header.background,
      "70f38993": e.basicOption.css.header.height + "px",
      "6d4bc870": e.basicOption.css.header.color,
      "2330066a": e.basicOption.css.header.fontSize + "px",
      "8288ea8c": e.basicOption.css.header.fontWeight,
      "05f5c52f": e.basicOption.css.header.fontStyle,
      "7685528c": e.basicOption.css.body.background,
      "4195bdcf": e.basicOption.css.oddBackground,
      a9e66176: e.basicOption.css.body.color,
      "222a46ff": e.basicOption.css.body.fontSize + "px",
      cbb2fdf6: e.basicOption.css.body.fontWeight,
      "49054cf8": e.basicOption.css.body.fontStyle
    }));
    const b = M, m = h(g()), c = h([]), s = z, p = h(s.basicOption.scroll.start), d = () => {
      U.parse({
        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(() => d()), S(() => y(s.basicOption), (e, o) => {
      H(e, o) || d();
    }, {
      deep: !0
    }), S(() => y(s.sources), (e, o) => {
      H(e, o) || d();
    }, {
      deep: !0
    }), J({
      refresh: () => d(),
      refreshView: () => d(),
      refreshData: () => d()
    });
    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, l) => {
      const n = { row: e, item: o, rowIndex: t, columnIndex: l };
      b("on-click-item", n), window.SHJParseEvent(s.useEvents, "on-click-item", n);
    };
    return (e, o) => c.value.length > 0 ? (r(), i("div", {
      key: m.value,
      class: "table-scroll",
      style: u({ lineHeight: e.basicOption.css.body.height + "px" })
    }, [
      e.basicOption.css.header.show ? (r(), i("div", {
        key: 0,
        class: "table-header",
        style: u({
          "--header-background-image": `url(${e.basicOption.css.header.backgroundImage})`
        })
      }, [
        (r(!0), i(O, null, v(Object.keys(c.value[0]), (t, l) => (r(), i("div", {
          key: t,
          class: V(["th", { customWidth: !k(l + 1) }]),
          style: u({ "--width": C(l + 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: 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",
        style: u([{ color: "red" }, {
          "line-height": "36px"
        }])
      }, {
        default: T(() => [
          (r(!0), i(O, null, v(c.value, (t, l) => (r(), i("div", {
            key: t,
            class: "tr",
            style: u({
              "--row-hover": e.basicOption.css.hoverColor
            }),
            onClick: (n) => D(t, l),
            onMouseenter: (n) => F(t, l),
            onMouseout: (n) => L(t, l)
          }, [
            (r(!0), i(O, null, v(P(t), (n, a) => (r(), i("div", {
              key: n,
              class: V(["td", { customWidth: !k(a + 1) }]),
              style: u({ "--width": C(a + 1) + "px" }),
              onClick: (Y) => N(t, n, l, a)
            }, [
              $(a + 1) ? (r(), i("p", Q, w(n), 1)) : (r(), i("p", {
                key: 0,
                class: "customFont",
                style: u({
                  "--text-color": f(a + 1).color,
                  "--text-font-size": f(a + 1).fontSize + "px",
                  "--text-font-style": f(a + 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"])
    ], 4)) : E("", !0);
  }
});
export {
  te as default
};
