<?php

namespace MovieEngine\Emails\Types;

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

use MovieEngine\Emails\EmailBase;

class SecurityEmail extends EmailBase {
    public function trigger($user, $login_data) {
        $subject = sprintf(
            /* translators: 1: site name */
            __('New Login to %1$s', 'cine-movie-engine'),
            get_bloginfo('name')
        );

        $design_options = get_option('movie_engine_design_settings', []);
        $dashboard_id = !empty($design_options['dashboard_page']) ? $design_options['dashboard_page'] : 0;
        $dashboard_url = $dashboard_id ? get_permalink($dashboard_id) : home_url('/');

        $data = [
            'user_name' => $user->display_name,
            'browser'   => sanitize_text_field($login_data['browser']),
            'os'        => sanitize_text_field($login_data['os']),
            'ip'        => sanitize_text_field($login_data['ip']),
            'time'      => date_i18n(get_option('date_format') . ' ' . get_option('time_format'), time()),
            'site_name' => get_bloginfo('name'),
            'reset_password_url' => wp_lostpassword_url(),
            'dashboard_url' => $dashboard_url
        ];

        return $this->send($user->user_email, $subject, 'security-login', $data);
    }
}
