<% content_for :content do %>
  <section id="script-info">
    <ul id="script-links" class="tabs">
      <%= script_tab_link(script_path(@script, version: params[:version]), t('scripts.info_page')) %>
      <%= script_tab_link(show_code_script_path(@script, version: params[:version]), t('scripts.code_page')) %>
      <%= script_tab_link(script_script_versions_path(@script), t('scripts.history_page'), additional_current_check: ((controller_name == 'script_versions' && action_name == 'index') || (controller_name == 'scripts' && action_name == 'diff'))) %>
      <%= script_tab_link(feedback_script_path(@script, version: params[:version]), t('scripts.feedback_page', count: @script.discussions.visible.count), additional_current_check: (controller_name == 'discussions')) %>
      <%= script_tab_link(stats_script_path(@script, version: params[:version]), t('scripts.stats_page')) %>
      <% same_user = current_user && @script.user_ids.include?(current_user.id)
      user_is_mod = !current_user.nil? && current_user.moderator? %>
      <% if same_user || user_is_mod %>
        <%= script_tab_link(derivatives_script_path(@script, version: params[:version]), t('scripts.derivatives_page')) %>
      <% end %>
      <% if same_user %>
        <%= script_tab_link(new_script_script_version_path(@script.id), t('scripts.update_page')) %>
      <% end %>
      <% if same_user || user_is_mod %>
        <%= script_tab_link(delete_script_path(@script), t('scripts.delete_page')) %>
        <%= script_tab_link(admin_script_path(@script), t('scripts.admin_page'), additional_current_check: (action_name == 'sync_update')) %>
      <% end %>
    </ul>
    <header>
      <h2><%= @script.name(request_locale) %></h2>
      <p id="script-description" class="script-description"><%= @script.description(request_locale) %></p>
      <% if !params[:version].nil?
        latest_version_link = link_to t('scripts.version_notice_latest_version_link'), {:version => nil} %>
        <p id="version-note"><%= t('scripts.version_notice_html', date: markup_date(@script.updated_at), latest_version_link: latest_version_link.html_safe) %></p>
      <% end %>
      <% if (@script.pending_report_by_trusted_reporter? || @script.review_required?) && !@script.deleted? %>
        <p id="reported-note"><%= t('scripts.reported_notice_for_author') %></p>
      <% end %>
      <% if @script.deleted? %>
        <p id="deleted-note">
          <% report = @script.report_that_deleted %>
          <% if @script.locked? && report %>
            <% if @script.self_deleted %>
              <% if same_user %>
                <%= it('scripts.self_deleted_locked_author_notice_html', delete_reason: delete_reason(@script), appeal_link: new_script_script_lock_appeal_path(@script), code_rules_link: help_code_rules_path, site_name: site_name, report_link: report_path(report)) %>
              <% else %>
                This script was deleted by the author in response to <%= link_to "report ##{report.id}", report_path(report) %>.
              <% end %>
            <% else %>
              <%= it('scripts.deleted_locked_author_notice_html', delete_reason: delete_reason(@script), appeal_link: new_script_script_lock_appeal_path(@script), code_rules_link: help_code_rules_path, site_name: site_name, report_link: report_path(report)) %>
            <% end %>
          <% else %>
            <%= t('scripts.deleted_author_notice') %>
          <% end %>
        </p>
      <% end %>
    </header>
    <div id="script-content">
      <%= content_for?(:scripts_content) ? yield(:scripts_content) : yield %>
    </div>
  </section>
<% end %>

<% content_for(:head_bottom) do %>
  <meta name="twitter:card" content="summary">
  <meta property="og:title" content="<%= @script.default_name %>">
  <meta property="og:url" content="<%= script_url(@script, locale: nil) %>">
  <meta property="og:description" content="<%= @script.description(request_locale) %>">
  <% if @script_version && !@script_version.new_record? %>
    <%# Same as in screenshots/_show.html.erb %>
    <% attachments = @script_version.attachments.includes(:blob).load %>
    <% if attachments.any? %>
      <meta property="og:image" content="<%= attachments.first.blob.url %>">
    <% end %>
  <% end %>
<% end %>

<%= render template: 'layouts/base' %>
