<script setup>
import { computed, ref } from "vue";
import { useErrorMessage } from "./useErrorMessage";
import { useRequiredLabel } from "./useRequiredLabel";
const props = defineProps({
  context: Object
});
const error = ref(false);
const errorMessage = ref("");
useErrorMessage(props.context.node, error, errorMessage);
const label = useRequiredLabel(props.context);
const value = computed({
  get: () => props.context.value,
  set: (val) => props.context.node.input(val)
});
const onBlur = () => {
  if (errorMessage.value) {
    error.value = true;
  } else {
    error.value = false;
  }
};
</script>

<template>
    <l-file-upload v-bind="context.attrs" v-model="value" :label="label" :error="error" :type="context.inputType"
        :error-message="errorMessage" @blur="onBlur">
        <template v-for="(s, name) in $slots" v-slot:[name]="props" :key="name">
            <slot :name="name" v-bind="props ?? {}"></slot>
        </template>
    </l-file-upload>
</template>
