'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var vueTypes = require('../../../utils/vue/vueTypes.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var _class = require('../../../utils/dom/class.cjs');

const checkboxProps = {
  prefixCls: String,
  name: String,
  id: String,
  type: String,
  defaultChecked: {
    type: [Boolean, Number],
    default: void 0
  },
  checked: {
    type: [Boolean, Number],
    default: void 0
  },
  disabled: Boolean,
  tabindex: {
    type: [Number, String]
  },
  readonly: Boolean,
  autofocus: Boolean,
  value: vueTypes.default.any,
  required: Boolean
};
var VcCheckbox = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "Checkbox",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(checkboxProps, {
    prefixCls: "rc-checkbox",
    type: "checkbox",
    defaultChecked: false
  }),
  emits: ["click", "change"],
  setup(props, {
    attrs,
    emit,
    expose
  }) {
    const checked = vue.ref(props.checked === void 0 ? props.defaultChecked : props.checked);
    const inputRef = vue.ref();
    vue.watch(() => props.checked, () => {
      checked.value = props.checked;
    });
    expose({
      focus() {
        var _a;
        (_a = inputRef.value) == null ? void 0 : _a.focus();
      },
      blur() {
        var _a;
        (_a = inputRef.value) == null ? void 0 : _a.blur();
      }
    });
    const eventShiftKey = vue.ref();
    const handleChange = (e) => {
      if (props.disabled)
        return;
      if (props.checked === void 0)
        checked.value = e.target.checked;
      e.shiftKey = eventShiftKey.value;
      const eventObj = {
        target: {
          ...props,
          checked: e.target.checked
        },
        stopPropagation() {
          e.stopPropagation();
        },
        preventDefault() {
          e.preventDefault();
        },
        nativeEvent: e
      };
      if (props.checked !== void 0)
        inputRef.value.checked = !!props.checked;
      emit("change", eventObj);
      eventShiftKey.value = false;
    };
    const onClick = (e) => {
      emit("click", e);
      eventShiftKey.value = e.shiftKey;
    };
    return () => {
      const {
        prefixCls,
        name,
        id,
        type,
        disabled,
        readonly,
        tabindex,
        autofocus,
        value,
        required,
        ...others
      } = props;
      const {
        class: className,
        onFocus,
        onBlur,
        onKeydown,
        onKeypress,
        onKeyup
      } = attrs;
      const othersAndAttrs = {
        ...others,
        ...attrs
      };
      const globalProps = Object.keys(othersAndAttrs).reduce((prev, key) => {
        if (key.startsWith("data-") || key.startsWith("aria-") || key === "role")
          prev[key] = othersAndAttrs[key];
        return prev;
      }, {});
      const classString = _class.classNames(prefixCls, className, {
        [`${prefixCls}-checked`]: checked.value,
        [`${prefixCls}-disabled`]: disabled
      });
      const inputProps = {
        name,
        id,
        type,
        readonly,
        disabled,
        tabindex,
        class: `${prefixCls}-input`,
        checked: !!checked.value,
        autofocus,
        value,
        ...globalProps,
        onChange: handleChange,
        onClick,
        onFocus,
        onBlur,
        onKeydown,
        onKeypress,
        onKeyup,
        required
      };
      return vue.createVNode("span", {
        "class": classString
      }, [vue.createVNode("input", {
        "ref": inputRef,
        ...inputProps
      }, null), vue.createVNode("span", {
        "class": `${prefixCls}-inner`
      }, null)]);
    };
  }
});

exports.checkboxProps = checkboxProps;
exports.default = VcCheckbox;
//# sourceMappingURL=Checkbox.cjs.map
