"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _utils = require("../../ui/src/utils");
var _ui = require("../../ui");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var _default2 = exports.default = /* define-vxe-component start */(0, _comp.defineVxeComponent)({
  name: 'VxeRadioButton',
  mixins: [_ui.globalMixins.sizeMixin, _ui.globalMixins.permissionMixin],
  props: {
    value: [String, Number, Boolean],
    checkedValue: {
      type: [String, Number, Boolean],
      default: undefined
    },
    title: [String, Number],
    content: [String, Number],
    disabled: {
      type: Boolean,
      default: null
    },
    strict: {
      type: Boolean,
      default: function _default() {
        return (0, _ui.getConfig)().radioButton.strict;
      }
    },
    size: {
      type: String,
      default: function _default() {
        return (0, _ui.getConfig)().radioButton.size || (0, _ui.getConfig)().size;
      }
    },
    /**
     * 已废弃，被 checkedValue 替换
     */
    label: {
      type: [String, Number, Boolean],
      default: null
    }
  },
  inject: {
    $xeForm: {
      default: null
    },
    formItemInfo: {
      from: 'xeFormItemInfo',
      default: null
    },
    $xeRadioGroup: {
      default: null
    }
  },
  data: function data() {
    var reactData = {};
    return {
      xID: _xeUtils.default.uniqueId(),
      reactData: reactData
    };
  },
  computed: Object.assign(Object.assign({}, {}), {
    computeIsDisabled: function computeIsDisabled() {
      var $xeRadioButton = this;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      var disabled = $xeRadioButton.disabled;
      if (disabled === null) {
        if ($xeRadioGroup) {
          var isDisabled = $xeRadioGroup.computeIsDisabled;
          return isDisabled;
        }
      }
      return disabled;
    },
    computeName: function computeName() {
      var $xeRadioButton = this;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      return $xeRadioGroup ? $xeRadioGroup.name : null;
    },
    computeStrict: function computeStrict() {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      return $xeRadioGroup ? $xeRadioGroup.strict : props.strict;
    },
    computeChecked: function computeChecked() {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      var label = props.label,
        checkedValue = props.checkedValue;
      var radioValue = _xeUtils.default.isUndefined(checkedValue) ? label : checkedValue;
      return $xeRadioGroup ? $xeRadioGroup.value === radioValue : props.value === radioValue;
    }
  }),
  methods: {
    //
    // Method
    //
    dispatchEvent: function dispatchEvent(type, params, evnt) {
      var $xeRadioButton = this;
      $xeRadioButton.$emit(type, (0, _ui.createEvent)(evnt, {
        $radioButton: $xeRadioButton
      }, params));
    },
    emitModel: function emitModel(value) {
      var $xeRadioButton = this;
      var _events = $xeRadioButton._events;
      $xeRadioButton.$emit('input', value);
      if (_events && _events.modelValue) {
        $xeRadioButton.$emit('modelValue', value);
      } else {
        $xeRadioButton.$emit('model-value', value);
      }
    },
    handleValue: function handleValue(checkedValue, evnt) {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var $xeForm = $xeRadioButton.$xeForm;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      var formItemInfo = $xeRadioButton.formItemInfo;
      var content = props.content;
      if ($xeRadioGroup) {
        $xeRadioGroup.handleChecked({
          label: checkedValue,
          checkedValue: checkedValue,
          checkedLabel: content
        }, evnt);
      } else {
        $xeRadioButton.emitModel(checkedValue);
        $xeRadioButton.dispatchEvent('change', {
          value: checkedValue,
          label: checkedValue,
          checkedValue: checkedValue,
          checkedLabel: content
        }, evnt);
        // 自动更新校验状态
        if ($xeForm && formItemInfo) {
          $xeForm.triggerItemEvent(evnt, formItemInfo.itemConfig.field, checkedValue);
        }
      }
    },
    changeEvent: function changeEvent(evnt) {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var isDisabled = $xeRadioButton.computeIsDisabled;
      if (!isDisabled) {
        var label = props.label,
          checkedValue = props.checkedValue;
        var radioValue = _xeUtils.default.isUndefined(checkedValue) ? label : checkedValue;
        $xeRadioButton.handleValue(radioValue, evnt);
      }
    },
    clickEvent: function clickEvent(evnt) {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var $xeRadioGroup = $xeRadioButton.$xeRadioGroup;
      var isDisabled = $xeRadioButton.computeIsDisabled;
      var isStrict = $xeRadioButton.computeStrict;
      if (!isDisabled && !isStrict) {
        var label = props.label,
          checkedValue = props.checkedValue;
        var radioValue = _xeUtils.default.isUndefined(checkedValue) ? label : checkedValue;
        if (radioValue === ($xeRadioGroup ? $xeRadioGroup.value : props.value)) {
          $xeRadioButton.handleValue(null, evnt);
        }
      }
    },
    //
    // Render
    //
    renderVN: function renderVN(h) {
      var $xeRadioButton = this;
      var props = $xeRadioButton;
      var slots = $xeRadioButton.$scopedSlots;
      var label = props.label,
        checkedValue = props.checkedValue;
      var radioValue = _xeUtils.default.isUndefined(checkedValue) ? label : checkedValue;
      var vSize = $xeRadioButton.computeSize;
      var isDisabled = $xeRadioButton.computeIsDisabled;
      var name = $xeRadioButton.computeName;
      var isChecked = $xeRadioButton.computeChecked;
      return h('label', {
        key: radioValue,
        class: ['vxe-radio vxe-radio--button', _defineProperty(_defineProperty({}, "size--".concat(vSize), vSize), 'is--disabled', isDisabled)],
        attrs: {
          title: props.title
        }
      }, [h('input', {
        class: 'vxe-radio--input',
        domProps: {
          checked: isChecked
        },
        attrs: {
          type: 'radio',
          name: name,
          disabled: isDisabled
        },
        on: {
          change: $xeRadioButton.changeEvent,
          click: $xeRadioButton.clickEvent
        }
      }), h('span', {
        class: 'vxe-radio--label'
      }, slots.default ? slots.default({}) : (0, _utils.getFuncText)(props.content))]);
    }
  },
  render: function render(h) {
    return this.renderVN(h);
  }
});
/* define-vxe-component end */