<?php
// If this file is called directly, abort.
if (!defined('WPINC')) {
    die;
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.Security.NonceVerification.Recommended -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
$section = isset($_GET['section']) ? sanitize_text_field(wp_unslash($_GET['section'])) : 'general';
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
$page_title = 'Off-Page SEO Tools';
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
$section_message = 'This section is currently under development. More tools and features are coming soon!';

switch ($section) {
    case 'backlink-management':
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Backlink Management Tools';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Tools for analyzing and managing your backlinks will be available here soon. Stay tuned!';
        break;
    case 'digital-pr':
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Digital PR Tools';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Resources and tools for your Digital PR campaigns are on their way!';
        break;
    case 'social-strategy':
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Social Strategy Tools';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Optimize and track your social media impact with tools coming to this section.';
        break;
    case 'social-content-generator':
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Social Media Content Generator';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Generate optimized content for multiple social media platforms';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $show_generator_interface = true;
        break;
    case 'reputation-management':
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Reputation Management Tools';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Manage and monitor your online reputation with features that will be added here.';
        break;
    default:
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_title = 'Off-Page Tools Hub';
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-local variable in an immediately included admin partial; it is not a public global symbol or persisted contract.
        $section_message = 'Welcome to the Off-Page Tools Hub. Select a specific tool area or check back later for more options.';
        break;
}

?>

<div class="wrap aysa-off-page-tools-page">
    <h1><span class="dashicons dashicons-admin-tools"></span> <?php echo esc_html($page_title); ?></h1>
    
    <div class="aysa-tools-content-area">
        <h2><?php echo esc_html($section_title); ?></h2>
        <p><?php echo esc_html($section_message); ?></p>
        
        <?php if (isset($show_generator_interface) && $show_generator_interface): ?>
            <!-- Social Media Content Generator Interface -->
            <div class="social-generator-interface">
                <!-- Platform Selection Grid -->
                <div class="generator-section">
                    <h3><i class="fas fa-share-alt"></i> Select Platforms</h3>
                    <div class="platform-grid" id="platform-selection-page">
                        <div class="platform-card" data-platform="facebook" data-limit="63206">
                            <i class="fab fa-facebook-f"></i>
                            <span>Facebook</span>
                            <div class="platform-status">Ready</div>
                        </div>
                        <div class="platform-card" data-platform="linkedin" data-limit="3000">
                            <i class="fab fa-linkedin-in"></i>
                            <span>LinkedIn</span>
                            <div class="platform-status">Ready</div>
                        </div>
                        <div class="platform-card" data-platform="x" data-limit="280">
                            <i class="fab fa-x-twitter"></i>
                            <span>X</span>
                            <div class="platform-status">Ready</div>
                        </div>
                        <div class="platform-card" data-platform="instagram" data-limit="2200">
                            <i class="fab fa-instagram"></i>
                            <span>Instagram</span>
                            <div class="platform-status">Ready</div>
                        </div>
                        <div class="platform-card" data-platform="youtube" data-limit="5000">
                            <i class="fab fa-youtube"></i>
                            <span>YouTube</span>
                            <div class="platform-status">Ready</div>
                        </div>
                        <div class="platform-card" data-platform="pinterest" data-limit="500">
                            <i class="fab fa-pinterest-p"></i>
                            <span>Pinterest</span>
                            <div class="platform-status">Ready</div>
                        </div>
                    </div>
                </div>

                <!-- Content Generation Controls -->
                <div class="generator-section">
                    <h3><i class="fas fa-magic"></i> Content Generation</h3>
                    <div class="generation-controls">
                        <div class="control-group">
                            <label for="content-topic">Topic/Keywords</label>
                            <input type="text" id="content-topic" placeholder="Enter your topic or keywords..." class="form-control">
                        </div>
                        <div class="control-group">
                            <label for="content-tone">Tone</label>
                            <select id="content-tone" class="form-control">
                                <option value="professional">Professional</option>
                                <option value="casual">Casual</option>
                                <option value="friendly">Friendly</option>
                                <option value="authoritative">Authoritative</option>
                                <option value="creative">Creative</option>
                            </select>
                        </div>
                        <div class="control-group">
                            <button id="generate-all-content" class="btn btn-primary">
                                <i class="fas fa-magic"></i> Generate for Selected Platforms
                            </button>
                        </div>
                    </div>
                </div>

                <!-- Generated Content Display -->
                <div class="generator-section">
                    <h3><i class="fas fa-list"></i> Generated Content</h3>
                    <div class="content-management">
                        <div class="bulk-actions">
                            <button id="copy-all-content" class="btn btn-outline-primary" disabled>
                                <i class="fas fa-copy"></i> Copy All
                            </button>
                            <button id="export-all-content" class="btn btn-outline-secondary" disabled>
                                <i class="fas fa-download"></i> Export All
                            </button>
                        </div>
                        <div id="generated-content-list" class="content-list">
                            <div class="aysa-table-responsive">
                                <table class="content-table" id="content-table" style="display: none;">
                                    <thead>
                                        <tr>
                                            <th>Platform</th>
                                            <th>Content</th>
                                            <th>Character Count</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody id="content-table-body">
                                    </tbody>
                                </table>
                            </div>
                            <div class="empty-state" id="empty-state">
                                <i class="fas fa-plus-circle"></i>
                                <p>No content generated yet. Select platforms to see dummy content or click "Generate for Selected Platforms" to get started.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        
        <p>
            <a href="<?php echo esc_url(admin_url('admin.php?page=aysa-off-page-optimization')); ?>" class="button button-secondary">
                <span class="dashicons dashicons-arrow-left-alt"></span> Back to Off-Page Optimization Overview
            </a>
        </p>
    </div>
</div>

<style>
    .aysa-off-page-tools-page h1 {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 24px;
        font-weight: 600;
        color: #2c3e50;
        margin-bottom: 20px;
    }
    .aysa-off-page-tools-page .dashicons {
        font-size: 28px;
    }
    .aysa-tools-content-area {
        background-color: #fff;
        padding: 25px;
        border-radius: 8px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.07);
    }
    .aysa-tools-content-area h2 {
        font-size: 20px;
        color: #34495e;
        margin-top: 0;
        margin-bottom: 15px;
    }
    .aysa-tools-content-area p {
        font-size: 15px;
        color: #566573;
        line-height: 1.6;
    }
    .aysa-tools-content-area .button .dashicons {
        font-size: 18px; /* Smaller for button icon */
        line-height: inherit; /* Align with button text */
        margin-right: 5px;
    }
    
    /* Social Media Content Generator Styles */
    .social-generator-interface {
        margin-top: 30px;
    }
    
    .generator-section {
        background: #f8f9fa;
        border: 1px solid #e9ecef;
        border-radius: 8px;
        padding: 25px;
        margin-bottom: 25px;
    }
    
    .generator-section h3 {
        margin: 0 0 20px 0;
        color: #2c3e50;
        font-size: 18px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .platform-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .platform-card {
        background: white;
        border: 2px solid #e9ecef;
        border-radius: 8px;
        padding: 20px;
        text-align: center;
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
    }
    
    .platform-card:hover {
        border-color: #007cba;
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,124,186,0.15);
    }
    
    .platform-card.selected {
        border-color: #007cba;
        background: linear-gradient(135deg, #007cba 0%, #005a87 100%);
        color: white;
    }
    
    .platform-card i {
        font-size: 32px;
        margin-bottom: 10px;
        display: block;
    }
    
    .platform-card[data-platform="facebook"] i { color: #1877f2; }
    .platform-card[data-platform="linkedin"] i { color: #0077b5; }
    .platform-card[data-platform="x"] i { color: #000000; }
    .platform-card[data-platform="instagram"] i { color: #e4405f; }
    .platform-card[data-platform="youtube"] i { color: #ff0000; }
    .platform-card[data-platform="pinterest"] i { color: #bd081c; }
    
    .platform-card.selected i {
        color: white;
    }
    
    .platform-card span {
        font-weight: 600;
        font-size: 14px;
    }
    
    .platform-status {
        font-size: 12px;
        margin-top: 5px;
        opacity: 0.7;
    }
    
    .generation-controls {
        display: grid;
        grid-template-columns: 1fr 200px auto;
        gap: 20px;
        align-items: end;
    }
    
    .control-group label {
        display: block;
        margin-bottom: 5px;
        font-weight: 600;
        color: #2c3e50;
    }
    
    .form-control {
        width: 100%;
        padding: 10px;
        border: 1px solid #ddd;
        border-radius: 4px;
        font-size: 14px;
    }
    
    .btn {
        padding: 10px 20px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        transition: all 0.3s ease;
    }
    
    .btn-primary {
        background: #007cba;
        color: white;
    }
    
    .btn-primary:hover {
        background: #005a87;
    }
    
    .btn-secondary {
        background: #6c757d;
        color: white;
    }
    
    .btn-secondary:hover {
        background: #545b62;
    }
    
    .btn-outline-primary {
        background: transparent;
        color: #007cba;
        border: 1px solid #007cba;
    }
    
    .btn-outline-primary:hover {
        background: #007cba;
        color: white;
    }
    
    .btn-outline-secondary {
        background: transparent;
        color: #6c757d;
        border: 1px solid #6c757d;
    }
    
    .btn-outline-secondary:hover {
        background: #6c757d;
        color: white;
    }
    
    .btn-outline-danger {
        background: transparent;
        color: #dc3545;
        border: 1px solid #dc3545;
    }
    
    .btn-outline-danger:hover {
        background: #dc3545;
        color: white;
    }
    
    .btn:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
    
    .content-management {
        min-height: 200px;
    }
    
    .bulk-actions {
        margin-bottom: 20px;
        display: flex;
        gap: 10px;
    }
    
    .content-list {
        border: 1px solid #e9ecef;
        border-radius: 8px;
        background: white;
        min-height: 150px;
    }

    .content-list .aysa-table-responsive {
        overflow-x: auto;
        overflow-y: visible;
    }
    
    .empty-state {
        text-align: center;
        padding: 40px 20px;
        color: #6c757d;
    }
    
    .empty-state i {
        font-size: 48px;
        margin-bottom: 15px;
        opacity: 0.5;
    }
    
    .content-item {
        border-bottom: 1px solid #e9ecef;
        padding: 20px;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }
    
    .content-item:last-child {
        border-bottom: none;
    }
    
    .content-details {
        flex: 1;
    }
    
    .content-platform {
        font-weight: 600;
        color: #007cba;
        margin-bottom: 5px;
    }
    
    .content-text {
        color: #2c3e50;
        line-height: 1.5;
        margin-bottom: 10px;
    }
    
    .content-meta {
        font-size: 12px;
        color: #6c757d;
    }
    
    .content-actions {
        display: flex;
        gap: 10px;
        margin-left: 20px;
    }
    
    .content-actions .btn {
        padding: 5px 10px;
        font-size: 12px;
    }
    
    /* Content Table Styles */
    .content-table {
        width: 100%;
        border-collapse: collapse;
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .content-table th {
        background: #f8f9fa;
        color: #2c3e50;
        font-weight: 600;
        padding: 15px;
        text-align: left;
        border-bottom: 2px solid #e9ecef;
    }
    
    .content-table td {
        padding: 15px;
        border-bottom: 1px solid #e9ecef;
        vertical-align: top;
    }
    
    .content-table tr:last-child td {
        border-bottom: none;
    }
    
    .content-table tr:hover {
        background: #f8f9fa;
    }
    
    .content-platform strong {
        color: #007cba;
        font-size: 14px;
    }
    
    .content-preview {
        color: #2c3e50;
        line-height: 1.5;
        margin-bottom: 8px;
        max-width: 400px;
        word-wrap: break-word;
    }
    
    .content-meta {
        font-size: 12px;
        color: #6c757d;
        font-style: italic;
    }
    
    .character-count {
        font-weight: 600;
        color: #28a745;
        font-size: 13px;
    }
    
    .content-table .content-actions {
        margin-left: 0;
        justify-content: flex-start;
    }
    
    .content-table .content-actions .btn {
        padding: 6px 12px;
        font-size: 11px;
        white-space: nowrap;
    }
    
    @media (max-width: 768px) {
        .generation-controls {
            grid-template-columns: 1fr;
            gap: 15px;
        }
        
        .platform-grid {
            grid-template-columns: repeat(2, 1fr);
        }
        
        .bulk-actions {
            flex-direction: column;
        }
        
        .content-item {
            flex-direction: column;
            gap: 15px;
        }
        
        .content-actions {
            margin-left: 0;
        }
        
        /* Table responsive styles */
        .content-table {
            font-size: 14px;
        }
        
        .content-table th,
        .content-table td {
            padding: 10px 8px;
        }
        
        .content-preview {
            max-width: 250px;
        }
        
        .content-table .content-actions {
            flex-direction: column;
            gap: 5px;
        }
        
        .content-table .content-actions .btn {
            font-size: 10px;
            padding: 4px 8px;
        }
    }
</style>                              
