import { isPropAbsent, isBoolean } from "../../../../utils/types.mjs";
import { useFormSize } from "../../../form/src/hooks/use-form-common-props.mjs";
import { checkboxGroupContextKey } from "../constants.mjs";
import { inject, ref, computed, toRaw } from "vue";
import { isArray, isObject } from "../../../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import isEqual from "../../../../../../lodash-es/isEqual.mjs";
const useCheckboxStatus = (props, slots, { model }) => {
  const checkboxGroup = inject(checkboxGroupContextKey, void 0);
  const isFocused = ref(false);
  const actualValue = computed(() => {
    if (!isPropAbsent(props.value)) return props.value;
    return props.label;
  });
  const isChecked = computed(() => {
    const value = model.value;
    if (isBoolean(value)) return value;
    else if (isArray(value)) if (isObject(actualValue.value)) return value.map(toRaw).some((o) => isEqual(o, actualValue.value));
    else return value.map(toRaw).includes(actualValue.value);
    else if (value !== null && value !== void 0) return value === props.trueValue || value === props.trueLabel;
    else return !!value;
  });
  return {
    checkboxButtonSize: useFormSize(computed(() => {
      var _a;
      return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;
    }), { prop: true }),
    isChecked,
    isFocused,
    checkboxSize: useFormSize(computed(() => {
      var _a;
      return (_a = checkboxGroup == null ? void 0 : checkboxGroup.size) == null ? void 0 : _a.value;
    })),
    hasOwnLabel: computed(() => {
      return !!slots.default || !isPropAbsent(actualValue.value);
    }),
    actualValue
  };
};
export {
  useCheckboxStatus
};
