<?php
/**
 * Value Reinforcement Abandoned Cart email template.
 *
 * @package EDD\Pro\CartRecovery\Emails\Templates
 * @copyright Copyright (c) 2026, Sandhills Development, LLC
 * @license https://opensource.org/licenses/GPL-2.0 GNU Public License
 * @since 3.6.5
 */

namespace EDD\Pro\CartRecovery\Emails\Templates;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

/**
 * Class ValueReinforcement
 *
 * @since 3.6.5
 * @package EDD\Pro\CartRecovery\Emails\Templates
 */
class ValueReinforcement extends Base {

	/**
	 * Unique identifier for this template.
	 *
	 * @since 3.6.5
	 * @var string
	 */
	protected $email_id = 'edd-pro-acr-vr';

	/**
	 * The email meta.
	 *
	 * @var array
	 */
	protected $meta = array(
		'delay'         => 24 * HOUR_IN_SECONDS,
		'unit'          => HOUR_IN_SECONDS,
		'discount_code' => '',
	);

	/**
	 * Name of the template.
	 *
	 * @since 3.6.5
	 * @return string
	 */
	public function get_name() {
		return __( 'Value Reinforcement', 'easy-digital-downloads' );
	}

	/**
	 * Description of the email.
	 *
	 * @since 3.6.5
	 * @return string
	 */
	public function get_description() {
		$hours = $this->get_metadata( 'delay' );

		/* translators: %s: number of hours */
		return sprintf( _n( 'Sent %s after the cart is abandoned to reinforce value and encourage completion. Personalize with HTML and <code>{tag}</code> markers.', 'Sent %s after the cart is abandoned to reinforce value and encourage completion. Personalize with HTML and <code>{tag}</code> markers.', absint( $hours / HOUR_IN_SECONDS ), 'easy-digital-downloads' ), absint( $hours / HOUR_IN_SECONDS ) );
	}

	/**
	 * Gets the context label.
	 *
	 * @since 3.6.5
	 * @return string
	 */
	public function get_context_label(): string {
		$hours = $this->get_metadata( 'delay' );

		/* translators: %s: number of hours */
		return sprintf( _n( '%s hour after the cart is abandoned', '%s hours after the cart is abandoned', absint( $hours / HOUR_IN_SECONDS ), 'easy-digital-downloads' ), absint( $hours / HOUR_IN_SECONDS ) );
	}

	/**
	 * Define the default email properties.
	 *
	 * @since 3.6.5
	 * @return array
	 */
	public function defaults(): array {
		return array(
			'subject' => __( 'Still thinking it over?', 'easy-digital-downloads' ),
			'heading' => __( 'Your Cart is Still Available', 'easy-digital-downloads' ),
			'content' => $this->get_default_content(),
			'status'  => 1,
		);
	}

	/**
	 * Gets the default email body content.
	 *
	 * @since 3.6.5
	 * @return string
	 */
	protected function get_default_content(): string {
		$content = '<p>' . sprintf(
			/* translators: %s: Customer first name */
			__( 'Hi %s,', 'easy-digital-downloads' ),
			'{customer_firstname}'
		) . '</p>';

		$content .= '<p>' . __( 'You still have items waiting in your cart. We wanted to make sure you didn\'t forget about them.', 'easy-digital-downloads' ) . '</p>';

		$content .= '<h3>' . __( 'Your Cart', 'easy-digital-downloads' ) . '</h3>';
		$content .= '{cart_items}';

		$content .= '<p><strong>' . __( 'Total:', 'easy-digital-downloads' ) . '</strong> {cart_total}</p>';

		$content .= '<p>' . __( 'If you have any questions before completing your purchase, we\'re here to help. Just reply to this email.', 'easy-digital-downloads' ) . '</p>';

		$content .= $this->get_default_cart_link();

		$content .= '<p>' . __( 'Best regards,', 'easy-digital-downloads' ) . '<br>';
		$content .= '{sitename}</p>';

		$content .= $this->get_unsubscribe_content();

		return $content;
	}
}
