<?php
// This is a view file for the "Manage Ads" tab
if (! defined('ABSPATH')) {
    exit; // No direct access
}

global $wpdb;
$gamadsmbai_table_main = $wpdb->prefix . 'gamadsmbai_ads';
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter -- $gamadsmbai_table_main derived from $wpdb->prefix and escaped; safe internal query; No need of cache
$gamadsmbai_total_ads = $wpdb->get_var("SELECT COUNT(*) FROM $gamadsmbai_table_main WHERE ad_type != 'custom_ad'");
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter -- $gamadsmbai_table_main derived from $wpdb->prefix and escaped;No need of cache
$gamadsmbai_active_ads = $wpdb->get_var("SELECT COUNT(*) FROM $gamadsmbai_table_main WHERE is_active = 1 AND ad_type != 'custom_ad'");
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter -- $gamadsmbai_table_main derived from $wpdb->prefix and escaped;No need of cache
$gamadsmbai_inactive_ads = $wpdb->get_var("SELECT COUNT(*) FROM $gamadsmbai_table_main WHERE is_active = 0 AND ad_type != 'custom_ad'");

$license_key   = get_option('gamadsmbai_license_key', '');
$token         = get_option('gamadsmbai_license_token', '');
?>

<div class="gam-dashboard-tabs">
    <button class="gam-tab-button active" data-tab="total-ads" data-adcounts=<?php echo esc_attr($gamadsmbai_total_ads); ?>>
        Total Ads (<?php echo intval($gamadsmbai_total_ads); ?>)
    </button>
    <button class="gam-tab-button" data-tab="active-ads" data-adcounts=<?php echo esc_attr($gamadsmbai_active_ads); ?>>
        Active Ads (<?php echo intval($gamadsmbai_active_ads); ?>)
    </button>
    <button class="gam-tab-button" data-tab="inactive-ads" data-adcounts=<?php echo esc_attr($gamadsmbai_inactive_ads); ?>>
        Inactive Ads (<?php echo intval($gamadsmbai_inactive_ads); ?>)
    </button>
</div>

<div class="gam-dashboard-content" id="gam-dashboard-content">
    <h4>Total Ads</h4>
    <p><?php /* translators: %d: total number of ads */
    echo esc_html(sprintf(_n('%d ad total.', '%d ads total.', intval( $gamadsmbai_total_ads ), 'gam-ads-ad-manager-and-ad-exchange'), intval($gamadsmbai_total_ads))); 
    ?></p>
</div>

<div id="gam-manage-ads">
    <h4>Manage Ads</h4>

    <input type="text" id="gam-search-ads"
        placeholder="Search ads...">

    <div id="gam-ads-list-container" <?php echo esc_attr((!empty($license_key) && !empty($token)) ? 'data-rfrsad=true' : ''); ?>>
    </div>
</div>