<?php
/**
 * Generate HTML previews for footer templates
 * Run this script to generate preview HTML files that can be converted to images
 * 
 * Usage: php generate-previews.php
 */

if (!defined('ABSPATH')) {
    // Allow running from command line
    define('ABSPATH', dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/');
}

// Load WordPress
require_once ABSPATH . 'wp-load.php';

if (!defined('ABSPATH')) {
    die('WordPress not loaded');
}

// Template directory
$template_dir = __DIR__ . '/templates/';
$preview_dir = __DIR__ . '/previews/';

// Create previews directory if it doesn't exist
if (!file_exists($preview_dir)) {
    mkdir($preview_dir, 0755, true);
}

// Mock settings for preview
$mock_settings = array(
    'activefooter' => '1',
    'footer_template' => 'Footer1'
);

// Mock class for template rendering
class MockFooterBase {
    public $aiautotool_footer_settings;
    
    public function __construct($settings) {
        $this->aiautotool_footer_settings = $settings;
    }
}

// Generate preview for each template
for ($i = 1; $i <= 7; $i++) {
    $template_file = $template_dir . 'template-' . $i . '.php';
    
    if (!file_exists($template_file)) {
        echo "Template $i not found: $template_file\n";
        continue;
    }
    
    $mock = new MockFooterBase($mock_settings);
    
    // Capture template output
    ob_start();
    include $template_file;
    $template_output = ob_get_clean();
    
    // Create preview HTML
    $preview_html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Footer Template $i Preview</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            background: #f5f5f5;
            padding: 20px;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        }
        .preview-container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .preview-header {
            background: #333;
            color: white;
            padding: 15px 20px;
            font-size: 18px;
            font-weight: bold;
        }
        .preview-content {
            position: relative;
        }
    </style>
</head>
<body>
    <div class="preview-container">
        <div class="preview-header">Footer Template $i - Preview</div>
        <div class="preview-content">
            $template_output
        </div>
    </div>
</body>
</html>
HTML;
    
    // Save preview HTML
    $preview_file = $preview_dir . 'preview-' . $i . '.html';
    file_put_contents($preview_file, $preview_html);
    echo "Generated preview for Template $i: $preview_file\n";
}

echo "\nAll previews generated successfully!\n";
echo "You can now:\n";
echo "1. Open the HTML files in a browser\n";
echo "2. Take screenshots of each preview\n";
echo "3. Save them as footer1.png, footer2.png, etc. in the images/footer/ directory\n";
?>






