<?php

namespace RadiusTheme\RadiusBooking\Helpers;

class BookingHelper {
	public static function formatMinutesAsReadableTime( $minutes ) {
		$hours = floor( $minutes / 60 );
		$mins  = $minutes % 60;

		$parts = array();

		if ( $hours > 0 ) {
			$parts[] = sprintf(
			/* translators: %d: Number of hours */
				_n( '%d hour', '%d hours', $hours, 'radius-booking' ),
				$hours
			);
		}

		if ( $mins > 0 ) {
			$parts[] = sprintf(
			/* translators: %d: Number of minutes */
				_n( '%d minute', '%d minutes', $mins, 'radius-booking' ),
				$mins
			);
		}

		if ( empty( $parts ) ) {
			return __( '0 minutes', 'radius-booking' );
		}

		/* translators: Used to join hours and minutes, e.g., "2 hours and 30 minutes" */

		return implode( __( ' and ', 'radius-booking' ), $parts );
	}
}