"use strict";

var _interopRequireDefault = require("D:/GIT/opu-components-vue/node_modules/@babel/runtime/helpers/interopRequireDefault.js").default;

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("core-js/modules/es.number.constructor.js");

require("core-js/modules/es.array.concat.js");

var _objectSpread2 = _interopRequireDefault(require("D:/GIT/opu-components-vue/node_modules/@babel/runtime/helpers/esm/objectSpread2.js"));

var _index = _interopRequireDefault(require("ant-design-vue/lib/checkbox/index"));

var _utils = _interopRequireDefault(require("../../utils"));

var _default = {
  name: "OpuCheckbox",
  components: {},
  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _index.default.props), {}, {
    trueValue: {
      type: [String, Boolean, Number],
      default: true
    },
    falseValue: {
      type: [String, Boolean, Number],
      default: false
    },
    checked: [Number, String, Boolean]
  }),
  model: {
    prop: "value",
    event: "update"
  },
  data: function data() {
    return {};
  },
  computed: {
    componentProps: function componentProps() {
      var _this = this;

      var $listeners = this.$listeners,
          $options = this.$options;
      var propsData = $options.propsData;
      var ons = {};

      _utils.default.each($listeners, function (cb, type) {
        ons[type] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this.$emit.apply(_this, [type].concat(args));
        };
      });

      var props = {
        props: (0, _objectSpread2.default)({}, propsData),
        on: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
          change: this.updateValue
        })
      };
      return props;
    }
  },
  methods: {
    updateValue: function updateValue(e) {
      var checked = e.target.checked;
      var trueValue = this.trueValue,
          falseValue = this.falseValue;
      var val = checked ? trueValue : falseValue;
      this.$emit("update", val);
      this.$emit("change", val);
    }
  },
  render: function render(h) {
    var componentProps = this.componentProps,
        $scopedSlots = this.$scopedSlots,
        checked = this.checked,
        trueValue = this.trueValue;
    return h("a-checkbox", {
      ref: "inputComponent",
      props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, componentProps.props), {}, {
        checked: checked === trueValue ? true : false
      }),
      on: (0, _objectSpread2.default)({}, componentProps.on),
      scopedSlots: $scopedSlots
    }, []);
  }
};
exports.default = _default;