<?php
/**
 * Camera detail partial — Specs & Protection (right column).
 *
 * Technical specs from the camera profile as inline chips (FOV, battery,
 * video resolutions, connectivity, drain rates), followed by protection
 * rows (trap files, physical protection, GPS trackers). Merges the old
 * camera-profile + security-gps partials.
 *
 * Expected variables in scope (via include):
 *   $mtc_cam_id, $mtc_cam
 *
 * @package My Trail Camera
 * @since   8.2.4
 */

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

call_user_func( function () use ( $mtc_cam_id, $mtc_cam ) {

$profile_id  = $mtc_cam['profile'] ?? 'custom';
$profile     = ( $profile_id !== 'custom' && function_exists( 'mtcam_get_camera_profile' ) )
	? mtcam_get_camera_profile( $profile_id )
	: array();
$has_profile = ! empty( $profile['label'] );
?>
<div class="mtcam-detail-card-inner">
    <h4>⚙️ <?php esc_html_e( 'Specs & Protection', 'my-trail-camera' ); ?></h4>

    <?php if ( $has_profile ) : ?>
    <div class="mtcam-chip-group">
        <?php if ( ! empty( $profile['fov'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( 'Field of view', 'my-trail-camera' ); ?>">📐 <?php echo intval( $profile['fov'] ); ?>°</span>
        <?php endif; ?>

        <?php if ( ! empty( $profile['battery_capacity'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( 'Battery capacity', 'my-trail-camera' ); ?>">🔋 <?php echo esc_html( number_format( $profile['battery_capacity'], 0, '', ' ' ) ); ?> mAh<?php if ( ! empty( $profile['battery_type'] ) ) echo ' · ' . esc_html( $profile['battery_type'] ); ?></span>
        <?php endif; ?>

        <?php if ( ! empty( $profile['has_sim'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec">📶 4G/LTE</span>
        <?php endif; ?>
        <?php if ( ! empty( $profile['has_wifi'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec">📡 WiFi</span>
        <?php endif; ?>
        <?php if ( ! empty( $profile['has_solar'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec">☀️ <?php esc_html_e( 'Solar', 'my-trail-camera' ); ?></span>
        <?php endif; ?>
        <?php if ( ! empty( $profile['has_cloud'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec">☁️ Cloud</span>
        <?php endif; ?>

        <?php if ( ! empty( $profile['video_resolutions'] ) ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( 'Video resolutions', 'my-trail-camera' ); ?>">🎥 <?php echo esc_html( implode( ' / ', $profile['video_resolutions'] ) ); ?></span>
        <?php else : ?>
            <span class="mtcam-chip mtcam-chip-spec">📸 <?php esc_html_e( 'Photo only', 'my-trail-camera' ); ?></span>
        <?php endif; ?>

        <?php if ( floatval( $profile['drain_standby'] ?? 0 ) > 0 ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( 'Standby drain per day', 'my-trail-camera' ); ?>">⏸️ <?php echo esc_html( floatval( $profile['drain_standby'] ) ); ?> mAh/<?php esc_html_e( 'day', 'my-trail-camera' ); ?></span>
        <?php endif; ?>

        <?php if ( floatval( $profile['drain_photo'] ?? 0 ) > 0 ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( 'Drain per photo', 'my-trail-camera' ); ?>">📸 <?php echo esc_html( floatval( $profile['drain_photo'] ) ); ?> mAh</span>
        <?php endif; ?>

        <?php if ( floatval( $profile['drain_4g'] ?? 0 ) > 0 ) : ?>
            <span class="mtcam-chip mtcam-chip-spec" title="<?php esc_attr_e( '4G daily drain', 'my-trail-camera' ); ?>">📶 <?php echo esc_html( floatval( $profile['drain_4g'] ) ); ?> mAh/<?php esc_html_e( 'day', 'my-trail-camera' ); ?></span>
        <?php endif; ?>
    </div>

    <?php if ( ! empty( $profile['tip'] ) ) : ?>
        <p class="mtcam-spec-tip">💡 <?php echo esc_html( $profile['tip'] ); ?></p>
    <?php endif; ?>
    <?php endif; ?>

    <div class="mtcam-chip-row">
        <span class="mtcam-chip-row-label"><?php esc_html_e( 'Trap files:', 'my-trail-camera' ); ?></span>
        <span class="mtcam-chip-row-values"><?php mtcam_render_files( $mtc_cam ); ?></span>
    </div>
    <div class="mtcam-chip-row">
        <span class="mtcam-chip-row-label"><?php esc_html_e( 'Protection:', 'my-trail-camera' ); ?></span>
        <span class="mtcam-chip-row-values"><?php mtcam_render_security( $mtc_cam ); ?></span>
    </div>
    <div class="mtcam-chip-row">
        <span class="mtcam-chip-row-label"><?php esc_html_e( 'GPS Tracker:', 'my-trail-camera' ); ?></span>
        <span class="mtcam-chip-row-values"><?php mtcam_render_gps_trackers( $mtc_cam ); ?></span>
    </div>
</div>
<?php
} );
