/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { h as helper } from '../../chunks/helper.js';
import Vue from 'vue';
import { renderContent } from '../../utils/render-node.js';
import { omit } from '../../utils/helper.js';
import { emitEvent } from '../../utils/event.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import { CheckboxProps } from './props.js';
import '../../chunks/_commonjsHelpers.js';
import 'lodash';
import 'lodash/camelCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("checkbox");
var _Checkbox = mixins(classPrefixMixins, Vue).extend({
  name: "LCheckbox",
  inheritAttrs: false,
  props: {
    ...CheckboxProps,
    stopLabelTrigger: Boolean
  },
  inject: {
    checkboxGroup: {
      default: void 0
    }
  },
  data() {
    return {
      formDisabled: void 0
    };
  },
  computed: {
    labelClasses() {
      return [`${this.componentName}`, {
        [this.commonStatusClassName.checked]: this.checked$,
        [this.commonStatusClassName.disabled]: this.disabled$,
        [this.commonStatusClassName.indeterminate]: this.indeterminate$
      }];
    },
    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$() {
      var _this$checkboxGroup3;
      return this.name || ((_this$checkboxGroup3 = this.checkboxGroup) === null || _this$checkboxGroup3 === void 0 ? void 0 : _this$checkboxGroup3.name);
    },
    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$() {
      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() {
    const h = arguments[0];
    return h("label", {
      "class": this.labelClasses,
      "attrs": {
        "title": this.$attrs.title
      }
    }, [h("input", helper([{
      "attrs": {
        "type": "checkbox"
      }
    }, {
      "on": {
        ...omit(this.$listeners, ["checked", "change"])
      }
    }, {
      "class": `${this.componentName}__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": `${this.componentName}__input`
    }), h("span", {
      "class": `${this.componentName}__label`,
      "on": {
        "click": this.handleLabelClick
      }
    }, [renderContent(this, "default", "label")])]);
  },
  methods: {
    handleLabelClick(e) {
      if (this.stopLabelTrigger) e.preventDefault();
    },
    handleChange(e) {
      var _this$checkboxGroup6;
      const value = !this.checked$;
      emitEvent(this, "change", value, {
        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,
        option: this.$props
      });
    }
  }
});

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