/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-33ee4bce.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var utils_renderTnode = require('../utils/render-tnode.js');
var config = require('../config.js');
var utils_classnames = require('../utils/classnames.js');
var checkbox_props = require('./props.js');
var utils_helper = require('../utils/helper.js');
var utils_event = require('../utils/event.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isObject');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

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 name = "".concat(config.prefix, "-checkbox");
var _Checkbox = Vue__default["default"].extend({
  name: "TCheckbox",
  inheritAttrs: false,
  props: _objectSpread({}, checkbox_props["default"]),
  inject: {
    checkboxGroup: {
      "default": void 0
    }
  },
  data: function data() {
    return {
      formDisabled: void 0
    };
  },
  computed: {
    labelClasses: function labelClasses() {
      var _ref;

      return ["".concat(name), (_ref = {}, _defineProperty__default["default"](_ref, utils_classnames["default"].STATUS.checked, this.checked$), _defineProperty__default["default"](_ref, utils_classnames["default"].STATUS.disabled, this.disabled$), _defineProperty__default["default"](_ref, utils_classnames["default"].STATUS.indeterminate, this.indeterminate$), _ref)];
    },
    disabled$: function disabled$() {
      var _this$checkboxGroup, _this$checkboxGroup2;

      if (this.formDisabled) return this.formDisabled;

      if (!this.checkAll && !this.checked$ && (_this$checkboxGroup = this.checkboxGroup) !== null && _this$checkboxGroup !== void 0 && _this$checkboxGroup.maxExceeded) {
        return true;
      }

      if (this.disabled !== void 0) return this.disabled;
      return !!((_this$checkboxGroup2 = this.checkboxGroup) !== null && _this$checkboxGroup2 !== void 0 && _this$checkboxGroup2.disabled);
    },
    name$: function name$() {
      var _this$checkboxGroup3;

      return this.name || ((_this$checkboxGroup3 = this.checkboxGroup) === null || _this$checkboxGroup3 === void 0 ? void 0 : _this$checkboxGroup3.name);
    },
    checked$: function checked$() {
      var _this$checkboxGroup4;

      if (this.checkAll) return (_this$checkboxGroup4 = this.checkboxGroup) === null || _this$checkboxGroup4 === void 0 ? void 0 : _this$checkboxGroup4.isCheckAll;
      return this.checkboxGroup ? !!this.checkboxGroup.checkedMap[this.value] : this.checked;
    },
    indeterminate$: function indeterminate$() {
      var _this$checkboxGroup5;

      if (this.checkAll) return (_this$checkboxGroup5 = this.checkboxGroup) === null || _this$checkboxGroup5 === void 0 ? void 0 : _this$checkboxGroup5.indeterminate;
      return this.indeterminate;
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("label", {
      "class": this.labelClasses
    }, [h("input", helper.helper([{
      "attrs": {
        "type": "checkbox"
      }
    }, {
      "on": _objectSpread({}, utils_helper.omit(this.$listeners, ["checked", "change"]))
    }, {
      "class": "".concat(name, "__former"),
      "attrs": {
        "disabled": this.disabled$,
        "readonly": this.readonly,
        "indeterminate": this.indeterminate$,
        "name": this.name$
      },
      "domProps": {
        "value": this.value,
        "checked": this.checked$
      },
      "on": {
        "change": this.handleChange
      }
    }])), h("span", {
      "class": "".concat(name, "__input")
    }), h("span", {
      "class": "".concat(name, "__label")
    }, [utils_renderTnode.renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange: function handleChange(e) {
      var _this$checkboxGroup6;

      var value = !this.checked$;
      utils_event.emitEvent(this, "change", value, {
        e: e
      });
      e.stopPropagation();
      this === null || this === void 0 ? void 0 : (_this$checkboxGroup6 = this.checkboxGroup) === null || _this$checkboxGroup6 === void 0 ? void 0 : _this$checkboxGroup6.$emit("checked-change", {
        checked: value,
        checkAll: this.checkAll,
        e: e,
        option: this.$props
      });
    }
  }
});

exports["default"] = _Checkbox;
//# sourceMappingURL=checkbox.js.map
