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