import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
import { computed, toRef } from "vue";
import { getUid } from "@veno-ui/utils";
import { defineComponent } from "../../utils";
import { FormControl } from "../form-control";
import { SelectionGroupControl } from "../selection-group-control";
import { makeSelectionGroupControlProps } from "../selection-group-control/selection-group-control";
import { Checkbox } from "../checkbox";
import { makeSizeProps } from "../../composables/size";
import { makeDensityProps } from "../../composables/density";
import { provideDefaults } from "../../composables/defaults";
import { useProxiedModel } from "../../composables/proxied-model";
const CheckboxGroup = defineComponent({
  name: "VeCheckboxGroup",
  props: {
    /**
     * @zh 复选框的所有可选项
     */
    items: Array,
    ...makeSelectionGroupControlProps({
      type: "checkbox",
      falseIcon: "$checkboxOff",
      trueIcon: "$checkboxOn",
      multiple: true
    }),
    ...makeSizeProps(),
    ...makeDensityProps()
  },
  emits: {
    "update:modelValue": (_val) => true
  },
  setup(props, {
    slots
  }) {
    const id = computed(() => props.id || `ve-checkbox-group-${getUid()}`);
    const model = useProxiedModel(props, "modelValue");
    const items = computed(() => {
      return props.items?.map((itemProps) => typeof itemProps === "string" ? {
        value: itemProps
      } : itemProps);
    });
    provideDefaults({
      VeCheckbox: {
        size: toRef(props, "size"),
        density: toRef(props, "density"),
        readonly: toRef(props, "readonly"),
        disabled: toRef(props, "disabled")
      }
    });
    return () => {
      const {
        density,
        size,
        ...restProps
      } = props;
      return _createVNode(FormControl, {
        "class": "ve-checkbox-group",
        "density": density,
        "name": props.name,
        "size": size,
        "modelValue": model.value,
        "onUpdate:modelValue": ($event) => model.value = $event
      }, {
        ...slots,
        default: ({
          isDisabled,
          isReadonly,
          props: controlProps
        }) => {
          return _createVNode(SelectionGroupControl, _mergeProps(restProps, controlProps, {
            "id": id.value,
            "disabled": isDisabled.value,
            "readonly": isReadonly.value,
            "modelValue": model.value,
            "onUpdate:modelValue": ($event) => model.value = $event
          }), {
            default: () => [items.value?.map((itemProps) => _createVNode(Checkbox, itemProps, null)), slots.default?.()]
          });
        }
      });
    };
  }
});
export {
  CheckboxGroup
};
//# sourceMappingURL=checkbox-group.mjs.map
