<?php
/**
 * This file renders one <tr> of the "all versions of this file" table.
 *
 * @since 1.5.3
 */

switch( $version['type'] ) {
	case 'current':
		$type = $this->lang['current_file'];
		$row_actions = '';
		break;
	case 'historical':
		$type = $this->lang['historical_file'];
		$row_actions = sprintf( '<a href="" class="restore-historical" data-file-version="%2$s">%1$s</a>', __( 'Restore previous version', 'boldgrid-backup' ), $version['name'] );
		break;
	case 'in_archives':
		$type = $this->lang['archive_file'];
		$row_actions = sprintf( '<a href="" class="restore">%1$s</a>', __( 'Restore from archive', 'boldgrid-backup' ) );
		break;
	default:
		$type = __( 'Unknown', 'boldgrid-backup' );
		$row_actions = '';
}

$version_td = '<td></td>';
$tr_class = '';
if( $version['lastmodunix'] !== $last_modified ) {
	$version_number++;
	$last_modified = $version['lastmodunix'];
	$tr_class = 'top';

	$version_td = sprintf( '<td><strong>%1$s</strong>.</td>', $version_number );
}

return sprintf( '
				<tr data-filename="%5$s" class="%8$s">
					%6$s
					<td>
						<strong>%1$s</strong>
						<div class="row-actions">%4$s</div>
					</td>
					<td>%7$s</td>
					<td>%2$s</td>
					<td>%3$s</td>
				</tr>',
	// 1. Type.
	$type,
	// 2. Last modified.
	sprintf(
		'<strong>%1$s %3$s</strong> <em>(%2$s)</em>',
		human_time_diff( $version['lastmodunix'], time() ),
		date( 'M j @ h:i a', $version['lastmodunix'] ),
		__( 'ago', 'boldgrid-backup' )
	),
	// date( 'M j, Y h:i:s a', $version['lastmodunix'] ),
	// 3. Size.
	Boldgrid_Backup_Admin_Utility::bytes_to_human( $version['size'] ),
	// 4. Row actions (restore/etc).
	$row_actions,
	// 5. Path to zip file.
	! empty( $version['archive_filepath'] ) ? basename( $version['archive_filepath'] ) : '',
	// 6. The version number.
	$version_td,
	// 7. Created.
	empty( $version['created'] ) ? '' : sprintf(
		'<strong>%1$s %3$s</strong> <em>(%2$s)</em>',
		human_time_diff( $version['created'], time() ),
		date( 'M j @ h:i a', $version['created'] ),
		__( 'ago', 'boldgrid-backup' )
	),
	// 8. Class applied to the tr.
	$tr_class
);

?>