<% provide :title do %><%= @proposal.title %><% end %>
<% content_for :meta_description do %><%= @proposal.summary %><% end %>
<% provide :social_media_meta_tags do %>
<%= render "shared/social_media_meta_tags",
            social_url: proposal_url(@proposal),
            social_title: @proposal.title,
            social_description: @proposal.summary %>
<% end %>
<% content_for :canonical do %>
  <%= render "shared/canonical", href: proposal_url(@proposal) %>
<% end %>

<% cache [locale_and_user_status(@proposal), @proposal, @proposal.author, Flag.flagged?(current_user, @proposal), @proposal_votes] do %>
  <div class="proposal-show">
    <div id="<%= dom_id(@proposal) %>" class="row">
      <div class="small-12 medium-9 column">
        <%= back_link_to %>

        <h1><%= @proposal.title %></h1>
        <% if @proposal.retired? %>
          <div data-alert class="callout alert margin-top proposal-retired">
            <strong>
              <%= t("proposals.show.retired_warning") %><br>
              <%= link_to t("proposals.show.retired_warning_link_to_explanation"), "#retired_explanation" %>
            </strong>
          </div>
        <% elsif @proposal.conflictive? %>
          <div data-alert class="callout alert margin-top">
            <strong><%= t("proposals.show.flag") %></strong>
          </div>
        <% end %>

        <div class="proposal-info">
          <%= render '/shared/author_info', resource: @proposal %>

          <span class="bullet">&nbsp;&bull;&nbsp;</span>
          <%= l @proposal.created_at.to_date %>
          <span class="bullet">&nbsp;&bull;&nbsp;</span>
          <span class="icon-comments"></span>&nbsp;
          <%= link_to t("proposals.show.comments", count: @proposal.comments_count), "#comments" %>

          <% if current_user %>
            <span class="bullet">&nbsp;&bull;&nbsp;</span>
            <span class="js-flag-actions">
              <%= render 'proposals/flag_actions', proposal: @proposal %>
            </span>
          <% end %>

        </div>

        <%= render_image(@proposal.image, :large, true) if @proposal.image.present? %>

        <br>
        <p>
          <%= t("proposals.show.code") %>
          <strong><%= @proposal.code %></strong>
        </p>

        <blockquote><%= @proposal.summary %></blockquote>

        <% if @proposal.video_url.present? %>
          <div class="small-12 medium-7 small-centered">
            <div class="flex-video">
              <div id="js-embedded-video" data-video-code="<%= embedded_video_code %>"></div>
            </div>
          </div>
        <% end %>

        <%= safe_html_with_links @proposal.description %>

        <% if feature?(:map) && map_location_available?(@proposal.map_location) %>
          <div class="margin">
            <%= render_map(@proposal.map_location, "proposal", false, nil) %>
          </div>
        <% end %>

        <% if @proposal.external_url.present? %>
          <div class="document-link">
            <p>
              <span class="icon-document"></span>&nbsp;
              <strong><%= t('proposals.show.title_external_url') %></strong>
            </p>
              <%= text_with_links @proposal.external_url %>
          </div>
        <% end %>

        <% if @proposal.video_url.present? %>
          <div class="video-link">
            <p>
              <span class="icon-video"></span>&nbsp;
              <strong><%= t('proposals.show.title_video_url') %></strong>
            </p>
            <%= text_with_links @proposal.video_url %>
          </div>

        <% end %>

        <h4><%= @proposal.question %></h4>

        <% if @proposal.retired? %>
          <div id="retired_explanation" class="callout">
            <h2><%= t('proposals.show.retired') %>: <%= t("proposals.retire_options.#{@proposal.retired_reason}") unless @proposal.retired_reason == 'other' %></h2>
            <%= simple_format text_with_links(@proposal.retired_explanation), {}, sanitize: false %>
          </div>
        <% end %>

        <%= render 'shared/tags', taggable: @proposal %>

        <%= render 'shared/geozone', geozonable: @proposal %>

        <%= render 'relationable/related_content', relationable: @proposal %>

        <div class="js-moderator-proposal-actions margin">
          <%= render 'proposals/actions', proposal: @proposal %>
        </div>
      </div>

      <aside class="small-12 medium-3 column">
        <% if author_of_proposal?(@proposal) || current_editable?(@proposal) || can_destroy_image?(@proposal) %>
          <div class="sidebar-divider"></div>
          <h2><%= t("proposals.show.author") %></h2>
          <div class="show-actions-menu">

            <% if current_editable?(@proposal) %>
              <%= link_to edit_proposal_path(@proposal), class: 'button hollow expanded' do %>
                          <span class="icon-edit"></span>
                          <%= t("proposals.show.edit_proposal_link") %>
              <% end %>
            <% end %>

            <% if author_of_proposal?(@proposal) %>
              <%= link_to new_proposal_notification_path(proposal_id: @proposal.id),
                          class: 'button hollow expanded' do %>
                          <span class="icon-no-notification"></span>
                          <%= t("proposals.show.send_notification") %>
              <% end %>
            <% end %>

            <% if can_destroy_image?(@proposal) %>
              <%= link_to image_path(@proposal.image, from: request.url),
                          method: :delete,
                          class: 'button hollow alert expanded',
                          data: { confirm: t('images.actions.destroy.confirm') } do %>
                          <span class="icon-image"></span>
                          <%= t("images.remove_image") %>
              <% end %>
            <% end %>

          </div>
        <% end %>

        <div class="sidebar-divider"></div>
        <h2><%= t("votes.supports") %></h2>
        <div id="<%= dom_id(@proposal) %>_votes">

          <% if @proposal.successful? %>
            <p>
              <%= t("proposals.proposal.successful",
                  voting: link_to(t("proposals.proposal.voting"), polls_path)).html_safe %>
            </p>
            <% if can? :create, Poll::Question %>
              <p class="text-center">
                <%= link_to t('poll_questions.create_question'),
                            new_admin_question_path(proposal_id: @proposal.id),
                            class: "button hollow expanded" %>
              </p>
            <% end %>
          <% elsif @proposal.archived? %>
            <div class="padding text-center">
              <p>
                <strong><%= t("proposals.proposal.supports", count: @proposal.total_votes) %></strong>
              </p>
              <p><%= t("proposals.proposal.archived") %></p>
            </div>
          <% else %>
            <%= render 'votes',
                      { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %>
          <% end %>
        </div>
        <%= render partial: 'shared/social_share', locals: {
          share_title: t("proposals.show.share"),
          title: @proposal.title,
          url: proposal_url(@proposal)
        } %>

        <% if current_user %>
          <div class="sidebar-divider"></div>
          <p class="sidebar-title"><%= t("shared.follow") %></p>

          <%= render 'follows/follow_button', follow: find_or_build_follow(current_user, @proposal)  %>
        <% end %>

        <%= render 'communities/access_button', community: @proposal.community %>

      </aside>
    </div>
  </div>
<% end %>

<div class="tabs-content" data-tabs-content="proposals-tabs" role="tablist">
  <%= render "proposals/filter_subnav" %>
  <%= render "proposals/notifications" %>

  <div class="tabs-panel is-active" id="tab-comments">
    <%= render "proposals/comments" %>
  </div>

  <div class="tabs-panel" id="tab-documents">
    <%= render 'documents/documents',
                documents: @proposal.documents,
                max_documents_allowed: Proposal.max_documents_allowed %>
  </div>
</div>
