<% content_for :title, "Replay — #{@match.team.name} vs #{@match.opponent_name}" %>
<% content_for :meta_description, "Replay partita #{@match.team.name} vs #{@match.opponent_name} su Match Live TV." %>
<% content_for :robots, "noindex, nofollow" %>

<div class="wrap">
  <%= link_to "← Tutte le dirette", public_live_index_path, class: "back-link" %>

  <h1>Replay</h1>
  <p style="color:#aaa"><%= @match.team.name %> vs <%= @match.opponent_name %></p>

  <% if @recording %>
    <div class="card" style="margin:16px 0">
      <% if @session.hls_playback_url.present? %>
        <video id="replay-player" class="replay-video" controls playsinline></video>
        <script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.7"></script>
        <script>
          (function() {
            var src = "<%= j @session.hls_playback_url %>";
            var video = document.getElementById("replay-player");
            if (video.canPlayType("application/vnd.apple.mpegurl")) {
              video.src = src;
            } else if (typeof Hls !== "undefined" && Hls.isSupported()) {
              var hls = new Hls();
              hls.loadSource(src);
              hls.attachMedia(video);
            } else {
              video.outerHTML = "<p>Il replay non è disponibile su questo browser.</p>";
            }
          })();
        </script>
      <% else %>
        <p>Registrazione indicizzata. Il playback dipende dalla retention del piano Premium.</p>
      <% end %>
      <% if @recording.expires_at %>
        <p class="stream-ended-meta" style="margin-top:12px">Disponibile fino al <%= l_local(@recording.expires_at) %></p>
      <% end %>
    </div>
  <% end %>
</div>
