<?php

declare(strict_types=1);


/**
 * Internal Linking Style Overrides
 * 
 * Injects clean styles directly into admin to override boxy appearance
 */

namespace ProRank\SEO\Admin;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}




class InternalLinkingStyles {
    
    public static function init() {
        add_action('admin_head', [__CLASS__, 'inject_styles']);
        add_action('admin_footer', [__CLASS__, 'inject_runtime_fixes']);
    }
    
    public static function inject_styles() {
        $page = prorank_get_query_var('page');
        if ($page === '' || strpos($page, 'prorank-seo') === false) {
            return;
        }
        ?>
        <style id="prorank-internal-linking-clean">
        /* Remove ALL box effects from Internal Linking stats */
        .prorank-internal-linking-dashboard .prorank-dashboard-stats {
            display: grid !important;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
            gap: 20px !important;
            margin-bottom: 30px !important;
        }
        
        /* Clean stat cards - NO BOXES */
        .prorank-internal-linking-dashboard .prorank-stat-card,
        .prorank-internal-linking-dashboard .components-card.prorank-stat-card {
            background: transparent !important;
            border: none !important;
            box-shadow: none !important;
            padding: 0 !important;
        }
        
        .prorank-internal-linking-dashboard .prorank-stat-card .components-card__body {
            padding: 16px 20px !important;
            background: #f8f9fa !important;
            border-radius: 8px !important;
            border: 1px solid #e0e0e0 !important;
            box-shadow: none !important;
            display: flex !important;
            align-items: center !important;
            gap: 15px !important;
            min-height: 90px !important;
        }
        
        .prorank-internal-linking-dashboard .prorank-stat-card:hover .components-card__body {
            background: #ffffff !important;
            border-color: #0073aa !important;
        }
        
        /* Stat icons - smaller and cleaner */
        .prorank-stat-icon {
            width: 40px !important;
            height: 40px !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            border-radius: 8px !important;
            background: #e3f2fd !important;
            flex-shrink: 0 !important;
        }
        
        .prorank-stat-icon svg {
            width: 20px !important;
            height: 20px !important;
            color: #0073aa !important;
        }
        
        .prorank-stat-icon--warning {
            background: #fff3cd !important;
        }
        
        .prorank-stat-icon--warning svg {
            color: #856404 !important;
        }
        
        .prorank-stat-icon--error {
            background: #f8d7da !important;
        }
        
        .prorank-stat-icon--error svg {
            color: #721c24 !important;
        }
        
        .prorank-stat-icon--success {
            background: #d4edda !important;
        }
        
        .prorank-stat-icon--success svg {
            color: #155724 !important;
        }
        
        /* Stat content */
        .prorank-stat-content {
            flex: 1 !important;
        }
        
        .prorank-stat-label {
            font-size: 11px !important;
            font-weight: 600 !important;
            color: #666 !important;
            text-transform: uppercase !important;
            letter-spacing: 0.5px !important;
            margin: 0 0 5px 0 !important;
        }
        
        .prorank-stat-value {
            font-size: 24px !important;
            font-weight: 700 !important;
            color: #23282d !important;
            line-height: 1 !important;
            margin: 0 !important;
        }
        
        /* Clean up other cards */
        .prorank-link-health-card,
        .prorank-advanced-features-card,
        .prorank-domains-card,
        .prorank-issues-card {
            box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
            border: 1px solid #e0e0e0 !important;
            border-radius: 8px !important;
        }
        
        .prorank-link-health-card .components-card__header,
        .prorank-advanced-features-card .components-card__header,
        .prorank-domains-card .components-card__header,
        .prorank-issues-card .components-card__header {
            background: #f5f5f5 !important;
            border-bottom: 1px solid #e0e0e0 !important;
            padding: 12px 16px !important;
        }
        
        .prorank-link-health-card h3,
        .prorank-advanced-features-card h3,
        .prorank-domains-card h3,
        .prorank-issues-card h3 {
            margin: 0 !important;
            font-size: 14px !important;
            font-weight: 600 !important;
            color: #23282d !important;
        }
        
        /* Progress bars */
        .prorank-health-metric {
            padding: 12px 0 !important;
            border-bottom: 1px solid #f0f0f0 !important;
        }
        
        .prorank-health-metric:last-child {
            border-bottom: none !important;
        }
        
        /* Remove extra shadows and borders */
        .prorank-internal-linking-dashboard .components-card {
            box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
        }
        
        .prorank-internal-linking-dashboard .components-notice {
            box-shadow: none !important;
            border-left-width: 3px !important;
        }
        
        /* Feature badges */
        .prorank-feature-badge {
            display: inline-flex !important;
            align-items: center !important;
            gap: 4px !important;
            padding: 4px 10px !important;
            background: white !important;
            border-radius: 15px !important;
            font-size: 11px !important;
            font-weight: 500 !important;
            border: 1px solid #ddd !important;
        }
        
        .prorank-feature-badge svg {
            width: 14px !important;
            height: 14px !important;
        }
        </style>
        <?php
    }
    
    public static function inject_runtime_fixes() {
        $page = prorank_get_query_var('page');
        if ($page === '' || strpos($page, 'prorank-seo') === false) {
            return;
        }
        ?>
        <script>
        // Runtime fix to ensure tabs show all features
        (function() {
            // Check if we're on the internal linking tab
            const checkInterval = setInterval(() => {
                const tabPanels = document.querySelectorAll('.components-tab-panel__tab-content');
                const internalLinkingContent = Array.from(tabPanels).find(panel => 
                    panel.innerHTML.includes('Internal Linking') || 
                    panel.innerHTML.includes('prorank-internal-linking')
                );
                
                if (internalLinkingContent) {
                    // Make sure all tabs are visible
                    const tabs = ['Dashboard', 'Settings', 'Links Report', 'Link Map'];
                    const tabButtons = document.querySelectorAll('button[role="tab"]');
                    
                    tabButtons.forEach(button => {
                        const buttonText = button.textContent;
                        tabs.forEach(tabName => {
                            if (buttonText.includes(tabName)) {
                                button.style.display = 'flex';
                                button.disabled = false;
                                
                            }
                        });
                    });
                    
                    clearInterval(checkInterval);
                }
            }, 500);
            
            // Stop checking after 10 seconds
            setTimeout(() => clearInterval(checkInterval), 10000);
        })();
        </script>
        <?php
    }
}

// Initialize immediately
InternalLinkingStyles::init();
