/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-b13ef886.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { omit } from '../../utils/helper.js';
import { renderContent } from '../../utils/render-node.js';
import { RadioProps } from './props.js';
import { emitEvent } from '../../utils/event.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '@babel/runtime/helpers/typeof';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-a0f2090c.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: "LRadio",
  inheritAttrs: false,
  props: _objectSpread({}, RadioProps),
  inject: {
    radioGroup: {
      "default": void 0
    },
    radioButton: {
      "default": void 0
    }
  },
  data: function data() {
    return {
      formDisabled: void 0
    };
  },
  computed: {
    tDisabled: function tDisabled() {
      return this.formDisabled || this.disabled;
    }
  },
  render: function render() {
    var _ref;

    var h = arguments[0];
    var radioGroup = this.radioGroup,
        radioButton = this.radioButton;
    var 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;
    }

    var prefixCls = radioButton ? "".concat(this.componentName, "-button") : this.componentName;
    var inputClass = ["".concat(prefixCls), (_ref = {}, _defineProperty(_ref, this.commonStatusClassName.checked, inputProps.checked), _defineProperty(_ref, this.commonStatusClassName.disabled, inputProps.disabled), _ref)];
    return h("label", {
      "class": inputClass
    }, [h("input", helper([{
      "attrs": {
        "type": "radio"
      },
      "class": "".concat(prefixCls, "__former")
    }, {
      "on": _objectSpread({}, omit(this.$listeners, ["change", "click"]))
    }, {
      "domProps": _objectSpread({}, inputProps),
      "on": {
        "change": this.handleChange,
        "click": this.handleClick
      }
    }])), h("span", {
      "class": "".concat(prefixCls, "__input")
    }), h("span", {
      "class": "".concat(prefixCls, "__label")
    }, [renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange: function handleChange(e) {
      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(this.value, {
          e: e
        });
      } else {
        var target = e.target;
        emitEvent(this, "change", target.checked, {
          e: e
        });
      }
    },
    handleClick: function handleClick(e) {
      this.$emit("click");
      if (!this.checked || !this.allowUncheck) return;

      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(void 0, {
          e: e
        });
      } else {
        emitEvent(this, "change", false, {
          e: e
        });
      }
    }
  }
});

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