"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../constants/event.js");
const error = require("../../../utils/error.js");
const index = require("../../../hooks/use-namespace/index.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const useFormItem = require("../../form/src/hooks/use-form-item.js");
const constants = require("./constants.js");
const checkbox2 = require("./checkbox2.js");
const checkboxButton = require("./checkbox-button.js");
const checkboxGroup = require("./checkbox-group.js");
const Vue = require("vue");
const pick = require("../../../../../lodash-es/pick.js");
const isEqual = require("../../../../../lodash-es/isEqual.js");
const omit = require("../../../../../lodash-es/omit.js");
var checkbox_group_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElCheckboxGroup",
  __name: "checkbox-group",
  props: checkboxGroup.checkboxGroupProps,
  emits: checkboxGroup.checkboxGroupEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const ns = index.useNamespace("checkbox");
    const checkboxDisabled = useFormCommonProps.useFormDisabled();
    const { formItem } = useFormItem.useFormItem();
    const { inputId: groupId, isLabeledByFormItem } = useFormItem.useFormItemInputId(props, { formItemContext: formItem });
    const changeEvent = async (value) => {
      emit(event.UPDATE_MODEL_EVENT, value);
      await Vue.nextTick();
      emit(event.CHANGE_EVENT, value);
    };
    const modelValue = Vue.computed({
      get() {
        return props.modelValue;
      },
      set(val) {
        changeEvent(val);
      }
    });
    const aliasProps = Vue.computed(() => ({
      ...checkboxGroup.checkboxDefaultProps,
      ...props.props
    }));
    const getOptionProps = (option) => {
      const { label, value, disabled } = aliasProps.value;
      const base = {
        label: option[label],
        value: option[value],
        disabled: option[disabled]
      };
      return {
        ...omit.default(option, [
          label,
          value,
          disabled
        ]),
        ...base
      };
    };
    const optionComponent = Vue.computed(() => props.type === "button" ? checkboxButton.default : checkbox2.default);
    Vue.provide(constants.checkboxGroupContextKey, {
      ...pick.default(Vue.toRefs(props), [
        "size",
        "min",
        "max",
        "validateEvent",
        "fill",
        "textColor"
      ]),
      disabled: checkboxDisabled,
      modelValue,
      changeEvent
    });
    Vue.watch(() => props.modelValue, (newVal, oldValue) => {
      if (props.validateEvent && !isEqual.default(newVal, oldValue)) formItem == null ? void 0 : formItem.validate("change").catch((err) => error.debugWarn(err));
    });
    return (_ctx, _cache) => {
      var _a;
      return Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(__props.tag), {
        id: Vue.unref(groupId),
        class: Vue.normalizeClass(Vue.unref(ns).b("group")),
        role: "group",
        "aria-label": !Vue.unref(isLabeledByFormItem) ? __props.ariaLabel || "checkbox-group" : void 0,
        "aria-labelledby": Vue.unref(isLabeledByFormItem) ? (_a = Vue.unref(formItem)) == null ? void 0 : _a.labelId : void 0
      }, {
        default: Vue.withCtx(() => [Vue.renderSlot(_ctx.$slots, "default", {}, () => [(Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(__props.options, (item, index2) => {
          return Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(optionComponent.value), Vue.mergeProps({ key: index2 }, { ref_for: true }, getOptionProps(item)), null, 16);
        }), 128))])]),
        _: 3
      }, 8, [
        "id",
        "class",
        "aria-label",
        "aria-labelledby"
      ]);
    };
  }
});
exports.default = checkbox_group_vue_vue_type_script_setup_true_lang_default;
