<%- title t('scripts.history_title', script_name: @script.name(request_locale)) %>
<%- description "Version history for #{@script.name(request_locale)}" %>

<%= render partial: 'shared/in_page_ad', locals: { ad_method: @ad_method, div_id: 'script-versions-list-ad', adsense_slot: '8369077042', ea_div_id: 'script-versions-list-ea-image', fallback_ea: true} %>

<%
show_diff = @script.script_versions.length > 1
show_all_versions = !params[:show_all_versions].nil?
if show_diff
  if !show_all_versions %>
    <p><%= t('scripts.history_only_code_changes_info') %> <%= link_to t('scripts.history_all_changes_link'), show_all_versions: 1 %></p>
  <% else %>
    <p><%= t('scripts.history_all_changes_info') %> <%= link_to t('scripts.history_only_code_changes_link'), show_all_versions: nil %></p>
  <% end
end %>
<form action="<%= diff_script_path(params[:script_id]) %>">
  <% if show_diff %>
    <%= submit_tag t('scripts.diff_button'), name: nil %>
  <% end %>
  <ul class="history_versions">
    <% @script_versions.each_with_index do |sv, i| %>
      <li>
        <% if show_diff %>
          <span class="diff-controls">
            <input required type="radio" name="v1" value="<%= sv.id %>"<% if i == 0 %> checked<% end %>><input required type="radio" name="v2" value="<%= sv.id %>"<% if i == 1 %> checked<% end %>>
          </span>
        <% end %>
        <span class="version-number">
          <%= link_to t('scripts.version_abbreviation', number: sv.version), script_path(sv.script, version: sv.id), rel: :nofollow %>
          <% if !current_user.nil? && current_user.moderator? %>
            <%= link_to 'Delete', script_script_version_delete_path(script_id: sv.script.id, script_version_id: sv.id) %>
          <% end %>
        </span>
        <%= markup_date(sv.created_at, class: 'version-date') %>
        <% if sv.changelog.present? %>
          <span class="version-changelog">
            <%= format_user_text(sv.changelog, sv.changelog_markup) %>
          </span>
        <% end %>
      </li>
    <% end %>
  </ul>
  <% if show_diff %>
    <p>
      <%= submit_tag t('scripts.diff_button'), name: nil %>
    </p>
  <% end %>
  <%= render_pagination %>
  <% if multiple_pages? %>
    <p>
      <%= link_to t('scripts.list_all_script_versions'), { list_all: 1 }, { rel: :nofollow } %>
    </p>
  <% end %>
</form>
