<div class="profiler-panel log-panel">
  <h2>Logs</h2>

  <div class="log-summary">
    <span class="log-count">{{ data.count }} log entries</span>
    {% if data.error_count > 0 %}
    <span class="error-count"
      >{{ data.error_count }} error{% if data.error_count > 1 %}s{% endif
      %}</span
    >
    {% endif %}
  </div>

  <div class="log-filters">
    <div class="filter-group">
      <input type="text" class="log-filter" placeholder="Filter logs..." />
      <button class="clear-filter" title="Clear filter">×</button>
    </div>
    <div class="select-controls">
      <select class="log-level-filter">
        <option value="all">All levels</option>
        <option value="debug">DEBUG</option>
        <option value="info">INFO</option>
        <option value="warning">WARNING</option>
        <option value="error">ERROR</option>
        <option value="critical">CRITICAL</option>
      </select>
      <select class="log-limit">
        <option value="50">50 entries</option>
        <option value="100">100 entries</option>
        <option value="200">200 entries</option>
        <option value="500">500 entries</option>
        <option value="all">All entries</option>
      </select>
    </div>
  </div>

  <div class="logs-table">
    <table>
      <thead>
        <tr>
          <th class="time-col">Time</th>
          <th class="channel-col">Channel</th>
          <th class="level-col">Level</th>
          <th class="message-col">Message</th>
        </tr>
      </thead>
      <tbody class="logs-container">
        {% for record in data.records %}
        <tr class="log-entry" data-level="{{ record.level | lower }}">
          <td class="time-col">{{ record.timestamp | date("%H:%M:%S") }}</td>
          <td class="channel-col">{{ record.channel }}</td>
          <td class="level-col">
            <span class="log-badge {{ record.level | lower }}"
              >{{ record.level }}</span
            >
          </td>
          <td class="message-col">{{ record.message }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>

  <div class="load-more-container" style="display: none">
    <button class="load-more-btn">Load more logs</button>
    <span class="showing-count"></span>
  </div>
</div>

<style>
  /* Styles pour le panel de logs */
  .log-summary {
    margin-bottom: 15px;
    font-weight: bold;
  }

  .error-count {
    color: #e74c3c;
    margin-left: 15px;
  }

  .log-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 15px;
    align-items: center;
    justify-content: space-between;
  }

  .filter-group {
    position: relative;
    width: 200px;
    min-width: 200px;
    flex-shrink: 0;
  }

  .log-filter {
    width: 100%;
    padding: 8px 30px 8px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }

  .clear-filter {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #888;
    display: none;
  }

  .log-level-filter,
  .log-limit {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
  }

  .logs-table {
    margin-top: 15px;
    border: 1px solid #eee;
    border-radius: 4px;
    overflow: auto;
    max-height: 500px;
  }

  .logs-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }

  .logs-table th {
    background-color: #f8f8f8;
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 1;
  }

  .logs-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
  }

  .time-col {
    width: 80px;
    white-space: nowrap;
  }

  .channel-col {
    width: 140px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .level-col {
    width: 90px;
    text-align: center;
  }

  .message-col {
    word-break: break-word;
  }

  .log-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
    color: white;
    min-width: 60px;
    text-align: center;
  }

  /* Couleurs des niveaux de logs - pour les badges */
  .log-badge.debug {
    background-color: #6c757d;
  }

  .log-badge.info {
    background-color: #17a2b8;
  }

  .log-badge.warning {
    background-color: #ffc107;
    color: #333;
  }

  .log-badge.error {
    background-color: #dc3545;
  }

  .log-badge.critical {
    background-color: #721c24;
  }

  /* Couleurs des niveaux de logs - pour les lignes entières */
  .log-entry[data-level="debug"] {
    background-color: rgba(108, 117, 125, 0.08);
  }

  .log-entry[data-level="info"] {
    background-color: rgba(23, 162, 184, 0.08);
  }

  .log-entry[data-level="warning"] {
    background-color: rgba(255, 193, 7, 0.12);
  }

  .log-entry[data-level="error"] {
    background-color: rgba(220, 53, 69, 0.08);
  }

  .log-entry[data-level="critical"] {
    background-color: rgba(114, 28, 36, 0.12);
  }

  /* Load More button */
  .load-more-container {
    text-align: center;
    margin: 15px 0;
    padding: 10px;
    background-color: #f8f8f8;
    border-top: 1px solid #eee;
  }

  .load-more-btn {
    background-color: #f4bf5f;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    color: #333;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
  }

  .load-more-btn:hover {
    background-color: #e5a94d;
  }

  .showing-count {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 12px;
  }
</style>
