<?php
/**
 * Camera detail partial — Camera Profile specifications.
 *
 * Shows technical specs from the camera profile (FOV, battery, video, features).
 * Only rendered when a non-custom profile is assigned.
 *
 * Expected variables in scope (via include):
 *   $mtc_cam_id, $mtc_cam
 *
 * @package My Trail Camera
 * @since   8.2.0
 */

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

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

$profile_id = $mtc_cam['profile'] ?? 'custom';
if ( $profile_id === 'custom' || ! function_exists( 'mtcam_get_camera_profile' ) ) {
	return;
}

$profile = mtcam_get_camera_profile( $profile_id );
if ( empty( $profile['label'] ) ) {
	return;
}
?>
<div>
    <h4><?php echo esc_html( $profile['label'] ); ?></h4>
    <table class="mtcam-info-table">
        <?php if ( ! empty( $profile['fov'] ) ) : ?>
        <tr>
            <td><?php esc_html_e( 'Field of View:', 'my-trail-camera' ); ?></td>
            <td><?php echo intval( $profile['fov'] ); ?>°</td>
        </tr>
        <?php endif; ?>

        <?php if ( ! empty( $profile['battery_capacity'] ) ) : ?>
        <tr>
            <td><?php esc_html_e( 'Battery:', 'my-trail-camera' ); ?></td>
            <td><?php echo esc_html( number_format( $profile['battery_capacity'], 0, '', ' ' ) ); ?> mAh</td>
        </tr>
        <?php endif; ?>

        <?php if ( ! empty( $profile['battery_type'] ) ) : ?>
        <tr>
            <td><?php esc_html_e( 'Type:', 'my-trail-camera' ); ?></td>
            <td><?php echo esc_html( $profile['battery_type'] ); ?></td>
        </tr>
        <?php endif; ?>

        <tr>
            <td><?php esc_html_e( 'Video:', 'my-trail-camera' ); ?></td>
            <td><?php
                if ( ! empty( $profile['video_resolutions'] ) ) {
                    echo esc_html( implode( ' / ', $profile['video_resolutions'] ) );
                } else {
                    esc_html_e( 'photo only', 'my-trail-camera' );
                }
            ?></td>
        </tr>

        <tr>
            <td><?php esc_html_e( 'Features:', 'my-trail-camera' ); ?></td>
            <td><?php
                $features = array();
                if ( ! empty( $profile['has_sim'] ) )   $features[] = '4G/LTE';
                if ( ! empty( $profile['has_wifi'] ) )  $features[] = 'WiFi';
                if ( ! empty( $profile['has_solar'] ) ) $features[] = __( 'Solar', 'my-trail-camera' );
                if ( ! empty( $profile['has_cloud'] ) ) $features[] = 'Cloud';
                echo ! empty( $features ) ? esc_html( implode( ', ', $features ) ) : '<span class="mtcam-text-muted">—</span>';
            ?></td>
        </tr>

        <tr>
            <td><?php esc_html_e( 'Standby:', 'my-trail-camera' ); ?></td>
            <td><?php echo esc_html( floatval( $profile['drain_standby'] ?? 0 ) ); ?> mAh/<?php esc_html_e( 'day', 'my-trail-camera' ); ?></td>
        </tr>

        <?php if ( floatval( $profile['drain_photo'] ?? 0 ) > 0 ) : ?>
        <tr>
            <td><?php esc_html_e( 'Per photo:', 'my-trail-camera' ); ?></td>
            <td><?php echo esc_html( floatval( $profile['drain_photo'] ) ); ?> mAh</td>
        </tr>
        <?php endif; ?>

        <?php if ( floatval( $profile['drain_4g'] ?? 0 ) > 0 ) : ?>
        <tr>
            <td><?php esc_html_e( '4G drain:', 'my-trail-camera' ); ?></td>
            <td><?php echo esc_html( floatval( $profile['drain_4g'] ) ); ?> mAh/<?php esc_html_e( 'day', 'my-trail-camera' ); ?></td>
        </tr>
        <?php endif; ?>
    </table>

    <?php if ( ! empty( $profile['tip'] ) ) : ?>
    <p class="mtcam-text-muted" style="font-size:12px; margin:8px 0 0;">
        <?php echo esc_html( $profile['tip'] ); ?>
    </p>
    <?php endif; ?>
</div>
<?php
} );
