import { ElCheckbox } from 'element-plus'
import { useFormInput } from '@cip/components/hooks/form-input'
import { formInputProps, fromInputEmits } from '../../form-input-props'
import { computed, h } from 'vue'
export default {
  props: formInputProps,
  emits: [...fromInputEmits],
  setup (props, context) {
    const { proxyValue, securityConfig, ...formInput } = useFormInput(props, context)
    const option = computed(() => {
      return securityConfig.value.option
    })
    return () => h(ElCheckbox, {
      ...formInput,
      label: option.value.value,
      modelValue: props.modelValue === option.value.value,
      'onUpdate:modelValue': (val) => {
        if (val) {
          proxyValue.value = option.value.value ?? true
        } else {
          proxyValue.value = option.value.inactiveValue
        }
      }
    }, { default: () => `${option.value.label}` })
  }
}
