<?php

namespace PloverCRM\Modules\Integrations\Helpers;

use PloverCRM\Common\BaseLogViewer;

/**
 * Webhooks Integration Log Viewer
 * 
 * Handles viewing and downloading webhook integration logs
 */
class WebhooksLogViewer extends BaseLogViewer
{
  public function __construct()
  {
    parent::__construct('data-sources/webhooks', 'webhooks');
  }

  /**
   * Render log viewer for webhook integrations
   */
  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: 30px;">';
    echo '<h3 style="margin-top: 0;">Webhook Logs</h3>';
    echo '<p style="color: #666;">Activity log for your webhooks. Shows when data is received and contacts are created or updated.</p>';

    $viewer->renderLogEntries($logs);

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

    echo '</div>';
  }
}
