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

import { h as helper } from '../../chunks/helper.js';
import Vue from 'vue';
import { omit } from '../../utils/helper.js';
import { renderContent } from '../../utils/render-node.js';
import { emitEvent } from '../../utils/event.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { RadioProps } from './props.js';
import '../../chunks/_commonjsHelpers.js';
import 'lodash/camelCase';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("radio");
var _Radio = mixins(Vue, classPrefixMixins).extend({
  name: "LRadio",
  inheritAttrs: false,
  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([{
      "attrs": {
        "type": "radio"
      },
      "class": `${prefixCls}__former`
    }, {
      "on": {
        ...omit(this.$listeners, ["change", "click"])
      }
    }, {
      "domProps": {
        ...inputProps
      },
      "on": {
        "change": this.handleChange,
        "click": this.handleClick
      }
    }])), h("span", {
      "class": `${prefixCls}__input`
    }), h("span", {
      "class": `${prefixCls}__label`
    }, [renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange(e) {
      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(this.value, {
          e
        });
      } else {
        const target = e.target;
        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 {
        emitEvent(this, "change", false, {
          e
        });
      }
    }
  }
});

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