<?php
/**
 * Order linking verification email notification.
 *
 * Sent when a user creates an account and has guest orders
 * that can be linked to their new account after email verification.
 *
 * @package Awesomemotive\Rewardswp\Notifications\Emails
 * @since 1.2.0
 */

namespace Awesomemotive\Rewardswp\Notifications\Emails;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Awesomemotive\Rewardswp\Abstracts\AbstractEmailNotification;

/**
 * Class OrderLinkingVerificationEmail
 *
 * @since 1.2.0
 */
class OrderLinkingVerificationEmail extends AbstractEmailNotification {

	/**
	 * Get the notification name.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'order_linking_verification';
	}

	/**
	 * Get the email title for admin display.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	public function get_title(): string {
		return __( 'Order Linking Verification', 'rewardswp' );
	}

	/**
	 * Get the default email subject.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	protected function get_default_subject(): string {
		return __( 'Verify your email to link your previous orders', 'rewardswp' );
	}

	/**
	 * Get the email context.
	 *
	 * @since 1.2.0
	 *
	 * @return string The email context.
	 */
	public function get_context(): string {
		return 'account';
	}

	/**
	 * Get the recipient type.
	 *
	 * @since 1.2.0
	 *
	 * @return string The recipient type.
	 */
	public function get_recipient_type(): string {
		return 'member';
	}

	/**
	 * Get the email description.
	 *
	 * @since 1.2.0
	 *
	 * @return string The email description.
	 */
	public function get_description(): string {
		return __( 'Sent when a user creates an account and has previous guest orders that can be linked', 'rewardswp' );
	}

	/**
	 * Get the HTML email template.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	protected function get_default_html_template(): string {
		ob_start();
		?>

		<!-- Header -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 0 0 16px 0;">
			<tr>
				<td style="text-align: center;">
					<h2 style="margin: 0 0 16px 0; font-size: 28px; font-weight: bold; line-height: 1.3; color: #2c3e50;"><?php esc_html_e( 'Link Your Previous Orders', 'rewardswp' ); ?></h2>
					<p style="margin: 0 0 16px 0; color: #2c3e50; line-height: 1.6;"><?php esc_html_e( 'We found {order_count} order(s) associated with your email address from before you created your account. Verify your email to link them.', 'rewardswp' ); ?></p>
				</td>
			</tr>
		</table>

		<!-- Verification Button -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 32px 0;">
			<tr>
				<td align="center">
					<a href="{verification_url}" style="background-color: {{brand_color}} !important; color: {{brand_text_color}} !important; text-decoration: none !important; font-weight: bold !important; font-size: 16px !important; display: inline-block !important; padding: 14px 28px !important; line-height: 1.4 !important; border-radius: 8px !important; mso-padding-alt: 0; text-underline-color: {{brand_color}};">
						<!--[if mso]>
						<i style="mso-font-width: -100%; mso-text-raise: 30pt;">&nbsp;</i>
						<![endif]-->
						<span style="mso-text-raise: 15pt;">
							<?php esc_html_e( 'Verify & Link My Orders', 'rewardswp' ); ?>
						</span>
						<!--[if mso]>
						<i style="mso-font-width: -100%;">&nbsp;</i>
						<![endif]-->
					</a>
				</td>
			</tr>
		</table>

		<!-- Expiration notice -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 24px 0;">
			<tr>
				<td style="text-align: center;">
					<div style="font-size: 14px; color: #6b7280; line-height: 1.6;">
						<?php
						printf(
							/* translators: %s: Number of hours until link expires */
							esc_html__( 'This verification link expires in %s hours.', 'rewardswp' ),
							'{expiration_hours}'
						);
						?>
					</div>
				</td>
			</tr>
		</table>

		<!-- Security notice -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 16px 0 0 0;">
			<tr>
				<td style="text-align: center;">
					<div style="font-size: 13px; color: #9ca3af; line-height: 1.6;">
						<?php esc_html_e( 'If you didn\'t create an account with us, you can safely ignore this email.', 'rewardswp' ); ?>
					</div>
				</td>
			</tr>
		</table>

		<?php
		return ob_get_clean();
	}

	/**
	 * Get the plain text email template.
	 *
	 * @since 1.2.0
	 *
	 * @return string
	 */
	protected function get_plain_text_template(): string {
		$output  = __( 'Link Your Previous Orders', 'rewardswp' ) . PHP_EOL . PHP_EOL;
		$output .= __( 'We found {order_count} order(s) associated with your email address from before you created your account. Verify your email to link them.', 'rewardswp' ) . PHP_EOL . PHP_EOL;
		$output .= __( 'Verify and link your orders:', 'rewardswp' ) . PHP_EOL . PHP_EOL;
		$output .= '{verification_url}' . PHP_EOL . PHP_EOL;
		/* translators: %s: Number of hours until link expires */
		$output .= sprintf( __( 'This verification link expires in %s hours.', 'rewardswp' ), '{expiration_hours}' ) . PHP_EOL . PHP_EOL;
		$output .= __( 'If you didn\'t create an account with us, you can safely ignore this email.', 'rewardswp' );

		return $output;
	}

	/**
	 * Get merge tag definitions for admin UI.
	 *
	 * @since 1.2.0
	 *
	 * @return array Array of merge tag definitions.
	 */
	public function get_merge_tag_definitions(): array {
		return [
			[
				'tag'         => 'user_name',
				'label'       => __( 'User Name', 'rewardswp' ),
				'description' => __( 'The name of the user receiving the email.', 'rewardswp' ),
				'example'     => 'John Doe',
			],
			[
				'tag'         => 'verification_url',
				'label'       => __( 'Verification URL', 'rewardswp' ),
				'description' => __( 'The link to verify and link orders.', 'rewardswp' ),
				'example'     => home_url( 'rewardswp-verify-orders/123/abc123' ),
			],
			[
				'tag'         => 'order_count',
				'label'       => __( 'Order Count', 'rewardswp' ),
				'description' => __( 'Number of guest orders found for this email.', 'rewardswp' ),
				'example'     => '3',
			],
			[
				'tag'         => 'expiration_hours',
				'label'       => __( 'Expiration Hours', 'rewardswp' ),
				'description' => __( 'Hours until the verification link expires.', 'rewardswp' ),
				'example'     => '48',
			],
			[
				'tag'         => 'site_url',
				'label'       => __( 'Site URL', 'rewardswp' ),
				'description' => __( 'Link to your store homepage.', 'rewardswp' ),
				'example'     => home_url(),
			],
		];
	}
}

