<script setup>
import { reactiveOmit } from "@vueuse/core";
import { Icon } from "@iconify/vue";
import { CheckboxIndicator, CheckboxRoot, useForwardPropsEmits } from "reka-ui";
import { cn } from "../../../utils/cn";
defineOptions({ name: "UiCheckbox" });
const props = defineProps({
  defaultValue: { type: null, required: false },
  modelValue: { type: null, required: false },
  disabled: { type: Boolean, required: false },
  value: { type: null, required: false },
  id: { type: String, required: false },
  trueValue: { type: null, required: false },
  falseValue: { type: null, required: false },
  asChild: { type: Boolean, required: false },
  as: { type: null, required: false },
  name: { type: String, required: false },
  required: { type: Boolean, required: false },
  class: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true }
});
const emits = defineEmits(["update:modelValue"]);
const delegatedProps = reactiveOmit(props, "class");
const forwarded = useForwardPropsEmits(delegatedProps, emits);
</script>

<template>
  <CheckboxRoot
    v-slot="slotProps"
    data-slot="checkbox"
    v-bind="forwarded"
    :class="
  cn(
    'peer cursor-pointer flex items-center justify-center border-zinc-200 data-[state=checked]:bg-(--primary) data-[state=checked]:text-white data-[state=checked]:border-(--primary) data-[state=indeterminate]:bg-(--primary) data-[state=indeterminate]:text-white data-[state=indeterminate]:border-(--primary) aria-invalid:border-red-400 size-4 shrink-0 rounded border shadow-xs hover:shadow transition-shadow outline-none disabled:cursor-not-allowed disabled:opacity-50',
    props.class
  )
"
  >
    <CheckboxIndicator
      data-slot="checkbox-indicator"
      class="grid h-full w-full place-content-center transition-none text-xs"
    >
      <slot v-bind="slotProps">
        <Icon
          v-if="slotProps.state === true"
          icon="fluent:checkmark-20-filled"
        />
        <Icon
          v-else-if="slotProps.state === 'indeterminate'"
          icon="radix-icons:minus"
        />
      </slot>
    </CheckboxIndicator>
  </CheckboxRoot>
</template>
