<?php
if (!defined('ABSPATH')) exit;
?>
        <!-- TAB 1: Security (Email + Bait + Auto-Stolen) -->
        <div id="tab-security" class="mtcam-tab-content active">
            <h2>🔒 <?php esc_html_e('Security & Notifications', 'my-trail-camera'); ?></h2>
            <p><?php esc_html_e('Anti-theft detection, email alerts, and automatic responses.', 'my-trail-camera'); ?></p>

            <!-- ── Email Notifications ── -->
            <h3>📧 <?php esc_html_e('Email Notifications', 'my-trail-camera'); ?></h3>

            <table class="form-table">
                <tr>
                    <th><label for="notifications"><?php esc_html_e('Enable Notifications', 'my-trail-camera'); ?></label></th>
                    <td>
                        <select name="notifications" id="notifications">
                            <option value="yes" <?php selected($settings['notifications'], 'yes'); ?>>✅ <?php esc_html_e('Enabled', 'my-trail-camera'); ?></option>
                            <option value="no" <?php selected($settings['notifications'], 'no'); ?>>❌ <?php esc_html_e('Disabled', 'my-trail-camera'); ?></option>
                        </select>
                        <p class="description"><?php esc_html_e('Send email alerts when a thief detection is triggered.', 'my-trail-camera'); ?></p>

                        <div class="mtcam-tip-box mtcam-tip-box-blue mtcam-mt-15">
                            <strong>ℹ️ <?php esc_html_e('IMPORTANT:', 'my-trail-camera'); ?></strong><br>
                            <?php esc_html_e('This setting applies ONLY to YOUR cameras.', 'my-trail-camera'); ?><br>
                            <?php esc_html_e('Notifications for other people\'s cameras are always sent directly to their email.', 'my-trail-camera'); ?>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th><label for="notify_email"><?php esc_html_e('Notification Emails', 'my-trail-camera'); ?></label></th>
                    <td>
                        <textarea name="notify_email" id="notify_email" class="large-text" rows="3"><?php echo esc_textarea($settings['notify_email']); ?></textarea>
                        <p class="description">
                            <?php esc_html_e('Separate multiple emails with a comma.', 'my-trail-camera'); ?><br>
                            <?php esc_html_e('Example:', 'my-trail-camera'); ?> <code>john@example.com, backup@example.com</code>
                        </p>
                    </td>
                </tr>
            </table>

            <!-- ── Auto-Theft Response ── -->

            <!-- ── Bait Files ── -->
            <h3 class="mtcam-mt-30">🪤 <?php esc_html_e('Anti-Theft Bait Files', 'my-trail-camera'); ?></h3>

            <div class="mtcam-tip-box mtcam-tip-box-yellow">
                <strong><?php esc_html_e('How bait files work:', 'my-trail-camera'); ?></strong><br>
                1. <?php esc_html_e('Download bait files using the 🪤 Bait button next to each camera in the Dashboard.', 'my-trail-camera'); ?><br>
                2. <?php esc_html_e('Copy the files from the ZIP to the trail camera\'s SD card.', 'my-trail-camera'); ?><br>
                3. <?php esc_html_e('When a thief steals the camera and opens an HTML file, their data is reported.', 'my-trail-camera'); ?><br>
                4. <?php esc_html_e('You receive an email notification with IP, location, and browser fingerprint.', 'my-trail-camera'); ?>
            </div>

            <div class="mtcam-tip-box mtcam-tip-box-blue mtcam-mt-10">
                <strong><?php esc_html_e('What the bait files collect:', 'my-trail-camera'); ?></strong><br>
                🌐 <?php esc_html_e('IP address & ISP', 'my-trail-camera'); ?> •
                📍 <?php esc_html_e('GPS location (if browser permits)', 'my-trail-camera'); ?> •
                💻 <?php esc_html_e('OS & browser fingerprint', 'my-trail-camera'); ?>
            </div>

            <div class="mtcam-tip-box mtcam-tip-box-blue mtcam-mt-10">
                <strong><?php esc_html_e('Files included in each download:', 'my-trail-camera'); ?></strong><br>
                <?php
                $mtcam_bait_templates = function_exists('mtcam_get_bait_template_list') ? mtcam_get_bait_template_list() : array();
                foreach ( $mtcam_bait_templates as $mtcam_tpl ) {
                                    echo '<code>' . esc_html( $mtcam_tpl['filename'] ) . '</code> — '
                                        . esc_html( $mtcam_tpl['label'] ) . '<br>';
                                }
                ?>
                <code>DCIM_XXXX.html</code> — <?php esc_html_e('Random filename mimicking camera naming', 'my-trail-camera'); ?><br>
            </div>

            <!-- ── IP Detection ── -->
            <h3 class="mtcam-mt-30">🌐 <?php esc_html_e('IP Address Detection', 'my-trail-camera'); ?></h3>

            <table class="form-table">
                <tr>
                    <th><label for="ip_source"><?php esc_html_e('IP Source', 'my-trail-camera'); ?></label></th>
                    <td>
                        <select name="ip_source" id="ip_source">
                            <option value="remote_addr" <?php selected($settings['ip_source'], 'remote_addr'); ?>>REMOTE_ADDR (<?php esc_html_e('Default', 'my-trail-camera'); ?>)</option>
                            <option value="cf_connecting_ip" <?php selected($settings['ip_source'], 'cf_connecting_ip'); ?>>CF-Connecting-IP (Cloudflare)</option>
                            <option value="x_forwarded_for" <?php selected($settings['ip_source'], 'x_forwarded_for'); ?>>X-Forwarded-For (<?php esc_html_e('Reverse proxy', 'my-trail-camera'); ?>)</option>
                        </select>
                        <p class="description"><?php esc_html_e('Select how the visitor\'s real IP address is determined. Use the default unless your site is behind a reverse proxy or Cloudflare.', 'my-trail-camera'); ?></p>

                        <div class="mtcam-tip-box mtcam-tip-box-yellow mtcam-mt-15">
                            <strong>⚠️ <?php esc_html_e('IMPORTANT:', 'my-trail-camera'); ?></strong><br>
                            <?php esc_html_e('Only change this if you know your server is behind a proxy. Incorrect settings may allow attackers to bypass rate limiting by spoofing headers.', 'my-trail-camera'); ?>
                        </div>
                    </td>
                </tr>
            </table>

        </div>
