<%# locals: ()  %>

<section id="script-comparison" class="multiform-page">
  <h3><%= t('scripts.admin.compare_title') %></h3>

  <%= form_with(url: admin_script_path(@script, anchor: 'script-comparison'), method: :GET, html: { class: 'diff_options' }) do |f| %>
    <div class="form-control">
      <%= f.label :compare, t('scripts.admin.compare_to', site_name: site_name) %>
      <%= f.url_field :compare, required: true, value: params[:compare], placeholder: 'https://greasyfork.org/…' %>
    </div>
    <%= render partial: 'diff_options', locals: { context: @context} %>
    <%= f.submit t('scripts.admin.compare_button') %>
  <% end %>

  <% if @diff_error %>
    <p class="notice"><%= @diff_error %></p>
  <% elsif @diff %>
    <p>
      <%= link_to(@other_script.name(request_locale), show_code_script_path(@other_script)) %><br>
    </p>

    <% if current_user.moderator? %>
      <p>
        <%= link_to delete_script_path(@script, delete_type: 'keep', replaced_by_script_id: script_url(@other_script)) do %>
          Mark <i><%= @script.name(request_locale) %></i> as a copy of <i><%= @other_script.name(request_locale) %></i>
        <% end %>
        <br>
        <%= link_to delete_script_path(@other_script, delete_type: 'keep', replaced_by_script_id: script_url(@script)) do %>
          Mark <i><%= @other_script.name(request_locale) %></i> as a copy of <i><%= @script.name(request_locale) %></i>
        <% end %>
      </p>
    <% end %>

    <% if @diff.diff.empty? %>
      <p class="notice"><%= t('scripts.diff_no_change') %></p>
    <% else %>
      <%= @diff.to_s(:html).html_safe %>
    <% end %>
  <% end %>
</section>
