<?php

/**
 * Subscription Reactivated Email
 *
 * Sent to customers when their subscription is reactivated after being on hold or cancelled.
 *
 * @package ArraySubs\Features\Emails\Emails
 * @since 1.0.0
 */

namespace ArraySubs\Features\Emails\Emails;

defined('ABSPATH') || exit;

use ArraySubs\Features\Emails\Abstracts\BaseSubscriptionEmail;

/**
 * Subscription Reactivated Email class
 */
class SubscriptionReactivatedEmail extends BaseSubscriptionEmail
{
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->id             = 'arraysubs_subscription_reactivated';
        $this->customer_email = true;
        $this->title          = __('[ArraySubs] Subscription Reactivated', 'arraysubs');
        $this->description    = __('Subscription reactivated emails are sent to customers when their subscription is reactivated.', 'arraysubs');

        $this->heading        = __('Your subscription has been reactivated!', 'arraysubs');
        $this->subject        = __('[{site_title}] Your subscription for {product_name} has been reactivated', 'arraysubs');

        $this->template_html  = 'customer-subscription-reactivated.php';
        $this->template_plain = 'plain/customer-subscription-reactivated.php';

        // Add reactivated placeholders with sample values for preview
        $this->placeholders['{next_payment_date}'] = \arraysubs_format_timestamp_local(
            strtotime('+1 month', \current_time('timestamp', true)),
            \get_option('date_format')
        );

        parent::__construct();
    }

    /**
     * Populate placeholders
     *
     * @param array $args Additional arguments
     */
    protected function populate_placeholders(array $args = []): void
    {
        parent::populate_placeholders($args);

        $next_payment = get_post_meta($this->subscription_id, '_next_payment_date', true);

        $this->placeholders['{next_payment_date}'] = !empty($next_payment)
            ? \arraysubs_format_date_local($next_payment)
            : __('N/A', 'arraysubs');
    }

    /**
     * Get template arguments
     *
     * @param bool $plain_text Whether this is plain text email
     * @return array
     */
    protected function get_template_args(bool $plain_text = false): array
    {
        $args = parent::get_template_args($plain_text);
        $args['arraysubs_next_payment_date'] = get_post_meta($this->subscription_id, '_next_payment_date', true);
        return $args;
    }

    /**
     * Get default additional content
     *
     * @return string
     */
    public function get_default_additional_content(): string
    {
        return __('Your subscription is now active again and you will be charged on your next payment date.', 'arraysubs');
    }
}
