import '@das-fed/upf-ui/packages/components/checkbox/style.css';
import { defineComponent as le, computed as k, reactive as ae, toRefs as te, watchEffect as ue, watch as oe, useSlots as ce, ref as Q, onMounted as se, openBlock as u, createElementBlock as s, normalizeStyle as p, createBlock as W, unref as i, mergeProps as U, isRef as A, withCtx as M, withDirectives as g, renderSlot as C, createCommentVNode as r, normalizeClass as f, Fragment as $, renderList as S, createElementVNode as j, createTextVNode as N, toDisplayString as x, createVNode as G } from "vue";
import { withInstall as ie } from "@das-fed/upf-utils/with-install/index";
import { CheckboxGroup as de } from "ant-design-vue/es";
import "ant-design-vue/es/checkbox/style/css";
import { Checkbox as H } from "ant-design-vue";
import { DasAutoRegisterIcon as ne, DasIcon as J } from "@das-fed/upf-ui/packages/components/icon/index";
import { vDasTooltip as T } from "@das-fed/upf-ui/packages/components/text-tooltip/index";
import { useModelValue as K } from "@das-fed/upf-utils/vue";
const re = { class: "label" }, fe = ["onClick", "onBlur", "tabindex"], he = {
  key: 0,
  class: "square-select-icon"
}, be = {
  key: 1,
  class: "empty-text"
}, ve = ["onClick", "tabindex"], ke = {
  key: 6,
  class: "das-checkbox-error-label-content"
}, xe = {
  key: 0,
  class: "das-input-error-label"
}, me = {
  key: 7,
  class: "das-checkbox-overlay-error-label-content"
}, ye = { class: "label" }, pe = /* @__PURE__ */ le({
  __name: "Index",
  props: {
    modelValue: { default: null },
    checkboxType: { default: "default" },
    disabled: { type: Boolean, default: !1 },
    optionType: { default: "default" },
    options: { default: () => [] },
    defaultProps: { default: () => ({
      value: "value",
      label: "label"
    }) },
    name: { default: "" },
    layout: { default: "default" },
    indeterminate: { type: Boolean, default: !1 },
    isView: { type: Boolean, default: !1 },
    width: { default: "" },
    maxWidth: { default: "" },
    size: { default: "small" },
    error: { type: Boolean, default: !1 },
    errorLabel: { default: "" },
    teleported: { type: Boolean, default: !0 },
    errorMode: { default: "default" },
    isErrorTitle: { type: Boolean, default: !1 },
    noSetDefaultVal: { type: Boolean, default: !1 },
    formSize: {}
  },
  emits: ["change", "update:modelValue", "update:indeterminate"],
  setup(l, { emit: z }) {
    ne({
      select: import("@das-fed/upf-ui/packages/icons/select")
    });
    const o = l, B = k(() => o.noSetDefaultVal ? "" : "-"), D = ae({
      checkboxValue: null,
      isFocus: !1,
      checkboxLayout: "",
      checkboxIndeterminate: !1
    });
    let { checkboxValue: c, isFocus: I, checkboxIndeterminate: m } = te(D);
    const L = o.layout, y = z;
    ue(() => {
      c.value = o.modelValue, m.value = o.indeterminate, o.checkboxType == "default" && o.optionType == "default" && o.modelValue && (m.value = !1);
    }), oe(c, (a) => {
      y("update:modelValue", a);
    });
    const h = K(o, "defaultProps"), V = K(o, "options"), b = k(() => V.value.length ? V.value.map((a) => {
      var t;
      return {
        value: a[h.value.value],
        label: a[h.value.label],
        disabled: a.disabled,
        isFocus: !1,
        checked: (t = o.modelValue) == null ? void 0 : t.includes(a[h.value.value]),
        mutual: a.mutual
      };
    }) : []), O = () => {
      m && (m.value = !1, y("update:indeterminate", m.value), y("update:modelValue", c.value)), y("change", c.value);
    }, X = o.disabled, Y = b.value.some((a) => !!a.mutual), E = (a, t) => {
      if (!X)
        if (a == "group") {
          if (t.disabled) return;
          Y ? t.mutual ? (b.value.forEach((d) => {
            d.checked = !1;
          }), t.checked = !0) : (t.checked = !t.checked, b.value.forEach((d) => {
            d.mutual && (d.checked = !b.value.some((e) => e.checked));
          })) : t.checked = !t.checked, t.isFocus = !0, c.value = b.value.filter((d) => d.checked).map((d) => d.value), y("change", c.value);
        } else
          c.value = !c.value, I.value = !0, y("change", c.value);
    }, F = k(() => {
      var a, t, d;
      if (!o.isView) return [];
      if ((!((a = V.value) != null && a.length) || !((t = c.value) != null && t.length)) && o.checkboxType == "group") return [];
      if (o.checkboxType == "group")
        return V.value.filter((e) => {
          if (c.value.includes(e[h.value.value]))
            return e;
        });
      {
        if (!c.value) return [];
        const e = ce();
        let n = null;
        return e && e.default && ((d = e.default()) == null ? void 0 : d.length) == 0 && (n = e.default()[0].children), [
          {
            value: c.value,
            label: n
          }
        ];
      }
    }), P = (a, t) => {
      a == "group" ? t.isFocus = !1 : I.value = !1;
    }, Z = k(() => o.maxWidth ? o.maxWidth : o.width), v = k(() => {
      let a = `${Number(String(Z.value).split("px")[0])}`;
      if (o.maxWidth)
        return `max-width:${a}px`;
      if (o.width)
        return Number(a) > 72 && o.maxWidth ? `width:${a};max-width:${a}px;` : `width:${a}px`;
    }), R = Q(null), _ = () => {
      setTimeout(() => {
        var t, d;
        const a = (d = (t = R.value) == null ? void 0 : t.$el) == null ? void 0 : d.querySelectorAll(".ant-checkbox-input");
        a && a.length && a.forEach((e) => e.setAttribute("tabindex", "-1"));
      }, 1e3);
    }, q = k(() => o.formSize), ee = k(() => ({
      "--checkbox-height": q.value && {
        small: "24px",
        default: "32px",
        large: "40px"
      }[q.value],
      "--checkbox-font-size": q.value && {
        small: "12px",
        default: "14px",
        large: "14px"
      }[q.value]
    }));
    return se(_), (a, t) => {
      const d = de;
      return u(), s(
        "div",
        {
          class: "das-ui-checkbox",
          style: p(ee.value)
        },
        [
          l.checkboxType == "default" && l.optionType == "default" && !l.isView ? (u(), W(i(H), U({
            key: 0,
            ref_key: "checkboxRef",
            ref: R,
            checked: i(c),
            "onUpdate:checked": t[0] || (t[0] = (e) => A(c) ? c.value = e : c = e),
            disabled: l.disabled
          }, a.$attrs, {
            optionType: l.optionType,
            indeterminate: i(m),
            onChange: O,
            class: [l.size, { nolabel: Object.keys(a.$slots).length == 0 }]
          }), {
            default: M(() => [
              g((u(), s(
                "div",
                {
                  class: "label",
                  style: p([v.value, { color: "#666" }])
                },
                [
                  C(a.$slots, "default", {}, void 0, !0)
                ],
                4
                /* STYLE */
              )), [
                [i(T)]
              ])
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["checked", "disabled", "optionType", "indeterminate", "class"])) : r("v-if", !0),
          l.checkboxType == "default" && l.optionType == "square" && !l.isView ? (u(), s(
            "div",
            {
              key: 1,
              class: f([
                "das-ui-checkbox-square",
                l.size,
                {
                  "das-ui-checkbox-square--disabled": l.disabled,
                  "das-ui-checkbox-square--checked": !!i(c),
                  "das-ui-checkbox-square--focus": i(I),
                  "ellipsis-square-checkbox": !!v.value
                }
              ]),
              tabindex: "0",
              onClick: t[1] || (t[1] = (e) => E("default", "")),
              onBlur: t[2] || (t[2] = (e) => P("default", "")),
              style: p(v.value)
            },
            [
              g((u(), s("div", re, [
                C(a.$slots, "default", {}, void 0, !0)
              ])), [
                [i(T)]
              ])
            ],
            38
            /* CLASS, STYLE, NEED_HYDRATION */
          )) : r("v-if", !0),
          l.checkboxType == "group" && l.optionType == "default" && !l.isView ? (u(), W(d, U({
            key: 2,
            ref_key: "checkboxRef",
            ref: R
          }, a.$attrs, {
            class: [l.size, { "das-ui-checkbox-vertical": i(L) == "vertical" }],
            value: i(c),
            "onUpdate:value": t[3] || (t[3] = (e) => A(c) ? c.value = e : c = e),
            name: l.name,
            onChange: O
          }), {
            default: M(() => [
              (u(!0), s(
                $,
                null,
                S(b.value, (e, n) => (u(), W(i(H), {
                  key: n,
                  value: e.value,
                  "onUpdate:value": (w) => e.value = w,
                  disabled: e.disabled || l.disabled
                }, {
                  default: M(() => [
                    j(
                      "div",
                      {
                        class: f(["label", { "label-min-width": !!v.value }]),
                        style: p([v.value, { color: "#666" }])
                      },
                      [
                        C(a.$slots, "content", {
                          item: e,
                          index: n
                        }, () => [
                          g((u(), s("div", null, [
                            N(
                              x(e.label),
                              1
                              /* TEXT */
                            )
                          ])), [
                            [i(T)]
                          ])
                        ], !0)
                      ],
                      6
                      /* CLASS, STYLE */
                    )
                  ]),
                  _: 2
                  /* DYNAMIC */
                }, 1032, ["value", "onUpdate:value", "disabled"]))),
                128
                /* KEYED_FRAGMENT */
              ))
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["class", "value", "name"])) : r("v-if", !0),
          l.checkboxType == "group" && l.optionType == "square" && !l.isView ? (u(), s(
            "div",
            {
              key: 3,
              class: f(["das-ui-checkbox-square-group", [l.size, { "das-ui-checkbox-vertical": i(L) == "vertical" }]])
            },
            [
              (u(!0), s(
                $,
                null,
                S(b.value, (e, n) => (u(), s("div", {
                  class: f([
                    "das-ui-checkbox-square",
                    {
                      "das-ui-checkbox-square--disabled": e.disabled || l.disabled,
                      "das-ui-checkbox-square--checked": e.checked,
                      "das-ui-checkbox-square--focus": e.isFocus,
                      "ellipsis-square-checkbox": !!v.value
                    }
                  ]),
                  style: p(v.value),
                  onClick: (w) => E("group", e),
                  onBlur: (w) => P("group", e),
                  tabindex: n,
                  key: n
                }, [
                  e.checked ? (u(), s("span", he, [
                    G(i(J), {
                      size: "mini",
                      icon: "select",
                      iconColor: "#fff",
                      class: "view-icon"
                    })
                  ])) : r("v-if", !0),
                  g((u(), s("div", null, [
                    N(
                      x(e.label),
                      1
                      /* TEXT */
                    )
                  ])), [
                    [i(T)]
                  ])
                ], 46, fe))),
                128
                /* KEYED_FRAGMENT */
              ))
            ],
            2
            /* CLASS */
          )) : r("v-if", !0),
          r("多选组 查看状态 "),
          l.isView ? (u(), s(
            "div",
            {
              key: 4,
              class: f(["das-ui-checkbox-view-group", { "flex-view": F.value.length > 1 }])
            },
            [
              F.value.length ? (u(!0), s(
                $,
                { key: 0 },
                S(F.value, (e, n) => (u(), s(
                  "div",
                  {
                    class: f(["das-checkbox-item-view", e[i(h).label] && "nonelabel-item-view"]),
                    key: n
                  },
                  [
                    G(i(J), {
                      size: "mini",
                      icon: "select",
                      iconColor: "#666",
                      class: f(["view-icon", { "m-r-5": e[i(h).label] || Object.keys(a.$slots).length > 0 }])
                    }, null, 8, ["class"]),
                    e[i(h).label] ? g((u(), s(
                      "div",
                      {
                        key: 0,
                        class: f(["label", l.size]),
                        style: p([v.value, { color: "#666" }])
                      },
                      [
                        N(
                          x(e[i(h).label]),
                          1
                          /* TEXT */
                        )
                      ],
                      6
                      /* CLASS, STYLE */
                    )), [
                      [i(T)]
                    ]) : C(a.$slots, "default", { key: 1 }, void 0, !0)
                  ],
                  2
                  /* CLASS */
                ))),
                128
                /* KEYED_FRAGMENT */
              )) : (u(), s(
                "span",
                be,
                x(B.value),
                1
                /* TEXT */
              ))
            ],
            2
            /* CLASS */
          )) : r("v-if", !0),
          r(" 用于过滤条件的多选 "),
          l.checkboxType == "group" && l.optionType == "filterSquare" ? (u(), s(
            "div",
            {
              key: 5,
              class: f(["das-ui-checkbox-square-group das-ui-checkbox-filter-square-group", { "das-ui-checkbox-vertical": i(L) == "vertical" }])
            },
            [
              (u(!0), s(
                $,
                null,
                S(b.value, (e, n) => (u(), s("div", {
                  class: f([
                    "das-ui-checkbox-square",
                    {
                      "das-ui-checkbox-square--disabled": e.disabled || l.disabled,
                      "das-ui-checkbox-square--checked": e.checked
                    }
                  ]),
                  onClick: (w) => E("group", e),
                  tabindex: n,
                  key: n
                }, x(e.label), 11, ve))),
                128
                /* KEYED_FRAGMENT */
              ))
            ],
            2
            /* CLASS */
          )) : r("v-if", !0),
          l.error && l.errorLabel && l.errorMode === "default" ? (u(), s("div", ke, [
            l.error ? (u(), s(
              "span",
              xe,
              x(l.errorLabel),
              1
              /* TEXT */
            )) : r("v-if", !0)
          ])) : r("v-if", !0),
          l.error && l.errorLabel && l.errorMode === "overlay" ? (u(), s("div", me, [
            j(
              "span",
              ye,
              x(l.errorLabel),
              1
              /* TEXT */
            )
          ])) : r("v-if", !0)
        ],
        4
        /* STYLE */
      );
    };
  }
}), ge = (l, z) => {
  const o = l.__vccOpts || l;
  for (const [B, D] of z)
    o[B] = D;
  return o;
}, Te = /* @__PURE__ */ ge(pe, [["__scopeId", "data-v-260192ae"]]), De = () => Q(null), Ie = ie(Te);
export {
  Ie as DasCheckbox,
  De as DasCheckboxRef,
  Ie as default
};
