import { defineComponent as S, watch as m, withDirectives as F, createElementBlock as O, openBlock as R, withModifiers as r, normalizeStyle as B, unref as c, isRef as C, vModelDynamic as z, ref as v, onMounted as M } from "vue";
import { cloneDeep as y, isEqual as h } from "lodash";
import { nanoid as w } from "nanoid";
import { SHJDatasourceV2 as L } from "../../commons/core/datasource/index.mjs";
import { autoInstallFont as E, jsonToCssStyle as f } from "../../commons/utils/json2css.mjs";
const j = ["type", "placeholder"], q = S({ name: "zv-interaction-input" }), N = /* @__PURE__ */ S({
  ...q,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: ["on-blur", "on-focus", "on-input", "on-change"],
  setup(b, { expose: I, emit: k }) {
    const t = b, s = k, D = () => {
      const e = v(""), o = v(), i = (u) => {
        if (E(u.fontFamily), E(u.focus.fontFamily), o.value)
          return {
            ...f(u),
            ...f(u.focus, "focus"),
            ...f(u.placeholder, "placeholder")
          };
      }, p = v(), d = () => {
        L.parse({
          tId: t.uuid,
          sources: t.sources,
          callback: ({ data: u }) => {
            try {
              window.SHJParseEvent(t.useEvents, "dataListener", u), p.value = w(), e.value = u[0].data[0].value;
            } catch {
              window.SHJParseEvent(t.useEvents, "dataListener", null), p.value = w();
            }
          }
        });
      };
      return M(() => d()), {
        key: p,
        init: d,
        rendererDomStyle: i,
        inputRef: o,
        inputValue: e
      };
    }, { key: H, init: a, rendererDomStyle: J, inputRef: n, inputValue: l } = D(), V = (e) => {
      n.value && (s("on-blur", e, n.value.value), window.SHJParseEvent(t.useEvents, "on-blur", {
        data: n.value.value,
        event: e
      }));
    }, g = (e) => {
      n.value && (s("on-focus", e, n.value.value), window.SHJParseEvent(t.useEvents, "on-focus", {
        data: n.value.value,
        event: e
      }));
    }, P = (e) => {
      n.value && (s("on-input", e, n.value.value), window.SHJParseEvent(t.useEvents, "on-input", {
        data: n.value.value,
        event: e
      }));
    }, _ = (e) => {
      n.value && (s("on-change", e, n.value.value), window.SHJParseEvent(t.useEvents, "on-change", {
        data: n.value.value,
        event: e
      }));
    };
    return m(
      () => y(t.basicOption),
      (e, o) => {
        h(e, o) || a();
      },
      { deep: !0 }
    ), m(
      () => y(t.sources),
      (e, o) => {
        h(e, o) || a();
      },
      { deep: !0 }
    ), I({
      refresh: () => a(),
      refreshView: () => a(),
      refreshData: () => a()
    }), (e, o) => F((R(), O("input", {
      "onUpdate:modelValue": o[0] || (o[0] = (i) => C(l) ? l.value = i : null),
      key: c(H),
      ref_key: "inputRef",
      ref: n,
      type: e.basicOption.css.type || "text",
      class: "zerov-widget-input",
      placeholder: e.basicOption.placeholderValue,
      style: B(c(J)(e.basicOption.css)),
      onBlur: r(V, ["stop"]),
      onFocus: r(g, ["stop"]),
      onInput: r(P, ["stop"]),
      onChange: r(_, ["stop"])
    }, null, 44, j)), [
      [z, c(l)]
    ]);
  }
});
export {
  N as default
};
