import $ from 'jquery';

export const showError = (form: JQuery, message?: string) => {
	form.find($('.wetail-return-portal__form-field')).addClass('invalid');
	const errorWrapper = $( '.wetail-return-portal__error' );
	if ( !message ) {
		const {i18n} = window.__wetail_shipping_return_portal;
		message = i18n.order_verification_error;
	}

	if ( errorWrapper.find('.wetail-return-portal__error--msg-verify-order').length > 0 ) {
		errorWrapper.find('.wetail-return-portal__error--msg-verify-order').text(message)
	} else {
		errorWrapper.append(`<li class="wetail-return-portal__error--msg wetail-return-portal__error--msg-verify-order">${message}</li>`);
	}

	errorWrapper.fadeIn(200);
}
