import { calculate_total_weight } from './calculate_total_weight';
import { set_required_element_ids } from './required_element_ids';
import { get_tbody_from_event } from './get_tbody_from_event';
import { append_row_to_table } from './append_row_to_table';
import { process_required_elements } from './total_weight_input_element_value';
import { prompt_product_name } from './prompt_product_name';

export const add_a_row_to_dimensions_validation_form = ( event: JQuery.ClickEvent ) => {
	event.preventDefault();

	const product_name = prompt_product_name();
	if ( !product_name ) {
		return;
	}

	const tbody = get_tbody_from_event( event );
	if ( tbody.length ) {
		append_row_to_table( product_name, tbody );
	}

	calculate_total_weight();
	set_required_element_ids();
	process_required_elements();
};
