import { defineComponent as j, ref as f, computed as ee, onMounted as te, watch as E, withDirectives as oe, createElementBlock as s, openBlock as d, normalizeClass as x, unref as o, createElementVNode as u, createVNode as re, normalizeStyle as h, createCommentVNode as b, toDisplayString as O, Transition as ne, withCtx as ae, Fragment as le, renderList as ie, withModifiers as ce } from "vue";
import { nanoid as F } from "nanoid";
import { cloneDeep as I, isEqual as V } from "lodash";
import { jsonToCssStyle as r, autoInstallFont as v } from "../../commons/utils/json2css.mjs";
import se from "../../commons/utils/clickOutSide.mjs";
import { SHJDatasourceV2 as de } from "../../commons/core/datasource/index.mjs";
const ue = { style: { display: "flex", "align-items": "center", gap: "4px" } }, pe = {
  key: 1,
  class: "zerov-widget-select__prefix"
}, fe = ["src"], ve = ["src"], me = ["onClick"], he = ["src"], Se = { class: "zerov-widget-select__option-label" }, be = j({ name: "zv-interaction-select" }), Oe = /* @__PURE__ */ j({
  ...be,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: ["update:modelValue", "on-change"],
  setup(B, { expose: H, emit: J }) {
    const p = B, L = () => {
      const t = f(), c = (e) => {
        if (t.value) {
          v(e.fontFamily), v(e.hover.fontFamily), v(e.focus.fontFamily);
          const n = f("");
          return e.boxShadow && (n.value = `${e.boxShadow.isInset ? "inset" : ""} ${e.boxShadow.offsetX}px ${e.boxShadow.offsetY}px ${e.boxShadow.blur}px ${e.boxShadow.diffus}px ${e.boxShadow.color}`), {
            ...r(e),
            ...r(e.hover, "hover"),
            ...r(e.focus, "focus"),
            boxShadow: n.value,
            padding: `${e.padding.map((a) => `${a}px`).join(" ")}`,
            background: e.isBgImage ? `no-repeat center/100% url(${e.backgroundImage})` : e.backgroundColor
          };
        }
        return {};
      }, l = (e) => {
        if (t.value) {
          v(e.fontFamily);
          const n = `${e.boxShadow.isInset ? "inset" : ""} ${e.boxShadow.offsetX}px ${e.boxShadow.offsetY}px ${e.boxShadow.blur}px ${e.boxShadow.diffus}px ${e.boxShadow.color}`;
          return e.placement === "bottom" ? {
            ...r(e),
            top: "100%",
            marginTop: "6px",
            boxShadow: n,
            padding: `${e.padding.map((a) => `${a}px`).join(" ")}`
          } : {
            ...r(e),
            bottom: "100%",
            marginBottom: "6px",
            boxShadow: n,
            padding: `${e.padding.map((a) => `${a}px`).join(" ")}`
          };
        }
      }, D = (e) => {
        if (t.value)
          return v(e.fontFamily), {
            padding: `${e.padding.map((n) => `${n}px`).join(" ")}`,
            ...r(e),
            ...r(e.hover, "hover"),
            ...r(e.active, "active")
          };
      }, U = (e) => {
        if (t.value)
          return v(e.fontFamily), {
            ...r(e)
          };
      }, W = (e) => {
        if (t.value)
          return v(e.fontFamily), {
            ...r(e),
            ...r(e, "hover"),
            ...r(e, "focus")
          };
      }, Z = (e, n) => {
        const a = n.find((k) => k.type === e);
        return a ? a.url : "";
      }, C = (e, n) => {
        if (t.value) {
          const a = n.find((k) => k.type === e);
          if (a)
            return {
              ...r(a)
            };
        }
      }, $ = f(), S = f([]);
      return {
        key: $,
        init: () => {
          de.parse({
            tId: p.uuid,
            sources: p.sources,
            callback: (e) => {
              try {
                window.SHJParseEvent(p.useEvents, "dataListener", S), $.value = F(), e && e.data ? S.value = I(e.data[0].data) : S.value = [];
              } catch {
                window.SHJParseEvent(p.useEvents, "dataListener", null), $.value = F(), S.value = [];
              }
            }
          });
        },
        options: S,
        selectRef: t,
        rendererSelectInput: c,
        rendererSelectOption: D,
        rendererSelectDropdown: l,
        rendererSelectSelected: W,
        rendererSelectPlaceholder: U,
        rendererPrefixIcon: Z,
        rendererPrefixIconCss: C
      };
    }, y = f(""), z = J, i = f(!1), w = ee(() => {
      const t = P.value.find((c) => c.value === y.value);
      return t ? t.label : "";
    }), R = () => {
      i.value = !i.value;
    }, _ = f(""), T = (t) => {
      y.value = t.value, _.value = t.type, z("update:modelValue", t.value), z("on-change", t), window.SHJParseEvent(p.useEvents, "on-change", {
        data: t
      }), i.value = !1;
    }, N = () => {
      i.value = !1;
    }, {
      key: M,
      init: m,
      options: P,
      selectRef: X,
      rendererSelectInput: Y,
      rendererSelectOption: q,
      rendererSelectDropdown: A,
      rendererSelectSelected: G,
      rendererSelectPlaceholder: K,
      rendererPrefixIcon: g,
      rendererPrefixIconCss: Q
    } = L();
    return te(() => m()), E(
      () => I(p.basicOption),
      (t, c) => {
        V(t, c) || m();
      },
      { deep: !0 }
    ), E(
      () => I(p.sources),
      (t, c) => {
        V(t, c) || m();
      },
      { deep: !0 }
    ), H({
      refresh: () => m(),
      refreshView: () => m(),
      refreshData: () => m()
    }), (t, c) => oe((d(), s("div", {
      key: o(M),
      ref_key: "selectRef",
      ref: X,
      class: x(["zerov-widget-select", { "is-open": i.value }]),
      onClick: R
    }, [
      u("div", {
        class: x(["zerov-widget-select__trigger", { "is-active": i.value }]),
        style: h({
          ...o(Y)(t.basicOption.input)
        })
      }, [
        u("div", ue, [
          w.value ? b("", !0) : (d(), s("span", {
            key: 0,
            class: "zerov-widget-select__placeholder",
            style: h({
              ...o(K)(t.basicOption.input.placeholder)
            })
          }, O(t.basicOption.input.placeholder.value), 5)),
          w.value && o(g)(_.value, t.basicOption.dropdown.option.prefixs) ? (d(), s("span", pe, [
            u("img", {
              src: o(g)(_.value, t.basicOption.dropdown.option.prefixs),
              alt: ""
            }, null, 8, fe)
          ])) : b("", !0),
          w.value ? (d(), s("span", {
            key: 2,
            class: "zerov-widget-select__selected",
            style: h({
              ...o(G)(t.basicOption.input.selected)
            })
          }, O(w.value), 5)) : b("", !0)
        ]),
        u("span", {
          class: x(["zerov-widget-select__arrow", { "is-open": i.value }])
        }, [
          u("img", {
            src: t.basicOption.input.arrow.url,
            alt: ""
          }, null, 8, ve)
        ], 2)
      ], 6),
      re(ne, { name: "fade-in-linear" }, {
        default: ae(() => [
          i.value ? (d(), s("div", {
            key: 0,
            class: "zerov-widget-select__dropdown",
            style: h({
              ...o(A)(t.basicOption.dropdown)
            })
          }, [
            u("ul", null, [
              (d(!0), s(le, null, ie(o(P), (l) => (d(), s("li", {
                key: l.value,
                class: x([{ "is-selected": l.value === y.value }, "zerov-widget-select__option"]),
                style: h({
                  ...o(q)(t.basicOption.dropdown.option)
                }),
                onClick: ce((D) => T(l), ["stop"])
              }, [
                o(g)(l.type, t.basicOption.dropdown.option.prefixs) ? (d(), s("span", {
                  key: 0,
                  class: "zerov-widget-select__option-prefix",
                  style: h({
                    ...o(Q)(l.type, t.basicOption.dropdown.option.prefixs)
                  })
                }, [
                  u("img", {
                    src: o(g)(l.type, t.basicOption.dropdown.option.prefixs),
                    alt: ""
                  }, null, 8, he)
                ], 4)) : b("", !0),
                u("span", Se, O(l.label), 1)
              ], 14, me))), 128))
            ])
          ], 4)) : b("", !0)
        ]),
        _: 1
      })
    ], 2)), [
      [o(se), N]
    ]);
  }
});
export {
  Oe as default
};
