<?php

/**
 * Customer renewal invoice email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-renewal-invoice.php.
 *
 * @package ArraySubs\Features\Emails\templates
 * @version 1.0.0
 */

defined('ABSPATH') || exit;

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce core hook
do_action('woocommerce_email_header', $arraysubs_email_heading, $arraysubs_email);
?>

<p>
<?php
    printf(
        /* translators: %s: Customer first name */
        esc_html__('Hi %s,', 'arraysubs'),
        esc_html($arraysubs_customer['first_name'] ?: __('there', 'arraysubs'))
    );
    ?>
    </p>

<p>
<?php
    printf(
        /* translators: %s: subscription ID */
        esc_html__('A renewal order has been created for your subscription #%s.', 'arraysubs'),
        esc_html($arraysubs_subscription_id)
    );
    ?>
    </p>

<?php if ($arraysubs_order) : ?>
    <h2>
    <?php
        printf(
            /* translators: %s: Order ID */
            esc_html__('Order #%s', 'arraysubs'),
            esc_html($arraysubs_order->get_order_number())
        );
        ?>
        </h2>

    <table class="td" cellspacing="0" cellpadding="6" style="width: 100%; margin-bottom: 40px;" border="1">
        <tbody>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Subscription', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">#<?php echo esc_html($arraysubs_subscription_id); ?></td>
            </tr>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Product', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">
                    <?php
                    $arraysubs_product_id = get_post_meta($arraysubs_subscription_id, '_product_id', true);
                    $arraysubs_product = wc_get_product($arraysubs_product_id);
                    echo esc_html($arraysubs_product ? $arraysubs_product->get_name() : __('N/A', 'arraysubs'));
                    ?>
                </td>
            </tr>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Amount', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">
                    <?php echo wp_kses_post($arraysubs_order->get_formatted_order_total()); ?>
                </td>
            </tr>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Due Date', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">
                    <?php
                    $arraysubs_next_payment = get_post_meta($arraysubs_subscription_id, '_next_payment_date', true);
                    echo esc_html(arraysubs_format_date_local($arraysubs_next_payment));
                    ?>
                </td>
            </tr>
        </tbody>
    </table>

    <?php if ($arraysubs_order->needs_payment()) : ?>
        <p>
            <a class="link" href="<?php echo esc_url($arraysubs_order->get_checkout_payment_url()); ?>" style="font-weight: bold;">
                <?php esc_html_e('Pay for this order', 'arraysubs'); ?>
            </a>
        </p>
    <?php endif; ?>

<?php endif; ?>

<?php
if ($arraysubs_additional_content) {
    echo wp_kses_post(wpautop(wptexturize($arraysubs_additional_content)));
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce core hook
do_action('woocommerce_email_footer', $arraysubs_email);
