<?php
// Manage Feed Source UI Component
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<div class="blog82ai-manage-feeds">
    <div class="blog82ai-page-header">
        <h2>Manage Feed Sources</h2>
        <p>Manage and monitor your RSS/Atom feed sources</p>
    </div>

    <div class="blog82ai-header-actions">
        <button class="button button-primary" onclick="location.href='<?php echo esc_url(admin_url('admin.php?page=blogibot&tab=feed&subtab=add_feed_source')); ?>'">Add New Feed</button>
        <button class="button" onclick="bulkFetchAll()">Fetch All Now</button>
    </div>

    <!-- Filters and Search -->
    <div class="blog82ai-feeds-filters">
        <div class="blog82ai-filter-row">
            <div class="blog82ai-filter-group">
                <label for="filter-status">Status:</label>
                <select id="filter-status">
                    <option value="">All Status</option>
                    <option value="active">Active</option>
                    <option value="inactive">Inactive</option>
                    <option value="error">Error</option>
                    <option value="paused">Paused</option>
                </select>
            </div>
            <div class="blog82ai-filter-group">
                <label for="filter-category">Category:</label>
                <select id="filter-category">
                    <option value="">All Categories</option>
                    <?php
                    // Get all WordPress categories
                    $wp_categories = get_categories(array(
                        'hide_empty' => false,
                        'orderby' => 'name',
                        'order' => 'ASC',
                    ));
                    foreach ($wp_categories as $cat) {
                        echo '<option value="' . esc_attr($cat->term_id) . '">' . esc_html($cat->name) . '</option>';
                    }
                    ?>
                </select>
            </div>

            <div class="blog82ai-filter-group">
                <label for="filter-frequency">Frequency:</label>
                <select id="filter-frequency">
                    <option value="">All Frequencies</option>
                    <option value="hourly">Hourly</option>
                    <option value="6hours">Every 6 Hours</option>
                    <option value="daily">Daily</option>
                    <option value="weekly">Weekly</option>
                    <option value="manual">Manual</option>
                </select>
            </div>
            <div class="blog82ai-filter-group">
                <input type="text" id="search-feeds" placeholder="Search feeds...">
            </div>
        </div>
    </div>

    <!-- Feed Sources Table -->
    <div class="blog82ai-feeds-table">
        <table class="wp-list-table widefat fixed striped">
            <thead>
                <tr>
                    <th scope="col" class="manage-column">
                        <input type="checkbox" id="select-all-feeds">
                    </th>
                    <th scope="col" class="manage-column sortable">
                        <a href="#" onclick="return false;">Feed Name</a>
                    </th>
                    <th scope="col" class="manage-column">Category</th>
                    <th scope="col" class="manage-column">Frequency</th>
                    <th scope="col" class="manage-column">Last Fetch</th>
                    <th scope="col" class="manage-column">Posts Imported</th>
                    <th scope="col" class="manage-column">Status</th>
                    <th scope="col" class="manage-column">Actions</th>
                </tr>
            </thead>
            <tbody>
                <!-- Feeds will be loaded dynamically via AJAX -->
                <tr>
                    <td colspan="8" style="text-align:center; padding: 40px 0;">
                        <div class="blog82ai-loading" style="font-size: 16px;">🔄 Loading feeds...</div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    <!-- Bulk Actions -->
    <div class="blog82ai-bulk-actions">
        <div class="blog82ai-bulk-actions-bar">
            <select id="bulk-action-selector">
                <option value="">Bulk Actions</option>
                <option value="activate">Activate Selected</option>
                <option value="pause">Pause Selected</option>
                <option value="fetch">Fetch Selected</option>
                <option value="delete">Delete Selected</option>
            </select>
            <button class="button" onclick="applyBulkAction()" style="margin: 0;">Apply</button>
            
            <div class="blog82ai-table-info">
                <span class="blog82ai-items-count">0 feeds total</span>
                <span class="blog82ai-selection-count" style="display: none;">0 selected</span>
            </div>
        </div>
    </div>

    <!-- Feed Statistics Summary -->
    <div class="blog82ai-feed-stats-summary">
        <div class="blog82ai-stats-cards">
            <!-- Stats will be loaded dynamically via JavaScript -->
        </div>
    </div>
</div>
