import '@das-fed/ui/packages/components/radio/style.css';
import { defineComponent as K, reactive as Q, toRefs as X, ref as O, computed as c, watchEffect as Y, watch as Z, useSlots as x, onMounted as _, createElementBlock as u, openBlock as s, createBlock as b, createCommentVNode as t, unref as i, mergeProps as w, isRef as D, withCtx as m, renderSlot as q, normalizeClass as r, createVNode as $, Fragment as y, renderList as g, createTextVNode as V, toDisplayString as p, withDirectives as ee, normalizeStyle as ae } from "vue";
import { withInstall as le } from "@das-fed/utils/with-install/index";
import { Radio as A, RadioGroup as E, RadioButton as ie } from "ant-design-vue";
import "ant-design-vue/es/radio/style/css";
import { useModelValue as F } from "@das-fed/utils/vue";
import { vDasTooltip as oe } from "@das-fed/ui/packages/components/text-tooltip/index";
import { DasAutoRegisterIcon as se, DasIcon as I } from "@das-fed/ui/packages/components/icon/index";
import { setThemeRule as ue } from "@das-fed/web/packages/theme/index";
const de = {
  key: 0,
  class: "square-select-icon"
}, te = ["onClick", "onBlur", "tabindex"], re = {
  key: 0,
  class: "square-select-icon"
}, ne = {
  key: 1,
  class: "empty-text"
}, fe = ["onClick", "tabindex"], pe = /* @__PURE__ */ K({
  __name: "Index",
  props: {
    modelValue: { default: null },
    radioType: { default: "default" },
    disabled: { type: Boolean, default: !1 },
    optionType: { default: "default" },
    options: { default: () => [] },
    defaultProps: { default: () => ({
      value: "value",
      label: "label"
    }) },
    name: { default: "" },
    layout: { default: "default" },
    isView: { type: Boolean, default: !1 },
    width: {},
    maxWidth: {},
    isSetTimeout: { type: Boolean },
    noSetDefaultVal: { type: Boolean, default: !1 }
  },
  emits: ["change", "update:modelValue"],
  setup(U, { emit: L }) {
    se({
      select: import("@das-fed/ui/packages/icons/select")
    });
    const d = U, M = Q({
      radioValue: null,
      isFocus: !1
    });
    let { radioValue: l, isFocus: S } = X(M);
    const h = d.layout, v = L, W = O(null), G = c(() => d.noSetDefaultVal ? "" : "-");
    Y(() => {
      l.value = d.modelValue;
    }), Z([l], ([e]) => {
      v("update:modelValue", e);
    });
    const f = F(d, "defaultProps"), k = F(d, "options"), j = F(d, "isSetTimeout"), T = c(() => k.value.length ? k.value.map((e) => ({
      value: e[f.value.value],
      label: e[f.value.label],
      disabled: e.disabled,
      isFocus: !1
    })) : []), C = () => {
      j.value ? setTimeout(() => {
        v("change", l.value);
      }, 0) : v("change", l.value);
    }, R = c(() => {
      if (!d.isView) return [];
      if ((!k.value.length || l.value == "undefined") && d.radioType == "group") return [];
      if (d.radioType == "group")
        return k.value.filter((e) => l.value == e[f.value.value]);
      {
        if (l.value == "undefined") return [];
        const e = x();
        let o = null;
        return e && e.default && (o = e.default()[0].children), [
          {
            value: l.value,
            label: o
          }
        ];
      }
    }), H = d.disabled, B = (e, o) => {
      if (!H)
        if (e == "group") {
          if (o.disabled) return;
          l.value = o.value, o.isFocus = !0, v("change", l.value);
        } else
          l.value = !0, S.value = !0, v("change", l.value);
    }, z = (e, o) => {
      e == "group" ? o.isFocus = !1 : S.value = !1;
    }, N = c(() => d.maxWidth ? d.maxWidth : d.width), J = c(() => {
      if (d.maxWidth)
        return `max-width:${Number(String(N.value).split("px")[0])}px`;
      if (d.width)
        return `width:${Number(String(N.value).split("px")[0])}px`;
    });
    return _(() => {
      setTimeout(() => {
        var o;
        const e = (o = W.value) == null ? void 0 : o.querySelectorAll("input");
        e && e.length && e.forEach((a) => a.setAttribute("tabindex", "-1"));
      }, 1e3);
    }), (e, o) => (s(), u(
      "div",
      {
        class: "das-ui-radio",
        ref_key: "radioRef",
        ref: W
      },
      [
        e.radioType == "default" && e.optionType == "default" && !e.isView ? (s(), b(i(A), w({
          key: 0,
          disabled: e.disabled,
          checked: i(l),
          "onUpdate:checked": o[0] || (o[0] = (a) => D(l) ? l.value = a : l = a)
        }, e.$attrs, {
          optionType: e.optionType,
          onChange: C
        }), {
          default: m(() => [
            q(e.$slots, "default")
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["disabled", "checked", "optionType"])) : t("v-if", !0),
        e.radioType == "default" && e.optionType == "square" && !e.isView ? (s(), u(
          "div",
          {
            key: 1,
            class: r([
              "das-ui-radio-square",
              {
                "das-ui-radio-square--disabled": e.disabled,
                "das-ui-radio-square--checked": !!i(l),
                "das-ui-radio-square--focus": i(S)
              }
            ]),
            onClick: o[1] || (o[1] = (a) => B("default", "")),
            onBlur: o[2] || (o[2] = (a) => z("default", "")),
            tabindex: "0"
          },
          [
            i(l) ? (s(), u("span", de, [
              $(i(I), {
                size: "mini",
                icon: "select",
                iconColor: "#fff",
                class: "view-icon"
              })
            ])) : t("v-if", !0),
            q(e.$slots, "default")
          ],
          34
          /* CLASS, NEED_HYDRATION */
        )) : t("v-if", !0),
        e.radioType == "group" && e.optionType == "default" && !e.isView ? (s(), b(i(E), w({
          key: 2,
          class: { "das-ui-radio-vertical": i(h) == "vertical" },
          name: e.name,
          value: i(l),
          "onUpdate:value": o[3] || (o[3] = (a) => D(l) ? l.value = a : l = a)
        }, e.$attrs, {
          onChange: C,
          disabled: e.disabled
        }), {
          default: m(() => [
            (s(!0), u(
              y,
              null,
              g(T.value, (a) => (s(), b(i(A), {
                value: a.value,
                disabled: a.disabled,
                key: a.value
              }, {
                default: m(() => [
                  q(e.$slots, "default", { item: a }, () => [
                    V(
                      p(a.label),
                      1
                      /* TEXT */
                    )
                  ])
                ]),
                _: 2
                /* DYNAMIC */
              }, 1032, ["value", "disabled"]))),
              128
              /* KEYED_FRAGMENT */
            ))
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["class", "name", "value", "disabled"])) : t("v-if", !0),
        e.radioType == "group" && e.optionType == "button" ? (s(), b(i(E), w({
          key: 3,
          class: { "das-ui-radio-vertical": i(h) == "vertical" },
          name: e.name,
          disabled: e.disabled,
          value: i(l),
          "onUpdate:value": o[4] || (o[4] = (a) => D(l) ? l.value = a : l = a)
        }, e.$attrs, {
          buttonStyle: "solid",
          onChange: C
        }), {
          default: m(() => [
            (s(!0), u(
              y,
              null,
              g(T.value, (a) => (s(), b(i(ie), w({ ref_for: !0 }, e.$attrs, {
                value: a.value,
                disabled: a.disabled,
                key: a.value
              }), {
                default: m(() => [
                  q(e.$slots, "default", { item: a }, () => [
                    V(
                      p(a.label),
                      1
                      /* TEXT */
                    )
                  ])
                ]),
                _: 2
                /* DYNAMIC */
              }, 1040, ["value", "disabled"]))),
              128
              /* KEYED_FRAGMENT */
            ))
          ]),
          _: 3
          /* FORWARDED */
        }, 16, ["class", "name", "disabled", "value"])) : t("v-if", !0),
        e.radioType == "group" && e.optionType == "square" && !e.isView ? (s(), u(
          "div",
          {
            key: 4,
            class: r(["das-ui-radio-square-group", { "das-ui-radio-vertical": i(h) == "vertical" }])
          },
          [
            (s(!0), u(
              y,
              null,
              g(T.value, (a, n) => (s(), u("div", {
                class: r([
                  "das-ui-radio-square",
                  {
                    "das-ui-radio-square--disabled": a.disabled || e.disabled,
                    "das-ui-radio-square--checked": i(l) == a.value,
                    "das-ui-radio-square--focus": a.isFocus
                  }
                ]),
                onClick: (P) => B("group", a),
                onBlur: (P) => z("group", a),
                tabindex: n,
                key: n
              }, [
                i(l) ? (s(), u("span", re, [
                  $(i(I), {
                    size: "mini",
                    icon: "select",
                    iconColor: "#fff",
                    class: "view-icon"
                  })
                ])) : t("v-if", !0),
                V(
                  " " + p(a.label),
                  1
                  /* TEXT */
                )
              ], 42, te))),
              128
              /* KEYED_FRAGMENT */
            ))
          ],
          2
          /* CLASS */
        )) : t("v-if", !0),
        t("多选 查看状态 "),
        e.isView ? (s(), u(
          "div",
          {
            key: 5,
            class: r(["das-ui-radio-view-group", { "flex-view": R.value.length > 1 }])
          },
          [
            R.value.length ? (s(!0), u(
              y,
              { key: 0 },
              g(R.value, (a, n) => (s(), u(
                "div",
                {
                  class: r(["das-radio-item-view", a[i(f).label] && "nonelabel-item-view"]),
                  key: n
                },
                [
                  $(i(I), {
                    size: "mini",
                    icon: "select",
                    iconColor: "#666",
                    class: "view-icon"
                  }),
                  ee((s(), u(
                    "div",
                    {
                      class: r(["label", a[i(f).label] && "label-min-width"]),
                      style: ae([J.value, { color: "#666" }])
                    },
                    [
                      V(
                        p(a[i(f).label]),
                        1
                        /* TEXT */
                      )
                    ],
                    6
                    /* CLASS, STYLE */
                  )), [
                    [i(oe)]
                  ])
                ],
                2
                /* CLASS */
              ))),
              128
              /* KEYED_FRAGMENT */
            )) : (s(), u(
              "span",
              ne,
              p(G.value),
              1
              /* TEXT */
            ))
          ],
          2
          /* CLASS */
        )) : t("v-if", !0),
        t(" 用于过滤条件单选 "),
        e.radioType == "group" && e.optionType == "filterSquare" ? (s(), u(
          "div",
          {
            key: 6,
            class: r(["das-ui-radio-square-group das-ui-radio-filter-square-group", { "das-ui-radio-vertical": i(h) == "vertical" }])
          },
          [
            (s(!0), u(
              y,
              null,
              g(T.value, (a, n) => (s(), u("div", {
                class: r([
                  "das-ui-radio-square",
                  {
                    "das-ui-radio-square--disabled": a.disabled || e.disabled,
                    "das-ui-radio-square--checked": i(l) == a.value
                  }
                ]),
                onClick: (P) => B("group", a),
                tabindex: n,
                key: n
              }, p(a.label), 11, fe))),
              128
              /* KEYED_FRAGMENT */
            ))
          ],
          2
          /* CLASS */
        )) : t("v-if", !0)
      ],
      512
      /* NEED_PATCH */
    ));
  }
}), ve = {
  "--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)",
  "--das-ui-radio-filter-bgcolor": "#fff"
};
ue(ve);
const qe = () => O(null), Ve = le(pe);
export {
  Ve as DasRadio,
  qe as DasRadioRef,
  Ve as default
};
