text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  exports.__esModule = true;
  exports.CheckboxMixin = void 0;
  
  var _index = _interopRequireDefault(require("../icon/index"));
  
  var _relation = require("./relation");
  
  var _utils = require("../utils");
  
  /**
   * Common part of Checkbox & Radio
   */
  var CheckboxMixin = function CheckboxMixin(_ref) {
    var parent = _ref.parent,
        bem = _ref.bem,
        role = _ref.role;
    return {
      mixins: [(0, _relation.ChildrenMixin)(parent)],
      props: {
        name: null,
        value: null,
        disabled: Boolean,
        iconSize: [Number, String],
        checkedColor: String,
        labelPosition: String,
        labelDisabled: Boolean,
        shape: {
          type: String,
          default: 'round'
        }
      },
      computed: {
        isDisabled: function isDisabled() {
          return this.parent && this.parent.disabled || this.disabled;
        },
        iconStyle: function iconStyle() {
          var checkedColor = this.checkedColor;
  
          if (checkedColor && this.checked && !this.isDisabled) {
            return {
              borderColor: checkedColor,
              backgroundColor: checkedColor
            };
          }
        },
        tabindex: function tabindex() {
          if (this.isDisabled || role === 'radio' && !this.checked) {
            return -1;
          }
  
          return 0;
        }
      },
      methods: {
        onClick: function onClick(event) {
          var label = this.$refs.label;
          var target = event.target;
          var labelClicked = label && (label === target || label.contains(target));
  
          if (!this.isDisabled && !(labelClicked && this.labelDisabled)) {
            this.toggle();
          }
  
          this.$emit('click', event);
        }
      },
      render: function render() {
        var h = arguments[0];
        var slots = this.slots,
            checked = this.checked;
        var CheckIcon = slots('icon', {
          checked: checked
        }) || h(_index.default, {
          "attrs": {
            "name": "check"
          },
          "style": this.iconStyle
        });
        var Label = slots() && h("span", {
          "ref": "label",
          "class": bem('label', [this.labelPosition, {
            disabled: this.isDisabled
          }])
        }, [slots()]);
        var Children = [h("div", {
          "style": {
            fontSize: (0, _utils.addUnit)(this.iconSize)
          },
          "class": bem('icon', [this.shape, {
            disabled: this.isDisabled,
            checked: checked
          }])
        }, [CheckIcon])];
  
        if (this.labelPosition === 'left') {
          Children.unshift(Label);
        } else {
          Children.push(Label);
        }
  
        return h("div", {
          "attrs": {
            "role": role,
            "tabindex": this.tabindex,
            "aria-checked": String(this.checked)
          },
          "class": bem(),
          "on": {
            "click": this.onClick
          }
        }, [Children]);
      }
    };
  };
  
  exports.CheckboxMixin = CheckboxMixin;