<script setup>
import { computed, ref } from "vue";
import { useErrorMessage } from "./useErrorMessage";
import { useRequiredLabel } from "./useRequiredLabel";
import { useLight } from "#imports";
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;
  }
};
const light = useLight();
const attrs = computed(() => {
  return {
    ...light.styles.input,
    ...JSON.parse(JSON.stringify(props.context.attrs))
  };
});
</script>

<template>
    <q-file v-model="value" :label="label" v-bind="attrs" :error="error" :error-message="errorMessage"
        @blur="onBlur" hide-bottom-space>
        <template v-for="(s, name) in $slots" v-slot:[name]="props" :key="name">
            <slot :name="name" v-bind="props ?? {}"></slot>
        </template>
    </q-file>
</template>
