<?php
/**
 * Welcome member points email notification.
 *
 * @package Awesomemotive\Rewardswp\Notifications\Emails
 * @since 1.1.0
 */

namespace Awesomemotive\Rewardswp\Notifications\Emails;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractEmailNotification;
use function Awesomemotive\Rewardswp\Helpers\format_points_with_label;
use function Awesomemotive\Rewardswp\Helpers\get_points_currency_plural;
use function Awesomemotive\Rewardswp\Helpers\get_points_currency_singular;

/**
 * Email notification for welcome member points.
 *
 * @since 1.1.0
 */
class WelcomeMemberPointsEmail extends AbstractEmailNotification {

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

	/**
	 * Get the email subject.
	 *
	 * @since 1.1.0
	 *
	 * @return string
	 */
	protected function get_default_subject(): string {
		return __( 'Welcome to our Rewards Program! Your bonus points are here', 'rewardswp' );
	}

	/**
	 * Get the HTML email template.
	 *
	 * @since 1.1.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( 'Welcome to Our Rewards Program!', 'rewardswp' ); ?></h2>
					<p style="margin: 0 0 16px 0; color: #2c3e50; line-height: 1.6;"><?php esc_html_e( 'You\'re in! Here\'s a welcome bonus to get you started.', 'rewardswp' ); ?></p>
				</td>
			</tr>
		</table>

		<!-- Welcome bonus -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 24px 0 24px 0;">
			<tr>
				<td>
					<div style="border: 1px solid #d1d5db; border-radius: 8px; padding: 16px 20px; text-align: center; font-size: 24px; font-weight: bold; color: #2c3e50;">
						{points_earned_formatted}
					</div>
				</td>
			</tr>
		</table>

		<!-- Button -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 32px 0;">
			<tr>
				<td align="center">
					<a href="{site_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( 'Browse Rewards', 'rewardswp' ); ?>
						</span>
						<!--[if mso]>
						<i style="mso-font-width: -100%;">&nbsp;</i>
						<![endif]-->
					</a>
				</td>
			</tr>
		</table>

		<!-- Balance -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 0 0 16px 0;">
			<tr>
				<td style="text-align: center; padding: 8px 0;">
					<span style="font-size: 14px; color: #7f8c8d;"><?php esc_html_e( 'Balance:', 'rewardswp' ); ?></span>
					<span style="font-size: 14px; font-weight: bold; color: #2c3e50;"> {current_balance_formatted}</span>
				</td>
			</tr>
		</table>

		<!-- Footer message -->
		<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="width: 100%; margin: 24px 0 0 0;">
			<tr>
				<td style="text-align: center;">
					<div style="font-size: 14px; color: #7f8c8d; line-height: 1.6;">
						<?php esc_html_e( 'Welcome aboard! We look forward to rewarding your loyalty.', 'rewardswp' ); ?>
					</div>
				</td>
			</tr>
		</table>
		
		<?php
		return ob_get_clean();
	}

	/**
	 * Get the plain text email template.
	 *
	 * @since 1.1.0
	 *
	 * @return string
	 */
	protected function get_plain_text_template(): string {
		return __(
			'Welcome to Our Rewards Program!

You\'re in! Here\'s a welcome bonus to get you started.

{points_earned_formatted}

Balance: {current_balance_formatted}

Browse rewards: {site_url}

Welcome aboard! We look forward to rewarding your loyalty.',
			'rewardswp'
		);
	}

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

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

	/**
	 * Get the email description.
	 *
	 * @since 1.1.0
	 *
	 * @return string The email description.
	 */
	public function get_description(): string {
		return __( 'Sent to new members when they earn welcome bonus points', 'rewardswp' );
	}

	/**
	 * Get merge tag definitions for admin UI.
	 *
	 * @since 1.1.0
	 *
	 * @return array Array of merge tag definitions.
	 */
	public function get_merge_tag_definitions(): array {
		return [
			[
				'tag'         => 'member_name',
				'label'       => __( 'Member First Name', 'rewardswp' ),
				'description' => __( 'First name of the member.', 'rewardswp' ),
				'example'     => 'John',
			],
			[
				'tag'         => 'member_full_name',
				'label'       => __( 'Member Full Name', 'rewardswp' ),
				'description' => __( 'Full name of the member.', 'rewardswp' ),
				'example'     => 'John Doe',
			],
			[
				'tag'         => 'points_earned',
				'label'       => __( 'Points Earned (Number)', 'rewardswp' ),
				'description' => __( 'Welcome bonus points granted (number only).', 'rewardswp' ),
				'example'     => '50',
			],
			[
				'tag'         => 'points_earned_formatted',
				'label'       => __( 'Points Earned (Formatted)', 'rewardswp' ),
				'description' => __( 'Welcome bonus points with correct singular/plural label.', 'rewardswp' ),
				'example'     => format_points_with_label( 50 ),
			],
			[
				'tag'         => 'current_balance',
				'label'       => __( 'Current Balance (Number)', 'rewardswp' ),
				'description' => __( 'Member\'s current points balance (number only).', 'rewardswp' ),
				'example'     => '150',
			],
			[
				'tag'         => 'current_balance_formatted',
				'label'       => __( 'Current Balance (Formatted)', 'rewardswp' ),
				'description' => __( 'Member\'s current points balance with correct singular/plural label.', 'rewardswp' ),
				'example'     => format_points_with_label( 150 ),
			],
			[
				'tag'         => 'currency_singular',
				'label'       => __( 'Currency Label (Singular)', 'rewardswp' ),
				'description' => __( 'Points currency label in singular form.', 'rewardswp' ),
				'example'     => get_points_currency_singular(),
			],
			[
				'tag'         => 'currency_plural',
				'label'       => __( 'Currency Label (Plural)', 'rewardswp' ),
				'description' => __( 'Points currency label in plural form.', 'rewardswp' ),
				'example'     => get_points_currency_plural(),
			],
			[
				'tag'         => 'site_url',
				'label'       => __( 'Site URL', 'rewardswp' ),
				'description' => __( 'Link to your store homepage.', 'rewardswp' ),
				'example'     => home_url(),
			],
		];
	}
}
