import { useValidator } from 'src/composables/useValidator';

export function useRequired($attrs) {
    const { validations } = useValidator();
    const hasRequired = Object.keys($attrs).includes('required');
    let isRequired = false;
    if (hasRequired) {
        const required = $attrs['required'];
        if (typeof required === 'boolean') {
            isRequired = required;
        }
    }
    const requiredFieldRule = (val) => validations().required(isRequired, val);

    return {
        isRequired,
        requiredFieldRule,
    };
}
