<?php

/**
 * Customer renewal invoice email (plain text)
 *
 * @package ArraySubs\Features\Emails\templates\plain
 * @version 1.0.0
 */

defined('ABSPATH') || exit;

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
echo esc_html(wp_strip_all_tags($arraysubs_email_heading));
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

printf(
    /* translators: %s: Customer first name */
    esc_html__('Hi %s,', 'arraysubs'),
    esc_html($arraysubs_customer['first_name'] ?: __('there', 'arraysubs'))
);
echo "\n\n";

printf(
    /* translators: %s: subscription ID */
    esc_html__('A renewal order has been created for your subscription #%s.', 'arraysubs'),
    esc_html($arraysubs_subscription_id)
);
echo "\n\n";

if ($arraysubs_order) {
    echo "----------\n";
    printf(
        /* translators: %s: Order ID */
        esc_html__('Order #%s', 'arraysubs'),
        esc_html($arraysubs_order->get_order_number())
    );
    echo "\n----------\n\n";

    printf(
        /* translators: %s: subscription ID */
        esc_html__('Subscription: #%s', 'arraysubs'),
        esc_html($arraysubs_subscription_id)
    );
    echo "\n";

    $arraysubs_product_id = get_post_meta($arraysubs_subscription_id, '_product_id', true);
    $arraysubs_product = wc_get_product($arraysubs_product_id);
    printf(
        /* translators: %s: product name */
        esc_html__('Product: %s', 'arraysubs'),
        esc_html($arraysubs_product ? $arraysubs_product->get_name() : __('N/A', 'arraysubs'))
    );
    echo "\n";

    printf(
        /* translators: %s: order amount */
        esc_html__('Amount: %s', 'arraysubs'),
        esc_html(wp_strip_all_tags($arraysubs_order->get_formatted_order_total()))
    );
    echo "\n";

    $arraysubs_next_payment = get_post_meta($arraysubs_subscription_id, '_next_payment_date', true);
    printf(
        /* translators: %s: due date */
        esc_html__('Due Date: %s', 'arraysubs'),
        esc_html(arraysubs_format_date_local($arraysubs_next_payment))
    );
    echo "\n\n";

    if ($arraysubs_order->needs_payment()) {
        printf(
            /* translators: %s: checkout payment URL */
            esc_html__('Pay for this order: %s', 'arraysubs'),
            esc_url($arraysubs_order->get_checkout_payment_url())
        );
        echo "\n\n";
    }
}

if ($arraysubs_additional_content) {
    echo "----------\n\n";
    echo esc_html(wp_strip_all_tags(wptexturize($arraysubs_additional_content)));
    echo "\n\n";
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WooCommerce core hook
echo wp_kses_post(apply_filters('woocommerce_email_footer_text', get_option('woocommerce_email_footer_text')));
