<?php

namespace PloverCRM\Modules\NativeCRM\Helpers;

use PloverCRM\Common\BaseLogViewer;

/**
 * Log Viewer Helper
 * 
 * Handles viewing and downloading built-in CRM logs
 */
class LogViewer extends BaseLogViewer
{
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct('native-crm', 'native-crm');
    }

    /**
     * Render log viewer for the built-in CRM
     */
    public static function render(): void
    {
        $viewer = new self();
        $logs = $viewer->getRecentLogs();

        echo '<div style="padding: 20px; background: #fff; border: 1px solid #ddd; border-radius: 4px; margin-top: 20px;">';
        echo '<h3>Built-in CRM Logs</h3>';
        echo '<p>View logs for built-in CRM operations (last 7 days).</p>';

        $viewer->renderLogEntries($logs);

        if (!empty($logs)) {
            echo '<div style="margin-top: 15px;">';
            echo \PloverCRM\Common\BaseLogViewer::getDownloadButton('native-crm');
            echo '</div>';
        }

        echo '</div>';
    }
}
