<?php
/**
 * Email Downloads.
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-downloads.php.
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.4.0
 */
defined( 'ABSPATH' ) || exit;
?>
<div class="email-download-list">
    <table class="td" cellspacing="0" cellpadding="6" style="width: 100%;" dir="<?php echo esc_attr( $direction ) ?>"
           border="1">
        <thead>
        <tr>
			<?php foreach ( $columns as $edpw_column_id => $edpw_column_name ) : ?>
                <th class="td" scope="col"
                    style="text-align:<?php echo esc_attr( $direction ); ?>;"><?php echo esc_html( $edpw_column_name ); ?></th>
			<?php endforeach; ?>
        </tr>
        </thead>
        <tbody>
		<?php foreach ( $downloads as $edpw_download ) : ?>
            <tr>
				<?php foreach ( $columns as $edpw_column_id => $edpw_column_name ) : ?>
                    <td class="td" style="text-align:<?php echo esc_attr( $direction ); ?>;">
						<?php
						if ( has_action( 'woocommerce_email_downloads_column_' . $edpw_column_id ) ) {
							//phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
							do_action( 'woocommerce_email_downloads_column_' . $edpw_column_id, $edpw_download, $plain_text );
						} else {
							switch ( $edpw_column_id ) {
								case 'download-product':
									?>
                                    <a href="<?php echo esc_url( get_permalink( $edpw_download['product_id'] ) ); ?>"><?php echo wp_kses_post( $edpw_download['product_name'] ); ?></a>
									<?php
									break;
								case 'download-file':
									?>
                                    <a href="<?php echo esc_url( $edpw_download['download_url'] ); ?>"
                                       class="woocommerce-MyAccount-downloads-file button alt"><?php echo esc_html( $edpw_download['download_name'] ); ?></a>
									<?php
									break;
								case 'download-expires':
									if ( ! empty( $edpw_download['access_expires'] ) ) {
										?>
                                        <time datetime="<?php echo esc_attr( gmdate( 'Y-m-d', strtotime( $edpw_download['access_expires'] ) ) ); ?>"
                                              title="<?php echo esc_attr( strtotime( $edpw_download['access_expires'] ) ); ?>"><?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $edpw_download['access_expires'] ) ) ); ?></time>
										<?php
									} else {
										esc_html_e( 'Never', 'email-editor-plus' );
									}
									break;
							}
						}
						?>
                    </td>
				<?php endforeach; ?>
            </tr>
		<?php endforeach; ?>
        </tbody>
    </table>
</div>