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

'use strict';

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

var helper = require('../../chunks/helper.js');
var Vue = require('vue');
var utils_renderNode = require('../../utils/render-node.js');
var utils_helper = require('../../utils/helper.js');
var utils_event = require('../../utils/event.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_checkbox_props = require('./props.js');
require('lodash');
require('lodash/camelCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("checkbox");
var _Checkbox = utils_mixins["default"](classPrefixMixins, Vue__default["default"]).extend({
  name: "LCheckbox",
  inheritAttrs: false,
  props: {
    ...components_checkbox_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.helper([{
      "attrs": {
        "type": "checkbox"
      }
    }, {
      "on": {
        ...utils_helper.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
      }
    }, [utils_renderNode.renderContent(this, "default", "label")])]);
  },
  methods: {
    handleLabelClick(e) {
      if (this.stopLabelTrigger) e.preventDefault();
    },
    handleChange(e) {
      const value = !this.checked$;
      utils_event.emitEvent(this, "change", value, {
        e
      });
      e.stopPropagation();
      this?.checkboxGroup?.$emit("checked-change", {
        checked: value,
        checkAll: this.checkAll,
        e,
        option: this.$props
      });
    }
  }
});

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