/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var helper = require('../../chunks/helper.js');
var Vue = require('vue');
var utils_helper = require('../../utils/helper.js');
var utils_renderNode = require('../../utils/render-node.js');
var utils_event = require('../../utils/event.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_radio_props = require('./props.js');
require('lodash/camelCase');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("radio");
var _Radio = utils_mixins["default"](Vue__default["default"], classPrefixMixins).extend({
  name: "LRadio",
  inheritAttrs: false,
  props: {
    ...components_radio_props.RadioProps
  },
  inject: {
    radioGroup: {
      default: void 0
    },
    radioButton: {
      default: void 0
    }
  },
  data() {
    return {
      formDisabled: void 0
    };
  },
  computed: {
    tDisabled() {
      return this.formDisabled || this.disabled;
    }
  },
  render() {
    const h = arguments[0];
    const {
      radioGroup,
      radioButton
    } = this;
    const inputProps = {
      checked: this.checked,
      disabled: this.tDisabled,
      value: this.value,
      name: this.name
    };
    if (radioGroup) {
      inputProps.checked = this.value === radioGroup.value;
      inputProps.disabled = this.tDisabled === void 0 ? radioGroup.disabled : this.tDisabled;
      inputProps.name = radioGroup.name;
    }
    const prefixCls = radioButton ? `${this.componentName}-button` : this.componentName;
    const inputClass = [`${prefixCls}`, {
      [this.commonStatusClassName.checked]: inputProps.checked,
      [this.commonStatusClassName.disabled]: inputProps.disabled
    }];
    return h("label", {
      "class": inputClass
    }, [h("input", helper.helper([{
      "attrs": {
        "type": "radio"
      },
      "class": `${prefixCls}__former`
    }, {
      "on": {
        ...utils_helper.omit(this.$listeners, ["change", "click"])
      }
    }, {
      "domProps": {
        ...inputProps
      },
      "on": {
        "change": this.handleChange,
        "click": this.handleClick
      }
    }])), h("span", {
      "class": `${prefixCls}__input`
    }), h("span", {
      "class": `${prefixCls}__label`
    }, [utils_renderNode.renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange(e) {
      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(this.value, {
          e
        });
      } else {
        const target = e.target;
        utils_event.emitEvent(this, "change", target.checked, {
          e
        });
      }
    },
    handleClick(e) {
      this.$emit("click");
      if (!this.checked || !this.allowUncheck) return;
      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(void 0, {
          e
        });
      } else {
        utils_event.emitEvent(this, "change", false, {
          e
        });
      }
    }
  }
});

exports["default"] = _Radio;
//# sourceMappingURL=radio.js.map
