<?php

namespace MovieEngine\Emails\Types;

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

use MovieEngine\Emails\EmailBase;

class WelcomeEmail extends EmailBase {
    public function trigger($user, $plan_id = null, $custom_to = '') {
        $subject = sprintf(
            /* translators: 1: site name */
            esc_html__('Welcome to %1$s!', 'cine-movie-engine'),
            get_bloginfo('name')
        );
        $plan_name = $plan_id ? get_the_title($plan_id) : esc_html__('Free Account', 'cine-movie-engine');

        $design_settings = get_option('movie_engine_design_settings', []);
        $browse_page_id = $design_settings['browse_page'] ?? 0;
        $dashboard_page_id = $design_settings['dashboard_page'] ?? 0;

        $browse_url = $browse_page_id ? get_permalink($browse_page_id) : home_url('/browse');
        $dashboard_url = $dashboard_page_id ? get_permalink($dashboard_page_id) : home_url('/dashboard');

        $data = [
            'user_name' => $user->display_name,
            'plan_name' => $plan_name,
            'browse_url' => $browse_url,
            'dashboard_url' => $dashboard_url,
            'site_name' => get_bloginfo('name')
        ];

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