<%= render RailwayUiWeb.MessageView, "live_flash.html", assigns %>
<div class="row justify-content-md-center">
  <div class="col-md-auto w-100 p-3">
    <h1 class="display-3">Published Messages</h1>
    <%= live_component @socket, RailwayUiWeb.MessageLive.SearchComponent, view: @view, search: @state.search, id: :search %>
    <table class="table table-responsive pt-3 table-hover" phx-update="replace">
      <thead>
        <tr>
          <th>Message Type</th>
          <th>UUID</th>
          <th>Queue</th>
          <th>Exchange</th>
          <th>Encoded Message</th>
          <th>Correlation ID</th>
          <th>User UUID</th>
        </tr>
      </thead>
      <tbody>
        <%= for message <- @messages do %>
          <tr>
            <td><%= message.message_type %></td>
            <td><%= message.uuid %></td>
            <td><%= message.queue %></td>
            <td><%= message.exchange %></td>
            <td><%= decode_message_body(message.encoded_message) %></td>
            <td><%= message.correlation_id %></td>
            <td><%= message.user_uuid %></td>
            <%= if message.message_type != "LearnIpc::Commands::RepublishMessage" do %>
              <td><button class="btn btn-info" phx-click="republish" phx-value-message_uuid="<%= message.uuid %>">republish</button></td>
            <% end %>
          </tr>
        <% end %>
      </tbody>
    </table>
    <%= render RailwayUiWeb.MessageView, "pagination.html", assigns %>
  </div>
</div>
