<?php

/**
 * Customer auto-downgrade email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-auto-downgrade.php.
 *
 * @package ArraySubs\Features\Emails\templates
 * @version 1.7.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__('Your subscription #%s has been automatically updated to a new plan.', 'arraysubs'),
        esc_html($arraysubs_subscription_id)
    );
    ?>
</p>

<h2>
    <?php
    printf(
        /* translators: %s: Subscription ID */
        esc_html__('Subscription #%s', 'arraysubs'),
        esc_html($arraysubs_subscription_id)
    );
    ?>
</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('Previous Plan', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left;">
                <?php
                if ($arraysubs_old_product) {
                    echo esc_html(arraysubs_get_subscription_product_name($arraysubs_old_product));
                } else {
                    echo esc_html('#' . $arraysubs_old_product_id);
                }
                ?>
            </td>
        </tr>
        <tr>
            <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('New Plan', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left; font-weight: bold;">
                <?php
                if ($arraysubs_new_product) {
                    echo esc_html(arraysubs_get_subscription_product_name($arraysubs_new_product));
                } else {
                    echo esc_html('#' . $arraysubs_new_product_id);
                }
                ?>
            </td>
        </tr>
        <tr>
            <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Status', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left; color: #27ae60; font-weight: bold;">
                <?php esc_html_e('Active', 'arraysubs'); ?>
            </td>
        </tr>
        <?php
        $arraysubs_next_payment = get_post_meta($arraysubs_subscription_id, '_next_payment_date', true);
        if (!empty($arraysubs_next_payment)) :
        ?>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Next Payment', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">
                    <?php echo esc_html(arraysubs_format_date_local($arraysubs_next_payment)); ?>
                </td>
            </tr>
        <?php endif; ?>
    </tbody>
</table>

<p><?php esc_html_e('Your subscription has been automatically adjusted to keep your access active. No action is needed on your part.', 'arraysubs'); ?></p>

<p>
    <a class="link" href="<?php echo esc_url(wc_get_account_endpoint_url('subscriptions')); ?>" style="font-weight: bold;">
        <?php esc_html_e('View Your Subscription', 'arraysubs'); ?>
    </a>
</p>

<?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);
