<?php

/**
 * Customer renewal reminder email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-renewal-reminder.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
    if ('trial' === $arraysubs_reminder_context) {
        printf(
            /* translators: %d: days before trial ends */
            esc_html__('Your trial ends in %d days. After the trial ends, your subscription will convert to the paid plan and future renewals will be charged using your saved payment method.', 'arraysubs'),
            absint($arraysubs_days_before)
        );
    } elseif ('expiring' === $arraysubs_reminder_context) {
        printf(
            /* translators: %d: days before subscription ends */
            esc_html__('Your subscription is scheduled to end in %d days. A final invoice may be generated before the subscription ends if a final billing cycle is due.', 'arraysubs'),
            absint($arraysubs_days_before)
        );
    } else {
        printf(
            /* translators: %d: days before renewal */
            esc_html__('This is a friendly reminder that your subscription will renew in %d days.', 'arraysubs'),
            absint($arraysubs_days_before)
        );
    }
    ?>
</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('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('Renewal Amount', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left;">
                <?php
                $arraysubs_recurring_amount = get_post_meta($arraysubs_subscription_id, '_recurring_amount', true);
                echo wp_kses_post(wc_price($arraysubs_recurring_amount));
                ?>
            </td>
        </tr>
        <tr>
            <th class="td" scope="row" style="text-align: left;"><?php echo esc_html($arraysubs_context_date_label); ?></th>
            <td class="td" style="text-align: left;">
                <?php echo esc_html($arraysubs_context_date); ?>
            </td>
        </tr>
        <tr>
            <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Payment Method', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left;">
                <?php
                $arraysubs_payment_method_title = get_post_meta($arraysubs_subscription_id, '_payment_method_title', true);
                echo esc_html($arraysubs_payment_method_title ?: __('N/A', 'arraysubs'));
                ?>
            </td>
        </tr>
    </tbody>
</table>

<p>
    <?php
    if ('trial' === $arraysubs_reminder_context) {
        esc_html_e('Please review your subscription before the trial ends if you want to change or cancel before conversion.', 'arraysubs');
    } elseif ('expiring' === $arraysubs_reminder_context) {
        esc_html_e('No action is required unless you want to renew, change, or extend the subscription before it ends.', 'arraysubs');
    } else {
        esc_html_e('Please make sure the upcoming renewal invoice is paid on time to keep your subscription active.', 'arraysubs');
    }
    ?>
</p>

<p>
    <a class="link" href="<?php echo esc_url(wc_get_account_endpoint_url('subscriptions')); ?>">
        <?php esc_html_e('Manage 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);
