<%- title @script.name(request_locale) %>
<%- description @script.description(request_locale) %>

<%= render partial: 'install', locals: {script: @script, script_version: @script_version} %>

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

<%= render partial: 'feedback_suggestion', locals: {script: @script} %>

<div class="script-meta-block">
  <dl id="script-stats" class="inline-script-stats">
    <dt class="script-show-author"><span><%= t('scripts.author_name') %></span></dt>
    <dd class="script-show-author"><span><%= @script.users.map { |u| link_to(u.name, u) }.to_sentence.html_safe %></span></dd>
    <% if !@script.library? && params[:version].nil? %>
    <dt class="script-show-daily-installs"><span><%= t('scripts.daily_installs') %></span></dt>
    <dd class="script-show-daily-installs"><span><%= number_with_delimiter(@script.daily_installs) %></span></dd>
    <dt class="script-show-total-installs"><span><%= t('scripts.total_installs') %></span></dt>
    <dd class="script-show-total-installs"><span><%= number_with_delimiter(@script.total_installs) %></span></dd>
    <% end %>
    <% unless @script.library? %>
    <dt class="script-list-ratings"><span><%= t('scripts.ratings') %></span></dt>
    <dd class="script-list-ratings"><span><%= render partial: 'ratings', locals: {script: @script} %></span></dd>
    <% end %>
    <dt class="script-show-version"><span><%= t('scripts.version_number') %></span></dt>
    <dd class="script-show-version"><span><%= @script_version.version %></span></dd>
    <dt class="script-show-created-date"><span><%= t('scripts.created_date') %></span></dt>
    <dd class="script-show-created-date"><span><%= markup_date(@script.created_at) %></span></dd>
    <dt class="script-show-updated-date"><span><%= t('scripts.updated_date') %></span></dt>
    <dd class="script-show-updated-date"><span><%= markup_date(@script.code_updated_at) %></span></dd>
    <dt class="script-show-code-size"><span><%= t('scripts.code_size') %></span></dt>
    <dd class="script-show-code-size"><span><%= number_to_human_size(@script.code_size) %></span></dd>
    <% if !@script.library? && !@script.compatibilities.empty? %>
      <dt class="script-show-compatibility"><span><%= t('scripts.compatibility') %></span></dt>
      <dd class="script-show-compatibility"><span>
        <% Browser.all.each do |b|
          b_compatibilities = @script.compatibilities.select{|c| c.browser == b }
          if b_compatibilities.empty?
            status = 'unknown'
          elsif b_compatibilities.all?{|c| c.compatible}
            status = 'compatible'
          elsif b_compatibilities.all?{|c| !c.compatible}
            status = 'incompatible'
          else
            # a mixture
            status = 'unknown'
          end
          # show icons for compatible and incompatible
          if status == 'incompatible' %>
            <%= vite_image_tag 'images/x.svg', class: 'browser-incompatible-marker', alt: '' %>
            <%= vite_image_tag "images/browsericons/#{b.code}.svg", class: 'browser-incompatible', alt: t('scripts.incompatible_with_browser', browser: b.name), title: b_compatibilities.map(&:comments).reject(&:blank?).join("\n").presence || t('scripts.incompatible_with_browser', browser: b.name) %>
          <% elsif status == 'compatible' %>
            <%= vite_image_tag "images/browsericons/#{b.code}.svg", class: 'browser-compatible', alt: t('scripts.compatible_with_browser', browser: b.name), title: b_compatibilities.map(&:comments).reject(&:blank?).join("\n").presence || t('scripts.compatible_with_browser', browser: b.name) %>
          <% end %>
        <% end %>
      </span></dd>
    <% end %>
    <dt class="script-show-license"><span><%= t('scripts.license') %></span></dt>
    <dd class="script-show-license"><span><%= license_display(@script) %></span></dd>
    <% if @script.antifeatures.any? %>
      <dt class="script-antifeatures"><span><%= t('scripts.antifeatures.label') %></span></dt>
      <dd class="script-antifeatures">
        <span>
          <%= safe_join(@script.best_antifeatures_for_locale(request_locale).map do |antifeature|
            tag.span(title: strip_tags(t("scripts.antifeatures.types.#{antifeature.antifeature_type}.description_html", site_name: site_name))) { t("scripts.antifeatures.types.#{antifeature.antifeature_type}.title") }
          end, ', ') %>
        </span>
      </dd>
    <% end %>
    <% unless @script.library? %>
      <dt class="script-show-applies-to"><span><%= t('scripts.applies_to') %></span></dt>
      <dd class="script-show-applies-to">
        <% if @script.script_applies_tos.empty? %>
          <%= t('scripts.applies_to_all') %>
        <% else %>
          <ul class="block-list expandable">
            <% script_applies_to_list_contents(@script).each do |script_applies_to_content| %>
              <li><%= script_applies_to_content %></li>
            <% end %>
          </ul>
        <% end %>
      </dd>
    <% end %>
  </dl>
</div>

<% localized_additional_info = @script.localized_attribute_for('additional_info', request_locale)
if localized_additional_info.present? || @script_version.attachments.any? %>
  <div id="additional-info" class="user-content" <% if !localized_additional_info.nil? %> lang="<%= localized_additional_info.locale.code %>"<% end %>>
    <%= format_user_text(localized_additional_info.attribute_value, localized_additional_info.value_markup, mentions: localized_additional_info.mentions, relative_url_base: localized_additional_info.sync_identifier) if localized_additional_info %>
    <%= render partial: 'screenshots/show', locals: { attachable: @script_version } %>
  </div>
<% elsif (similar_scripts = @script.similar_scripts(script_subset: script_subset, locale: request_locale)).any? %>
  <hr>
  <p>
    <%= t('scripts.related_scripts') %>
  </p>
  <ul>
    <% similar_scripts.each do |script| %>
      <li><%= render_script(script) %> - <span class="script-description"><%= script.description(request_locale) %></span></li>
    <% end %>
  </ul>
<% end %>
