/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-c89aafbb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { omit } from '../utils/helper.js';
import { renderContent } from '../utils/render-tnode.js';
import { emitEvent } from '../utils/event.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import props from './props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '@babel/runtime/helpers/typeof';
import '@vue/composition-api';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = getClassPrefixMixins("radio");
var _Radio = mixins(Vue, classPrefixMixins).extend({
  name: "TRadio",
  inheritAttrs: false,
  props: _objectSpread({}, props),
  inject: {
    radioGroup: {
      "default": void 0
    },
    radioButton: {
      "default": void 0
    }
  },
  data: function data() {
    return {
      formDisabled: void 0
    };
  },
  render: function render() {
    var _ref, _this$radioGroup, _this$value;
    var h = arguments[0];
    var radioGroup = this.radioGroup,
      radioButton = this.radioButton;
    var tChecked = this.getChecked();
    var tDisabled = this.getDisabled();
    var prefixCls = radioButton ? "".concat(this.componentName, "-button") : this.componentName;
    var inputClass = ["".concat(prefixCls), (_ref = {}, _defineProperty(_ref, this.commonStatusClassName.checked, tChecked), _defineProperty(_ref, this.commonStatusClassName.disabled, tDisabled), _ref)];
    var allowUncheck = this.allowUncheck || ((_this$radioGroup = this.radioGroup) === null || _this$radioGroup === void 0 ? void 0 : _this$radioGroup.allowUncheck);
    return h("label", {
      "class": inputClass,
      "on": {
        "click": this.handleRadioClick
      },
      "attrs": {
        "tabindex": tDisabled ? void 0 : "0"
      }
    }, [h("input", helper([{
      "attrs": {
        "type": "radio",
        "name": this.name || (radioGroup === null || radioGroup === void 0 ? void 0 : radioGroup.name) || void 0,
        "disabled": tDisabled,
        "tabindex": "-1",
        "data-value": typeof this.value === "string" ? "'".concat(this.value, "'") : this.value,
        "data-allow-uncheck": allowUncheck || void 0
      },
      "class": "".concat(prefixCls, "__former"),
      "domProps": {
        "value": (_this$value = this.value) !== null && _this$value !== void 0 ? _this$value : void 0,
        "checked": tChecked
      },
      "on": {
        "click": this.onInputClick
      }
    }, {
      "on": _objectSpread({}, omit(this.$listeners, ["change", "click"]))
    }])), h("span", {
      "class": "".concat(prefixCls, "__input")
    }), h("span", {
      "class": "".concat(prefixCls, "__label")
    }, [renderContent(this, "default", "label")])]);
  },
  methods: {
    getChecked: function getChecked() {
      var _this$radioGroup2;
      return this.checked || this.value !== void 0 && ((_this$radioGroup2 = this.radioGroup) === null || _this$radioGroup2 === void 0 ? void 0 : _this$radioGroup2.value) === this.value;
    },
    getDisabled: function getDisabled() {
      var _ref2, _this$radioGroup3;
      return Boolean((_ref2 = this.formDisabled || this.disabled) !== null && _ref2 !== void 0 ? _ref2 : (_this$radioGroup3 = this.radioGroup) === null || _this$radioGroup3 === void 0 ? void 0 : _this$radioGroup3.disabled);
    },
    onInputClick: function onInputClick(e) {
      e.stopPropagation();
    },
    handleRadioClick: function handleRadioClick(e) {
      var tDisabled = this.getDisabled();
      if (tDisabled) return;
      this.$emit("click", {
        e: e
      });
      this.checkRadio(e);
    },
    checkRadio: function checkRadio(e) {
      var _this$radioGroup4;
      var tChecked = this.getChecked();
      var allowUncheck = this.allowUncheck || ((_this$radioGroup4 = this.radioGroup) === null || _this$radioGroup4 === void 0 ? void 0 : _this$radioGroup4.allowUncheck);
      if (this.radioGroup) {
        var value = tChecked && allowUncheck ? void 0 : this.value;
        this.radioGroup.handleRadioChange(value, {
          e: e
        });
      } else {
        var _value = allowUncheck ? !tChecked : true;
        emitEvent(this, "change", _value, {
          e: e
        });
      }
    }
  }
});

export { _Radio as default };
//# sourceMappingURL=radio.js.map
