<?php
/**
 * Theft detection, Financial damage calculation, IP/MAC correlations
 * @package My Trail Camera
 * @since 8.1.0
 */

if (!defined('ABSPATH')) exit;

// ============================================================================
// DAMAGE CALCULATION
// ============================================================================

/**
 * Calculation of total damage and the number of stolen cameras
 * Eliminates duplicate code in the dashboard and widget
 * * @param array $cameras All Trail Cameras
 * @param string $filter 'my'|'other'|'all' - ownership filter
 * @return array ['total_damage' => float, 'stolen_count' => int]
 */
function mtcam_calculate_stolen_damage($cameras, $filter = 'my') {
    $total_damage = 0;
    $stolen_count = 0;
    
    $filtered = mtcam_filter_cameras($cameras, $filter);
    
    foreach ($filtered as $cam) {
        // ⚡ OPTIMIZATION: Use helper function
        if (mtcam_is_stolen($cam)) {
            $total_damage += mtcam_get_camera_total_value($cam);
            $stolen_count++;
        }
    }
    
    return array(
        'total_damage' => $total_damage,
        'stolen_count' => $stolen_count
    );
}

