// validationMixin.js
export default {
    props: ['fields', 'field_id', 'field_value'],
    methods: {
      isVisible() {
        if (!this.fields.dependencies) return true;
        return this.fields.dependencies.every(dep => {
          const depValue = this.$parent?.$refs[dep.field]?.value;
          return depValue === dep.value;
        });
      },
      validateField() {
        const visible = this.isVisible();
        const required = this.fields.required === true;
        const value = this.field_value;
  
        const isValid = !required || (visible && value !== undefined && value !== null && value !== '');
  
        this.$root.$emit('field-validation', {
          fieldId: this.field_id,
          isValid
        });
  
        return isValid;
      }
    },
    watch: {
      field_value() {
        this.validateField();
      }
    },
    mounted() {
      this.validateField();
    }
};
  