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

'use strict';

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

var helper = require('../../chunks/helper.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var utils_helper = require('../../utils/helper.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_radio_props = require('./props.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');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('@babel/runtime/helpers/typeof');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('lodash');
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 _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

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__default["default"](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 = components_configProvider_configReceiver.getClassPrefixMixins("radio");
var _Radio = utils_mixins["default"](Vue__default["default"], classPrefixMixins).extend({
  name: "LRadio",
  inheritAttrs: false,
  props: _objectSpread({}, components_radio_props.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__default["default"](_ref, this.commonStatusClassName.checked, inputProps.checked), _defineProperty__default["default"](_ref, this.commonStatusClassName.disabled, inputProps.disabled), _ref)];
    return h("label", {
      "class": inputClass
    }, [h("input", helper.helper([{
      "attrs": {
        "type": "radio"
      },
      "class": "".concat(prefixCls, "__former")
    }, {
      "on": _objectSpread({}, utils_helper.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")
    }, [utils_renderNode.renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange: function handleChange(e) {
      if (this.radioGroup) {
        this.radioGroup.handleRadioChange(this.value, {
          e: e
        });
      } else {
        var target = e.target;
        utils_event.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 {
        utils_event.emitEvent(this, "change", false, {
          e: e
        });
      }
    }
  }
});

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