<?php

namespace MovieEngine\Emails\Types;

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

use MovieEngine\Emails\EmailBase;

class AdminSaleEmail extends EmailBase {
    public function trigger($user, $transaction, $custom_to = '') {
        $subject = sprintf(
            /* translators: 1: sale amount */
            __('New Sale: %1$s received!', 'cine-movie-engine'),
            $transaction->amount
        );
        $item_name = get_the_title($transaction->item_id);
        $currency_symbol = $transaction->currency === 'USD' ? '$' : $transaction->currency;

        $data = [
            'user_name'      => $user->display_name,
            'item_name'      => $item_name,
            'amount'         => $currency_symbol . $transaction->amount,
            'transaction_id' => $transaction->transaction_id,
            'site_name'      => get_bloginfo('name')
        ];

        $to = !empty($custom_to) ? $custom_to : ($this->options['admin_emails'] ?? get_option('admin_email'));
        return $this->send($to, $subject, 'admin_sale', $data);
    }
}
