<?php
/**
 * Immediate Recovery 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;

/**
 * The first recovery email sent after a cart is abandoned.
 */
class ImmediateRecovery extends Base {

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

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

	/**
	 * Gets the template name.
	 *
	 * @return string
	 */
	public function get_name() {
		return __( 'Immediate Recovery', 'easy-digital-downloads' );
	}

	/**
	 * Gets the template description.
	 *
	 * @return string
	 */
	public function get_description() {
		return __( 'The first email sent after a cart is considered abandoned. This is your first and best chance to recover the sale.', 'easy-digital-downloads' );
	}

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

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

	/**
	 * Gets the default template settings.
	 *
	 * @return array
	 */
	public function defaults(): array {
		return array(
			'subject' => __( 'You left something behind', 'easy-digital-downloads' ),
			'heading' => __( 'Your Cart is Saved', 'easy-digital-downloads' ),
			'content' => $this->get_default_content(),
			'status'  => 1,
		);
	}

	/**
	 * Gets the default email body content using the modern merge tags.
	 *
	 * @return string
	 */
	protected function get_default_content(): string {
		/* translators: %s: Customer first name */
		$content  = '<p>' . sprintf( __( 'Hi %s,', 'easy-digital-downloads' ), '{customer_firstname}' ) . '</p>';
		$content .= '<p>' . __( 'It looks like you didn\'t finish checking out. No worries — we saved your cart and it\'s ready whenever you are.', '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 .= $this->get_default_cart_link();
		$content .= '<p>' . __( 'If you ran into any trouble during checkout, just reply to this email and we\'ll be happy to help.', 'easy-digital-downloads' ) . '</p>';
		$content .= '<p>' . __( 'Best,', 'easy-digital-downloads' ) . '<br>{sitename}</p>';
		$content .= $this->get_unsubscribe_content();

		return $content;
	}
}
