<?php
// phpcs:ignoreFile
if ( ! defined( 'ABSPATH' ) ) { exit; }

use LolaCore\Admin\McpConfigGenerator;

$namespaces = apply_filters('lolacore_mcp_namespaces', ['lolacore']);
$base_url = get_rest_url( null, 'mcp/' );
?>

<div class="lc-card">
    <div class="lc-card-header">
        <span class="lc-section-number">1</span>
        <h3><?php esc_html_e( 'MCP Endpoints', 'lolacore' ); ?></h3>
    </div>
    <p class="description"><?php esc_html_e('These are the REST API endpoints exposed for the active LolaCore modules.', 'lolacore'); ?></p>
    
    <div class="lc-mcp-endpoints-list" style="margin-top: 16px;">
        <?php foreach ($namespaces as $ns): ?>
        <div class="lc-mcp-endpoint-row" style="margin-bottom: 12px; display: flex; align-items: center; gap: 12px;">
            <span class="lc-mcp-eyebrow" style="display:inline-block; width: 150px; font-weight: 600; font-family: var(--lc-mono);"><?php echo esc_html($ns); ?></span>
            <code id="lc-mcp-endpoint-<?php echo esc_attr($ns); ?>" style="flex: 1; padding: 8px 12px; background: #f8f9fa; border: 1px solid #d1d5db; border-radius: 6px;"><?php echo esc_html($base_url . $ns); ?></code>
            <button type="button" class="lc-action-btn ghost lc-mcp-copy-btn" data-target="lc-mcp-endpoint-<?php echo esc_attr($ns); ?>">
                <?php esc_html_e( 'Copy', 'lolacore' ); ?>
            </button>
        </div>
        <?php endforeach; ?>
    </div>
</div>

<?php
$mcp_adapter_active = class_exists( 'WP\\MCP\\Core\\McpAdapter' );
if ( ! $mcp_adapter_active ) : ?>
<div class="lc-card" style="background: #FFFBEB; border-color: #F59E0B;">
    <div class="lc-card-header">
        <h3><?php esc_html_e( 'Action Required: Install MCP Adapter', 'lolacore' ); ?></h3>
    </div>
    <p>
        <?php esc_html_e( 'To connect external AI clients (Cursor, Claude Desktop), you must install the WordPress MCP Adapter:', 'lolacore' ); ?>
    </p>
    <ol>
        <li><?php
            printf(
                esc_html__( 'Download the latest release from %s', 'lolacore' ),
                '<a href="https://github.com/10up/wp-mcp" target="_blank" rel="noopener">GitHub</a>'
            );
        ?></li>
        <li><?php esc_html_e( 'Upload the ZIP via Plugins > Add New > Upload Plugin.', 'lolacore' ); ?></li>
        <li><?php esc_html_e( 'Activate the MCP Adapter plugin and refresh this page.', 'lolacore' ); ?></li>
    </ol>
</div>
<?php endif; ?>

<div class="lc-mcp-connect-section">
    <?php
    require __DIR__ . '/partials/cred-form.php';
    require __DIR__ . '/partials/config-card.php';
    ?>
</div>
