<?php

/**
 * Customer renewal reminder 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";

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)
    );
}
echo "\n\n";

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

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

$arraysubs_recurring_amount = get_post_meta($arraysubs_subscription_id, '_recurring_amount', true);
/* translators: %s: renewal amount */
printf(
    /* translators: %s: renewal amount */
    esc_html__('Renewal Amount: %s', 'arraysubs'),
    esc_html(wp_strip_all_tags(wc_price($arraysubs_recurring_amount)))
);
echo "\n";

printf(
    /* translators: 1: date label, 2: date value */
    esc_html__('%1$s: %2$s', 'arraysubs'),
    esc_html($arraysubs_context_date_label),
    esc_html($arraysubs_context_date)
);
echo "\n";

$arraysubs_payment_method_title = get_post_meta($arraysubs_subscription_id, '_payment_method_title', true);
/* translators: %s: payment method name */
printf(
    /* translators: %s: payment method name */
    esc_html__('Payment Method: %s', 'arraysubs'),
    esc_html($arraysubs_payment_method_title ?: __('N/A', 'arraysubs'))
);
echo "\n\n";

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');
}
echo "\n\n";

/* translators: %s: URL to manage subscriptions in customer account */
printf(esc_html__('Manage your subscription: %s', 'arraysubs'), esc_url(wc_get_account_endpoint_url('subscriptions')));
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')));
