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