<?php
/**
 * Camera detail partial — Dates & Statistics section.
 *
 * Expected variables in scope (via include):
 *   $mtc_cam_id, $mtc_cam, $mtc_days_in_field, $mtc_detection_count
 *
 * @package My Trail Camera
 * @since   8.2.0
 */

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

?>
<!-- Dates, Location & Stats -->
<div>
    <h4>📅 <?php esc_html_e('Dates & Statistics', 'my-trail-camera'); ?></h4>
    <table class="mtcam-info-table">
        <tr>
            <td><?php esc_html_e('Purchased:', 'my-trail-camera'); ?></td>
            <td><?php mtcam_echo_date_html( $mtc_cam['purchase_date'] ?? '' ); ?></td>
        </tr>
        <tr>
            <td><?php esc_html_e('Deployed:', 'my-trail-camera'); ?></td>
			<td><?php mtcam_echo_date_html( $mtc_cam['deploy_date'] ?? '' ); ?><?php if ( ! empty( $mtc_cam['deploy_time'] ) ) echo ' ' . esc_html( $mtc_cam['deploy_time'] ); ?></td>
        </tr>
        <tr>
            <td><?php esc_html_e('Added:', 'my-trail-camera'); ?></td>
            <td><?php
                if (!empty($mtc_cam['created_date'])) {
                    mtcam_echo_date_html( $mtc_cam['created_date'], 'j.m.Y' );
                    echo ' <small class="mtcam-text-muted">' . esc_html(sprintf(__('at %s', 'my-trail-camera'), wp_date('H:i', strtotime($mtc_cam['created_date'])))) . '</small>';
                } else {
                    echo '—';
                }
            ?></td>
        </tr>
        <tr>
            <td><?php esc_html_e('Days in field:', 'my-trail-camera'); ?></td>
            <td>
                <?php if (!empty($mtc_cam['deploy_date'])): ?>
                    <strong><?php echo intval($mtc_days_in_field); ?> <?php esc_html_e('days', 'my-trail-camera'); ?></strong>
                    <?php if ($mtc_days_in_field === 0): ?>
                        <small style="color:#646970;">(<?php esc_html_e('today', 'my-trail-camera'); ?>)</small>
                    <?php endif; ?>
                <?php else: ?>
                    —
                <?php endif; ?>
            </td>
        </tr>
        <tr>
            <td><?php esc_html_e('Theft Alerts:', 'my-trail-camera'); ?></td>
            <td><strong><?php echo intval($mtc_detection_count); ?></strong></td>
        </tr>
        <tr>
            <td class="mtcam-cell-top"><?php esc_html_e('Status:', 'my-trail-camera'); ?></td>
            <td><div><?php mtcam_render_status_badge($mtc_cam); ?></div></td>
        </tr>
        <?php if ( ! empty( $mtc_cam['recovered_date'] ) ) : ?>
        <tr>
            <td>✅ <?php esc_html_e( 'Recovered:', 'my-trail-camera' ); ?></td>
            <td><?php mtcam_echo_date_html( $mtc_cam['recovered_date'] ); ?></td>
        </tr>
        <?php endif; ?>
        <?php if ( ! empty( $mtc_cam['last_checked'] ) ) : ?>
        <tr>
            <td>🔍 <?php esc_html_e( 'Last check:', 'my-trail-camera' ); ?></td>
            <td><?php mtcam_echo_date_html( $mtc_cam['last_checked'] ); ?>
                <?php
                if ( max( 0, intval( ( time() - strtotime( $mtc_cam['last_checked'] ) ) / 86400 ) ) > 0 ) :
                ?>
                    <?php /* translators: %d: number of days since last check */ ?>
                    <small class="mtcam-text-muted">(<?php echo esc_html( sprintf( __( '%d days ago', 'my-trail-camera' ), max( 0, intval( ( time() - strtotime( $mtc_cam['last_checked'] ) ) / 86400 ) ) ) ); ?>)</small>
                <?php endif; ?>
            </td>
        </tr>
        <?php endif; ?>
    </table>
</div>
