import { defineComponent as j, ref as S, computed as w, watch as x, onMounted as K, nextTick as v, resolveDirective as z, openBlock as u, createElementBlock as r, normalizeClass as f, Fragment as b, renderList as R, normalizeStyle as P, createElementVNode as g, renderSlot as G, withDirectives as B, createTextVNode as H, toDisplayString as O, createCommentVNode as D } from "vue";
/* empty css                       */
import { C as i } from "../Shared/base-PQGakkrl.js";
import { tooltipDirectives as Q } from "../Web/__directive__/Tooltip.js";
const U = ["id", "name", "value", "disabled", "checked", "onClick"], W = ["for"], ne = /* @__PURE__ */ j({
  name: "ClCheckbox",
  directives: {
    cltooltip: Q
  },
  __name: "Index",
  props: {
    value: {
      type: String,
      required: !0
    },
    className: {
      type: String,
      default: ""
    },
    name: {
      type: String,
      required: !0
    },
    list: {
      type: Array,
      default: () => []
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    width: {
      type: String,
      default: ""
    },
    isInline: {
      type: Boolean,
      default: !0
    },
    checkChangeBefore: {
      type: Function,
      default: void 0
    }
  },
  emits: ["update:value", "onChange", "onInit"],
  setup(d, { expose: $, emit: A }) {
    const a = d, y = A, k = `cb-${i.getRandom(8)}`, n = S(i.isEmpty(a.value) ? [] : a.value.split(",")), o = S(!1);
    let p = {};
    const C = {
      lastValue: []
    }, J = w(() => {
      const e = a.className, t = {
        "panel-checkbox": !0
      };
      return e && !i.isEmpty(e) && e.split(" ").forEach((s) => {
        i.isEmpty(s) || (t[s] = !0);
      }), t;
    }), N = w(() => {
      const e = {
        checkbox: !0,
        "checkbox-default": !0
      };
      return e["checkbox-inline"] = a.isInline ?? !0, e;
    }), F = (e) => {
      const t = {
        "checkbox-icon-tip": !0
      };
      return i.isEmpty(e.tipIcon) ? t["clIconFont clIcon-question-circle"] = !0 : t[e.tipIcon] = !0, t;
    }, M = (e) => {
      const t = {}, { width: s } = a;
      return e && !i.isEmpty(e.width) ? t.width = e.width : i.isEmpty(s) || (t.width = a.width), t;
    }, I = (e) => {
      y("update:value", e);
    }, T = (e) => {
      const t = [];
      i.isEmpty(e) || e.split(",").forEach((l) => {
        i.isExistJsonKey(p, l) && t.push(i.getJsonClone(p[l]));
      });
      const s = t.length > 0 && t.length === a.list.length;
      I(e), y("onChange", e, t, s);
    }, h = () => {
      v(() => {
        y("onInit");
      });
    }, _ = () => {
      const e = [];
      return n.value.forEach((t) => {
        i.isExistJsonKey(p, t) && e.push(t);
      }), e;
    }, E = (e) => {
      p = i.isEmpty(e) ? {} : i.getJsonByList(e);
    }, m = () => {
      if (o.value && !i.isEmpty(n.value)) {
        const e = _();
        i.isEqualArr(n.value, e) || (n.value = e, I(e.join(",")));
      }
    }, V = (e) => {
      const t = e.split(",");
      let s = i.isEqualArr(n.value, t);
      s && (s = e === n.value.join(",")), s || (n.value = t);
    }, q = () => {
      o.value = a.list.length !== 0, E(a.list), m(), C.lastValue = i.getArrClone(n.value);
    };
    x(o, (e) => {
      e && h();
    }), x(
      () => a.list,
      (e) => {
        o.value || (o.value = !0, e.length === 0 && m(), h());
      }
    ), x(
      [() => a.value, () => a.list],
      ([e, t]) => {
        const s = t;
        !o.value && s.length > 0 && (o.value = !0, h()), E(s), e !== a.value && V(e), m();
      }
    ), K(() => {
      v(() => {
        q();
      });
    });
    const L = async (e) => {
      if (!e.isDisabled && !a.disabled) {
        const t = e.id.toString();
        let s = i.getArrClone(n.value);
        i.isExistValue(n.value, t) ? s = i.getArrRemoveById(s, t) : s.push(t);
        const l = s.join(",");
        let c = !0;
        a.checkChangeBefore && (c = await a.checkChangeBefore(l), c = i.isBoolean(c) ? c : !0), c ? (n.value = s, C.lastValue = s, T(l)) : v(() => {
          n.value = s, v(() => {
            n.value = C.lastValue;
          });
        });
      }
    };
    return $({
      getValue: () => _().join(","),
      getValueData: () => {
        const e = [];
        return n.value.forEach((t) => {
          i.isExistJsonKey(p, t) && e.push(i.getJsonClone(p[t]));
        }), e;
      },
      setValue: (e) => {
        V(e), m();
      },
      runInitComplete: () => {
        o.value || (o.value = !0, E(a.list), V(a.value), m(), h());
      }
    }), (e, t) => {
      const s = z("cltooltip");
      return u(), r("div", {
        class: f(J.value)
      }, [
        (u(!0), r(b, null, R(d.list, (l, c) => (u(), r(b, {
          key: `${k}-${c}`
        }, [
          l.isShow || l.isShow === void 0 ? (u(), r("div", {
            key: 0,
            class: f(N.value),
            style: P(M(l))
          }, [
            g("span", null, [
              g("span", null, [
                g("input", {
                  type: "checkbox",
                  id: `${k}_${d.name}_${l.id}`,
                  name: d.name,
                  value: l.id,
                  disabled: l.isDisabled || d.disabled,
                  checked: n.value.includes(l.id.toString()),
                  onClick: (te) => L(l)
                }, null, 8, U),
                g("label", {
                  for: `${k}_${d.name}_${l.id}`
                }, [
                  G(e.$slots, "default", { data: l }, () => [
                    l.icon && l.icon.length > 0 ? B((u(), r("i", {
                      key: 0,
                      class: f(l.icon)
                    }, null, 2)), [
                      [s, { html: l.name, className: "tooltip-modal" }]
                    ]) : (u(), r(b, { key: 1 }, [
                      H(O(l.name), 1)
                    ], 64))
                  ])
                ], 8, W)
              ]),
              l.tipMsg && l.tipMsg.length > 0 ? B((u(), r("i", {
                key: 0,
                class: f(F(l))
              }, null, 2)), [
                [s, { html: l.tipMsg, className: "tooltip-modal" }]
              ]) : D("", !0)
            ])
          ], 6)) : D("", !0)
        ], 64))), 128))
      ], 2);
    };
  }
});
export {
  ne as default
};
//# sourceMappingURL=ClCheckbox.js.map
