/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var hooks_useVModel = require('../hooks/useVModel.js');
var form_hooks = require('../form/hooks.js');
var hooks_useRipple = require('../hooks/useRipple.js');
var hooks_tnode = require('../hooks/tnode.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var checkbox_props = require('./props.js');
var checkbox_constants = require('./constants.js');
require('lodash/kebabCase');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7f0559c3.js');
require('dayjs');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('lodash/camelCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');

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

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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 _Checkbox = vue.defineComponent({
  name: "TCheckbox",
  props: _objectSpread(_objectSpread({}, checkbox_props["default"]), {}, {
    needRipple: Boolean,
    stopLabelTrigger: Boolean
  }),
  setup: function setup(props2) {
    var labelRef = vue.ref();
    if (props2.needRipple) hooks_useRipple["default"](labelRef);
    var _toRefs = vue.toRefs(props2),
      checked = _toRefs.checked,
      modelValue = _toRefs.modelValue;
    var _useVModel = hooks_useVModel["default"](checked, modelValue, props2.defaultChecked, props2.onChange, "checked"),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      innerChecked = _useVModel2[0],
      setInnerChecked = _useVModel2[1];
    var checkboxGroup = vue.inject(checkbox_constants.CheckboxGroupInjectionKey, void 0);
    var GroupDisabled = vue.computed(function () {
      return props2.disabled || !!(checkboxGroup !== null && checkboxGroup !== void 0 && checkboxGroup.disabled);
    });
    var formDisabled = form_hooks.useFormDisabled(GroupDisabled);
    var name = vue.computed(function () {
      return props2.name || (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.name);
    });
    var selfChecked = vue.computed(function () {
      if (props2.checkAll) return checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.isCheckAll;
      return checkboxGroup ? !!checkboxGroup.checkedMap[props2.value] : innerChecked.value;
    });
    var disabled = vue.computed(function () {
      if (formDisabled.value) return formDisabled.value;
      if (!props2.checkAll && !selfChecked.value && checkboxGroup !== null && checkboxGroup !== void 0 && checkboxGroup.maxExceeded) return true;
      if (props2.disabled !== void 0) return props2.disabled;
      return !!(checkboxGroup !== null && checkboxGroup !== void 0 && checkboxGroup.disabled);
    });
    var selfIndeterminate = vue.computed(function () {
      if (props2.checkAll) return checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.indeterminate;
      return props2.indeterminate;
    });
    var classPrefix = hooks_useConfig.usePrefixClass();
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("checkbox");
    var labelClasses = vue.computed(function () {
      var _ref;
      return ["".concat(COMPONENT_NAME.value), (_ref = {}, _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-checked"), selfChecked.value), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-disabled"), disabled.value), _defineProperty__default["default"](_ref, "".concat(classPrefix.value, "-is-indeterminate"), selfIndeterminate.value), _ref)];
    });
    var handleChange = function handleChange(e) {
      if (props2.readonly) return;
      var checked2 = !selfChecked.value;
      setInnerChecked(checked2, {
        e: e
      });
      if (checkboxGroup && checkboxGroup.handleCheckboxChange) checkboxGroup.onCheckedChange({
        checked: checked2,
        checkAll: props2.checkAll,
        e: e,
        option: props2
      });
    };
    var renderContent = hooks_tnode.useContent();
    var handleLabelClick = function handleLabelClick(e) {
      if (props2.stopLabelTrigger) e.preventDefault();
    };
    return function () {
      return vue.createVNode("label", {
        "class": labelClasses.value,
        "ref": "labelRef"
      }, [vue.createVNode("input", {
        "type": "checkbox",
        "class": "".concat(COMPONENT_NAME.value, "__former"),
        "disabled": disabled.value,
        "readonly": props2.readonly,
        "indeterminate": props2.indeterminate,
        "name": name.value,
        "value": props2.value,
        "checked": selfChecked.value,
        "onChange": handleChange
      }, null), vue.createVNode("span", {
        "class": "".concat(COMPONENT_NAME.value, "__input")
      }, null), vue.createVNode("span", {
        "class": "".concat(COMPONENT_NAME.value, "__label"),
        "onClick": handleLabelClick
      }, [renderContent("default", "label")])]);
    };
  }
});

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