/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { renderContent } from '../utils/render-tnode.js';
import { prefix } from '../config.js';
import ClASSNAMES from '../utils/classnames.js';
import checkboxProps from './props.js';
import { omit } from '../utils/helper.js';
import { emitEvent } from '../utils/event.js';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';

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

      return ["".concat(name), (_ref = {}, _defineProperty(_ref, ClASSNAMES.STATUS.checked, this.checked$), _defineProperty(_ref, ClASSNAMES.STATUS.disabled, this.disabled$), _defineProperty(_ref, ClASSNAMES.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([{
      "attrs": {
        "type": "checkbox"
      }
    }, {
      "on": _objectSpread({}, 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")
    }, [renderContent(this, "default", "label")])]);
  },
  methods: {
    handleChange: function handleChange(e) {
      var _this$checkboxGroup6;

      var value = !this.checked$;
      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
      });
    }
  }
});

export { _Checkbox as default };
//# sourceMappingURL=checkbox.js.map
