<?php
/**
 * ==========================
 * 🔐 IGNY8 FILE RULE HEADER
 * ==========================
 * @file         : home.php
 * @location     : modules/
 * @type         : Home Page Template
 * @scope        : Global
 * @allowed      : Home page content only, no routing or business logic
 * @reusability  : Global
 * @notes        : Home page dashboard content
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Get workflow data
$workflow_data = igny8_get_system_workflow_data();

// Start output buffering
ob_start();
?>
<div class="igny8-module-home">
    <!-- System-Wide AI Workflow Guide -->
    <div class="igny8-system-workflow">
        <div class="igny8-system-workflow-header">
            <span class="dashicons dashicons-networking"></span>
            <div>
                <h2>Complete AI Content Workflow</h2>
                <p class="igny8-system-workflow-subtitle">Track your progress through the entire content creation and optimization pipeline</p>
            </div>
        </div>
        <div class="igny8-system-steps-container">
            <!-- Step 1: Add Keywords -->
            <div class="igny8-system-step <?php echo $workflow_data['keywords']['status']; ?> <?php echo !$workflow_data['keywords']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['keywords']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['keywords']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">1</div>
                <div class="igny8-system-step-title">Add Keywords</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['keywords']['status'] === 'completed' ? '✅' : '⚠'; ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['keywords']['status'] === 'completed' ? 'Completed' : 'Missing'; ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['keywords']['count'] > 0): ?>
                        <?php echo $workflow_data['keywords']['count']; ?> keywords added
                    <?php else: ?>
                        No keywords yet
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['keywords']['status'] === 'missing' && $workflow_data['keywords']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['keywords']['url']); ?>" class="igny8-btn igny8-btn-primary">Go to Planner</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 2: Select Sector -->
            <div class="igny8-system-step <?php echo $workflow_data['sector']['status']; ?> <?php echo !$workflow_data['sector']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['sector']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['sector']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">2</div>
                <div class="igny8-system-step-title">Select Sector</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['sector']['status'] === 'completed' ? '✅' : '⚠'; ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['sector']['status'] === 'completed' ? 'Selected' : 'Required'; ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['sector']['selected']): ?>
                        Sector configured
                    <?php else: ?>
                        Required for AI workflows
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['sector']['status'] === 'missing' && $workflow_data['sector']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['sector']['url']); ?>" class="igny8-btn igny8-btn-primary">Configure</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 3: Auto Cluster -->
            <div class="igny8-system-step <?php echo $workflow_data['clusters']['status']; ?> <?php echo !$workflow_data['clusters']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['clusters']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['clusters']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">3</div>
                <div class="igny8-system-step-title">Auto Cluster</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['clusters']['status'] === 'completed' ? '✅' : ($workflow_data['clusters']['status'] === 'in_progress' ? '⏳' : '⚠'); ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['clusters']['status'] === 'completed' ? 'Completed' : ($workflow_data['clusters']['status'] === 'in_progress' ? 'In Progress' : 'Missing'); ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['clusters']['unmapped_keywords'] > 0): ?>
                        <?php echo $workflow_data['clusters']['unmapped_keywords']; ?> unmapped keywords
                    <?php elseif ($workflow_data['clusters']['count'] > 0): ?>
                        <?php echo $workflow_data['clusters']['count']; ?> clusters created
                    <?php else: ?>
                        No clusters yet
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['clusters']['status'] === 'in_progress' && $workflow_data['clusters']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['clusters']['url']); ?>" class="igny8-btn igny8-btn-primary">Start Clustering</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 4: Generate Ideas -->
            <div class="igny8-system-step <?php echo $workflow_data['ideas']['status']; ?> <?php echo !$workflow_data['ideas']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['ideas']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['ideas']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">4</div>
                <div class="igny8-system-step-title">Generate Ideas</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['ideas']['status'] === 'completed' ? '✅' : '⚠'; ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['ideas']['status'] === 'completed' ? 'Completed' : 'Missing'; ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['ideas']['count'] > 0): ?>
                        <?php echo $workflow_data['ideas']['count']; ?> ideas generated
                    <?php else: ?>
                        No ideas yet
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['ideas']['status'] === 'missing' && $workflow_data['ideas']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['ideas']['url']); ?>" class="igny8-btn igny8-btn-primary">Generate Ideas</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 5: Queue to Writer -->
            <div class="igny8-system-step <?php echo $workflow_data['queue']['status']; ?> <?php echo !$workflow_data['queue']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['queue']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['queue']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">5</div>
                <div class="igny8-system-step-title">Queue to Writer</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['queue']['status'] === 'completed' ? '✅' : ($workflow_data['queue']['status'] === 'in_progress' ? '⏳' : '⚠'); ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['queue']['status'] === 'completed' ? 'Completed' : ($workflow_data['queue']['status'] === 'in_progress' ? 'In Progress' : 'Missing'); ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['queue']['queued_ideas'] > 0): ?>
                        <?php echo $workflow_data['queue']['queued_ideas']; ?> ideas ready to queue
                    <?php else: ?>
                        All ideas queued
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['queue']['status'] === 'in_progress' && $workflow_data['queue']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['queue']['url']); ?>" class="igny8-btn igny8-btn-primary">Queue Ideas</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 6: Generate Drafts -->
            <div class="igny8-system-step <?php echo $workflow_data['drafts']['status']; ?> <?php echo !$workflow_data['drafts']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['drafts']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['drafts']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">6</div>
                <div class="igny8-system-step-title">Generate Drafts</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['drafts']['status'] === 'completed' ? '✅' : ($workflow_data['drafts']['status'] === 'in_progress' ? '⏳' : '⚠'); ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['drafts']['status'] === 'completed' ? 'Completed' : ($workflow_data['drafts']['status'] === 'in_progress' ? 'In Progress' : 'Missing'); ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['drafts']['queued_tasks'] > 0): ?>
                        <?php echo $workflow_data['drafts']['queued_tasks']; ?> tasks ready for AI
                    <?php elseif ($workflow_data['drafts']['draft_tasks'] > 0): ?>
                        <?php echo $workflow_data['drafts']['draft_tasks']; ?> drafts generated
                    <?php else: ?>
                        No drafts yet
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['drafts']['status'] === 'in_progress' && $workflow_data['drafts']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['drafts']['url']); ?>" class="igny8-btn igny8-btn-primary">Go to Writer</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
            
            <!-- Step 7: Publish Content -->
            <div class="igny8-system-step <?php echo $workflow_data['publish']['status']; ?> <?php echo !$workflow_data['publish']['module_enabled'] ? 'disabled' : ''; ?>" 
                 <?php if ($workflow_data['publish']['url']): ?>onclick="window.location.href='<?php echo admin_url($workflow_data['publish']['url']); ?>'"<?php endif; ?>>
                <div class="igny8-system-step-number">7</div>
                <div class="igny8-system-step-title">Publish Content</div>
                <div class="igny8-system-step-status">
                    <span class="igny8-system-step-status-icon"><?php echo $workflow_data['publish']['status'] === 'completed' ? '✅' : ($workflow_data['publish']['status'] === 'in_progress' ? '⏳' : '⚠'); ?></span>
                    <span class="igny8-system-step-status-text"><?php echo $workflow_data['publish']['status'] === 'completed' ? 'Completed' : ($workflow_data['publish']['status'] === 'in_progress' ? 'In Progress' : 'Missing'); ?></span>
                </div>
                <div class="igny8-system-step-data">
                    <?php if ($workflow_data['publish']['published_tasks'] > 0): ?>
                        <?php echo $workflow_data['publish']['published_tasks']; ?> content published
                    <?php elseif ($workflow_data['publish']['draft_tasks'] > 0): ?>
                        <?php echo $workflow_data['publish']['draft_tasks']; ?> drafts ready to publish
                    <?php else: ?>
                        No content to publish
                    <?php endif; ?>
                </div>
                <?php if ($workflow_data['publish']['status'] === 'in_progress' && $workflow_data['publish']['module_enabled']): ?>
                    <div class="igny8-system-step-action">
                        <a href="<?php echo admin_url($workflow_data['publish']['url']); ?>" class="igny8-btn igny8-btn-primary">Publish Now</a>
                    </div>
                <?php endif; ?>
                <div class="igny8-system-step-connector"></div>
            </div>
        </div>
    </div>
    
    <!-- Welcome Section -->
    <div class="igny8-card">
        <div class="igny8-card-header">
            <h3>Welcome to Igny8 AI SEO OS</h3>
        </div>
        <div class="igny8-card-body">
            <p>Your comprehensive SEO management platform. Use the workflow guide above to track your progress through the complete content creation and optimization pipeline.</p>
            <p>Each step shows your current status and provides direct links to the relevant modules. Click on any step to navigate to the appropriate section.</p>
        </div>
    </div>
</div>

<?php
// Capture page content
$igny8_page_content = ob_get_clean();

// Include global layout
include_once plugin_dir_path(__FILE__) . '../core/global-layout.php';
?>
