<?php

/**
 * Customer payment failed email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-payment-failed.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__('Unfortunately, the renewal payment for your subscription #%s could not be completed.', 'arraysubs'),
        esc_html($arraysubs_subscription_id)
    );
    ?>
</p>

<?php if (!empty($arraysubs_failure_reason_text)) : ?>
    <p style="background: #fff3cd; padding: 10px 14px; border-left: 4px solid #e74c3c; margin: 0 0 16px;">
        <?php echo esc_html($arraysubs_failure_reason_text); ?>
    </p>
<?php endif; ?>

<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>
        <?php if ($arraysubs_order) : ?>
            <tr>
                <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Amount Due', 'arraysubs'); ?></th>
                <td class="td" style="text-align: left;">
                    <?php echo wp_kses_post($arraysubs_order->get_formatted_order_total()); ?>
                </td>
            </tr>
        <?php endif; ?>
        <tr>
            <th class="td" scope="row" style="text-align: left;"><?php esc_html_e('Status', 'arraysubs'); ?></th>
            <td class="td" style="text-align: left;">
                <?php echo esc_html($arraysubs_subscription_status); ?>
            </td>
        </tr>
    </tbody>
</table>

<p style="color: #e74c3c; font-weight: bold;">
    <?php esc_html_e('Please review the order and complete payment to avoid service interruption.', 'arraysubs'); ?>
</p>

<?php if (!empty($arraysubs_retry_url)) : ?>
    <p>
        <a class="link" href="<?php echo esc_url($arraysubs_retry_url); ?>" style="font-weight: bold; background: #e74c3c; color: #fff; padding: 10px 20px; text-decoration: none; display: inline-block; margin: 10px 0;">
            <?php esc_html_e('Pay Now', 'arraysubs'); ?>
        </a>
    </p>
<?php endif; ?>

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