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