<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
      line-height: 1.6;
      color: #333;
      max-width: 600px;
      margin: 0 auto;
      padding: 20px;
    }
    .header {
      padding: 20px;
      background: #fee2e2;
      margin: -20px -20px 0 -20px;
      border-bottom: 3px solid #dc2626;
    }
    .content { padding: 20px 0; }
    .priority-badge {
      display: inline-block;
      padding: 4px 12px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: bold;
      text-transform: uppercase;
    }
    .priority-low { background: #e5e7eb; color: #374151; }
    .priority-normal { background: #dbeafe; color: #1e40af; }
    .priority-high { background: #ffedd5; color: #9a3412; }
    .priority-urgent { background: #fee2e2; color: #991b1b; }
    .ticket-info {
      background: #f9fafb;
      padding: 15px;
      border-radius: 8px;
      margin: 20px 0;
    }
    .breach-notice {
      background: #fee2e2;
      border: 2px solid #dc2626;
      padding: 15px;
      border-radius: 8px;
      text-align: center;
      margin: 20px 0;
      color: #991b1b;
    }
    .breach-notice strong {
      font-size: 18px;
    }
    .button {
      display: inline-block;
      background-color: #dc2626;
      color: white;
      text-decoration: none;
      padding: 12px 24px;
      border-radius: 6px;
      font-weight: 500;
    }
    .footer {
      font-size: 12px;
      color: #9ca3af;
      border-top: 1px solid #eee;
      padding-top: 20px;
      margin-top: 30px;
    }
    .stats {
      display: flex;
      justify-content: space-around;
      margin: 20px 0;
    }
    .stat {
      text-align: center;
    }
    .stat-value {
      font-size: 24px;
      font-weight: bold;
      color: #991b1b;
    }
    .stat-label {
      font-size: 12px;
      color: #6b7280;
    }
  </style>
</head>
<body>
  <div class="header">
    <h2 style="margin: 0; color: #991b1b;">SLA BREACH</h2>
  </div>

  <div class="content">
    <div class="breach-notice">
      <strong>This ticket has exceeded its SLA response time</strong>
    </div>

    <div class="ticket-info">
      <span class="priority-badge priority-<%= @ticket.priority %>"><%= @ticket.priority %></span>
      <br><br>
      <strong><%= @ticket.ticket_number %></strong> - <%= @ticket.subject %><br>
      <span style="color: #6b7280;">Website: <%= @website.subdomain %></span>
    </div>

    <table style="width: 100%; border-collapse: collapse; margin: 20px 0;">
      <tr>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><strong>Customer</strong></td>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><%= @ticket.creator.display_name %></td>
      </tr>
      <tr>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><strong>Created</strong></td>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><%= @ticket.created_at.strftime('%B %d, %Y at %I:%M %p') %></td>
      </tr>
      <tr>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><strong>Time Elapsed</strong></td>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><%= distance_of_time_in_words(@ticket.created_at, Time.current) %></td>
      </tr>
      <tr>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><strong>Assigned To</strong></td>
        <td style="padding: 8px 0; border-bottom: 1px solid #eee;"><%= @ticket.assigned_to&.display_name || 'Unassigned' %></td>
      </tr>
      <tr>
        <td style="padding: 8px 0;"><strong>Status</strong></td>
        <td style="padding: 8px 0;"><%= @ticket.status.humanize %></td>
      </tr>
    </table>

    <p style="text-align: center; margin-top: 25px;">
      <a href="<%= tenant_admin_support_ticket_url(@ticket, host: ENV.fetch('BASE_DOMAIN', 'localhost:3000')) %>" class="button">
        Respond Immediately
      </a>
    </p>
  </div>

  <div class="footer">
    <p>This is an automated SLA monitoring notification. Please respond to this ticket as soon as possible.</p>
  </div>
</body>
</html>
