import $ from 'jquery';
import { get_updated_dimensions } from './get_updated_dimensions';

/**
 * Constructs request data for updating order items in the server.
 *
 * @param {string} order_id - The ID of the order to update.
 * @param {JQuery<HTMLFormElement>} form
 *
 * @returns {RequestData} - The constructed request data.
 */
export const get_request_data = ( order_id: string, form: JQuery<HTMLFormElement> ): RequestData => {
	const table = form.find( $( 'table' ) );
	const updated_dimensions = get_updated_dimensions( table );

	let total_order_weight = $( '#total_order_weight' ).val() as string | undefined;
	if ( !total_order_weight ) {
		total_order_weight = '';
	}

	return {
		action: 'wetail_shipping_update_order_items',
		order_id,
		updated_dimensions,
		total_order_weight,
	};
};
