<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

function moesec_send_email_notification($subject, $message) {
    $to = get_option('moesec_notification_email', get_option('admin_email'));
    $headers = array('Content-Type: text/html; charset=UTF-8');
    
    wp_mail($to, $subject, $message, $headers);
}

function moesec_threat_detected_notification($threat_type, $threat_details) {
    $subject = esc_html__('MoeSec Security Alert: New Threat Detected', 'moesec');
    
    $message = '<h2>' . esc_html__('MoeSec Security Alert', 'moesec') . '</h2>';
    $message .= '<p>' . esc_html__('A new threat has been detected on your WordPress site:', 'moesec') . '</p>';
    $message .= '<ul>';
    $message .= '<li><strong>' . esc_html__('Threat Type:', 'moesec') . '</strong> ' . esc_html($threat_type) . '</li>';
    $message .= '<li><strong>' . esc_html__('Details:', 'moesec') . '</strong> ' . esc_html($threat_details) . '</li>';
    $message .= '</ul>';
    $message .= '<p>' . esc_html__('Please log in to your WordPress admin panel and check the MoeSec security plugin for more details.', 'moesec') . '</p>';
    
    moesec_send_email_notification($subject, $message);
}

function moesec_login_attempt_notification($username, $ip_address, $status) {
    $subject = esc_html__('MoeSec Security Alert: Login Attempt', 'moesec');
    
    $message = '<h2>' . esc_html__('MoeSec Security Alert', 'moesec') . '</h2>';
    $message .= '<p>' . esc_html__('A login attempt has been detected on your WordPress site:', 'moesec') . '</p>';
    $message .= '<ul>';
    $message .= '<li><strong>' . esc_html__('Username:', 'moesec') . '</strong> ' . esc_html($username) . '</li>';
    $message .= '<li><strong>' . esc_html__('IP Address:', 'moesec') . '</strong> ' . esc_html($ip_address) . '</li>';
    $message .= '<li><strong>' . esc_html__('Status:', 'moesec') . '</strong> ' . esc_html($status) . '</li>';
    $message .= '</ul>';
    $message .= '<p>' . esc_html__('Please log in to your WordPress admin panel and check the MoeSec security plugin for more details.', 'moesec') . '</p>';
    
    moesec_send_email_notification($subject, $message);
}
