import { composeSomeConditions , composeValidators , Condition , required , validateMaxLength , validateMinLength , validateWhenOtherwise , Validator , } from "coral-framework/lib/validation" ; import getHTMLCharacterLength from "./getHTMLCharacterLength" ; const hasMediaAttached = ( value , values ) => ! ! values . media && ( values . media . type === "giphy" || values . media . type === "external" ) && ! ! values . media . url ; const hasRatingAttached = ( value , values ) => ! ! values . rating ; function getLengthValidators ( min , max ) { const validators = [ ] ; if ( min ) { validators . push ( required , validateMinLength ( min , getHTMLCharacterLength ) ) ; } if ( max ) { validators . push ( validateMaxLength ( max , getHTMLCharacterLength ) ) ; } return composeValidators ( ... validators ) ; } param min param max export default function getCommentBodyValidators ( min , max ) { return validateWhenOtherwise ( composeSomeConditions ( hasMediaAttached , hasRatingAttached ) , getLengthValidators ( null , max ) , getLengthValidators ( min || 1 , max ) ) ; }