import $ from 'jquery';

export const addErrorToWrapper = (selector: string, error: string) => {
	const errorWrapper = $('.wetail-return-portal__error');
	const className = selector.startsWith('.') ? selector.slice(1) : selector;

	const existing = errorWrapper.find(selector);

	if (existing.length > 0) {
		existing.text(error);
	} else {
		errorWrapper.append(
			`<li class="wetail-return-portal__error--msg ${className}">${error}</li>`
		);
	}
}
