<?php

//admin/diagnostics.php


function asana_automator_diagnostic_report() {
    echo '<div class="wrap"><h1>Asana Automator Diagnostics</h1>';

    echo '<h2>System Status</h2>';
    echo '<ul>';

    // 1. WP-Cron status
    echo '<li><strong>WP-Cron Enabled:</strong> ' . (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ? '❌ Disabled' : '✅ Enabled') . '</li>';

    // 2. Last cron execution
    $log_path = WP_CONTENT_DIR . '/cron-test.log';
    if (file_exists($log_path)) {
        $lines = file($log_path);
        $last = end($lines);
        echo '<li><strong>Last Cron Entry:</strong> <code>' . esc_html($last) . '</code></li>';
    } else {
        echo '<li><strong>Cron Log:</strong> Not found</li>';
    }

    // 3. Number of rules
    $rules = get_option('asana_automator_rules', []);
    echo '<li><strong>Configured Rules:</strong> ' . count($rules) . '</li>';

    // 4. PATs loaded
    $pats = asana_automator_get_pat_accounts();
    echo '<li><strong>PAT Accounts:</strong> ' . count($pats) . '</li>';

    // 5. Hook check
    $cron_info = _get_cron_array();
    $hook_found = isset($cron_info['asana_automator_cron_dispatch']);
    echo '<li><strong>Cron Hook Registered:</strong> ' . ($hook_found ? '✅ Yes' : '❌ No') . '</li>';

    echo '</ul>';
    echo '</div>';
}
