<?php
/**
 * Helper for handling email tags.
 *
 * @package     EDD\Pro\CampaignTracker\Emails
 * @copyright   Copyright (c) 2025, Sandhills Development, LLC
 * @license     https://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       3.6.3
 */

namespace EDD\Pro\CampaignTracker\Emails;

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

use EDD\Pro\CampaignTracker\Admin\Orders\Details\Campaign;
use EDD\EventManagement\SubscriberInterface;

/**
 * Email Tags Class.
 *
 * @since 3.6.3
 */
class EmailTags implements SubscriberInterface {

	/**
	 * Campaign instance.
	 *
	 * @since 3.6.3
	 * @var Campaign
	 */
	private $campaign;

	/**
	 * Returns an array of events that this subscriber wants to listen to.
	 *
	 * @since 3.6.3
	 * @return array
	 */
	public static function get_subscribed_events() {
		return array(
			'edd_add_email_tags' => 'register_email_tags',
		);
	}

	/**
	 * Constructor.
	 *
	 * @since 3.6.3
	 */
	public function __construct() {
		$this->campaign = new Campaign();
	}

	/**
	 * Register custom email tag.
	 *
	 * @since 3.6.3
	 * @return void
	 */
	public function register_email_tags() {
		edd_add_email_tag(
			'campaign_info',
			__( 'Display Google Analytics Campaign info for this transaction.', 'easy-digital-downloads' ),
			array( $this, 'email_tag_campaign_info' ),
			__( 'Campaign Info', 'easy-digital-downloads' ),
			array( 'order' ),
			array( 'admin' )
		);
	}

	/**
	 * Callback for `campaign_info` email tag.
	 *
	 * @since 3.6.3
	 * @param int $order_id Order ID.
	 * @return string Content for `campaign_info` tag.
	 */
	public function email_tag_campaign_info( $order_id = 0 ) {
		$output = '<h3>' . __( 'Campaign Information', 'easy-digital-downloads' ) . '</h3>';
		return $output . $this->campaign->render_campaign_info( $order_id );
	}
}
