/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-b0f1ed22.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 'lodash';
import 'lodash/camelCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../../_chunks/dep-b4fd1955.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$() {
      if (this.formDisabled) return this.formDisabled;
      if (!this.checkAll && !this.checked$ && this.checkboxGroup?.maxExceeded) return true;
      if (this.disabled !== void 0) return this.disabled;
      return !!this.checkboxGroup?.disabled;
    },
    name$() {
      return this.name || this.checkboxGroup?.name;
    },
    checked$() {
      if (this.checkAll) return this.checkboxGroup?.isCheckAll;
      return this.checkboxGroup ? !!this.checkboxGroup.checkedMap[this.value] : this.checked;
    },
    indeterminate$() {
      if (this.checkAll) return this.checkboxGroup?.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) {
      const value = !this.checked$;
      emitEvent(this, "change", value, {
        e
      });
      e.stopPropagation();
      this?.checkboxGroup?.$emit("checked-change", {
        checked: value,
        checkAll: this.checkAll,
        e,
        option: this.$props
      });
    }
  }
});

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