<?php

namespace MovieEngine\Emails\Types;

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

use MovieEngine\Emails\EmailBase;

class ReferralSaleEmail extends EmailBase {
    public function trigger($user, $args = [], $custom_to = '') {
        $amount = $args['amount'] ?? 0;
        $subject = sprintf(
            /* translators: 1: formatted commission amount */
            __('You earned a new commission of $%s!', 'cine-movie-engine'),
            number_format($amount, 2)
        );

        $data = [
            'user_name' => $user->display_name,
            'amount' => number_format($amount, 2),
            'dashboard_link' => home_url('/dashboard'),
            'site_name' => get_bloginfo('name')
        ];

        $to = !empty($custom_to) ? $custom_to : $user->user_email;
        return $this->send($to, $subject, 'referral-sale', $data);
    }
}
