<?php

/**
 * Subscription Expired Email
 *
 * Sent to customers when their subscription expires (reaches end date).
 *
 * @package ArraySubs\Features\Emails\Emails
 * @since 1.0.0
 */

namespace ArraySubs\Features\Emails\Emails;

defined('ABSPATH') || exit;

use ArraySubs\Features\Emails\Abstracts\BaseSubscriptionEmail;

/**
 * Subscription Expired Email class
 */
class SubscriptionExpiredEmail extends BaseSubscriptionEmail
{
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->id             = 'arraysubs_subscription_expired';
        $this->customer_email = true;
        $this->title          = __('[ArraySubs] Subscription Expired', 'arraysubs');
        $this->description    = __('Subscription expired emails are sent to customers when their subscription reaches its end date.', 'arraysubs');

        $this->heading        = __('Your subscription has expired', 'arraysubs');
        $this->subject        = __('[{site_title}] Your subscription #{subscription_id} has expired', 'arraysubs');

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

        // Add expiration placeholders with sample values for preview
        $this->placeholders['{expiration_date}'] = \arraysubs_format_timestamp_local(
            \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);

        $this->placeholders['{expiration_date}'] = arraysubs_format_date_local(
            get_post_meta($this->subscription_id, '_end_date', true) ?: \current_time('mysql', true)
        );
    }

    /**
     * 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_expiration_date'] = get_post_meta($this->subscription_id, '_end_date', true);
        return $args;
    }

    /**
     * Get default additional content
     *
     * @return string
     */
    public function get_default_additional_content(): string
    {
        return __('Your subscription term has ended. Visit our store to subscribe again and continue enjoying our services.', 'arraysubs');
    }
}
