import $ from 'jquery';

export const handle_print_label_success_response = ( response: any, order_id: string ) => {
	if ( response && !response.error && response.data ) {
		if ( $( `.order-${ order_id }` ).length === 0 ) {
			return;
		}

		const printIcon = $( `.order-${ order_id } .wetail_shipping_engine.column-wetail_shipping_engine .printExistingShippingLabel` );
		const returnIcon = $( `.order-${ order_id } .wetail_shipping_engine.column-wetail_shipping_engine .printReturnLabel` );

		if ( !printIcon.hasClass('wetail-shipping-engine-button--visible') ) {
			printIcon.addClass( 'wetail-shipping-engine-button--visible' );
		}

		if ( !returnIcon.hasClass('wetail-shipping-engine-button--visible') ) {
			returnIcon.addClass( 'wetail-shipping-engine-button--visible' );
		}

		const error = $( `.order-${ order_id } .wetail_shipping_engine.column-wetail_shipping_engine .wetail-shipping-engine-icon--error-visible` );

		if ( error.length > 0 ) {
			error.removeClass( 'wetail-shipping-engine-icon--error-visible' );
		}
	}
};
