<?php

/**
 * Renewal Invoice Email
 *
 * Sent to customers when a renewal order is created.
 *
 * @package ArraySubs\Features\Emails\Emails
 * @since 1.0.0
 */

namespace ArraySubs\Features\Emails\Emails;

defined('ABSPATH') || exit;

use ArraySubs\Features\Emails\Abstracts\BaseSubscriptionEmail;

/**
 * Renewal Invoice Email class
 */
class RenewalInvoiceEmail extends BaseSubscriptionEmail
{
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->id             = 'arraysubs_renewal_invoice';
        $this->customer_email = true;
        $this->title          = __('[ArraySubs] Renewal Invoice', 'arraysubs');
        $this->description    = __('Renewal invoice emails are sent to customers when a renewal order is created.', 'arraysubs');

        $this->heading        = __('Your renewal order', 'arraysubs');
        $this->subject        = __('[{site_title}] Invoice for subscription #{subscription_id}', 'arraysubs');

        $this->template_html  = 'customer-renewal-invoice.php';
        $this->template_plain = 'plain/customer-renewal-invoice.php';

        // Add order placeholders with sample values for preview
        $this->placeholders['{order_id}'] = '67890';
        $this->placeholders['{order_total}'] = wc_price(29.99);
        $this->placeholders['{order_pay_url}'] = wc_get_checkout_url();

        parent::__construct();
    }

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

        if ($this->order) {
            $this->placeholders['{order_id}'] = $this->order->get_id();
            $this->placeholders['{order_total}'] = $this->order->get_formatted_order_total();
            $this->placeholders['{order_pay_url}'] = $this->order->get_checkout_payment_url();
        }
    }

    /**
     * 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_order_pay_url'] = $this->order ? $this->order->get_checkout_payment_url() : '';
        return $args;
    }

    /**
     * Get default additional content
     *
     * @return string
     */
    public function get_default_additional_content(): string
    {
        return __('Please pay this renewal invoice before the due date to keep your subscription active.', 'arraysubs');
    }
}
