<%- title t('scripts.derivatives_title', script_name: @script.name) %>
<%- description "Potential derivatives of #{@script.name}" %>

<p><%= t('scripts.derivatives_intro') %></p>

<h3><%= t('scripts.derivatives_exact_copies_heading') %></h3>

<% identical_svs = @script.script_versions_with_identical_code.group_by(&:script_id).values %>

<% if identical_svs.any? %>
  <p><%= t('scripts.derivatives_exact_copies_list_intro') %></p>
  <ul>
    <% identical_svs.each do |svs| %>
      <li>
        <% script = svs.first.script %>
        <%= t('scripts.derivatives_exact_copies_item_html', script_link: render_script(script), author_links: script.users.map { |u| link_to u.name, user_path(u) }.to_sentence.html_safe, version_list: svs.map(&:version).uniq.join(', ')) %>
      </li>
    <% end %>
  </ul>
<% else %>
  <p><%= t('scripts.derivatives_exact_copes_none', site_name: site_name) %></p>
<% end %>

<h3><%= t('scripts.derivatives_similar_heading') %></h3>

<% check_date = @script.script_similarities.minimum(:checked_at) %>

<p><%= t('scripts.derivatives_similar_info') %></p>

<% if check_date %>
  <% if @similarities.any? %>
    <ul>
      <% @similarities.each do |other_script, score| %>
        <li title="<%= score %>">
          <%= it('scripts.derivatives_similar_item', score: similarity_string(score), diff_link: admin_script_path(@script, compare: script_url(other_script), anchor: 'script-comparison'), script: render_script(other_script)) %>
          <%= t('scripts.deleted_marker') if other_script.deleted? %>
        </li>
      <% end %>
    </ul>
  <% else %>
    <p>
      <%= t('scripts.derivatives_similar_none') %>
    </p>
  <% end %>
<% end %>

<p>
  <% if flash[:duplicates_enqueued] && check_date %>
    <%= t('scripts.derivatives_similar_last_check_again_soon_html', date: markup_date(check_date)) %>
  <% elsif check_date %>
    <%= t('scripts.derivatives_similar_last_check_html', date: markup_date(check_date)) %>
  <% else %>
    <%= t('scripts.derivatives_similar_last_check_soon') %>
  <% end %>

  <% if !flash[:duplicates_enqueued] && check_date && check_date < 1.day.ago %>
    <%= button_to t('scripts.derivatives_similar_check_now'), request_duplicate_check_script_path(@script), method: :POST %>
  <% end %>
</p>
