<% provide :social_media_meta_tags do %>
  <%= render "shared/social_media_meta_tags",
             social_url: budget_investments_path(investment),
             social_title: investment.title,
             social_description: investment.description,
             twitter_image_url: (investment.image.present? ? polymorphic_path(investment.image.variant(:thumb)) : nil),
             og_image_url: (investment.image.present? ? polymorphic_path(investment.image.variant(:thumb)) : nil) %>
<% end %>

<section class="budget-investment-show" id="<%= dom_id(investment) %>">
  <div class="row">
    <% cache [locale_and_user_status(investment),
              investment,
              investment.author,
              Flag.flagged?(current_user, investment)] do %>
      <div class="small-12 medium-9 column">
        <%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>

        <%= render "/budgets/investments/investment_detail", investment: investment %>
      </div>
    <% end %>

    <aside class="small-12 medium-3 column">
      <%= render "/budgets/investments/author_actions", investment: investment %>

      <% if investment.should_show_aside? %>
        <% if investment.should_show_votes? %>
          <div class="sidebar-divider"></div>
          <h2><%= t("budgets.investments.show.supports") %></h2>
          <div class="text-center">
            <div id="<%= dom_id(investment) %>_votes">
              <%= render Budgets::Investments::VotesComponent.new(investment) %>
            </div>
          </div>
        <% elsif investment.should_show_vote_count? %>
          <div class="sidebar-divider"></div>
          <h2><%= t("budgets.investments.show.supports") %></h2>
          <div class="text-center">
            <span class="total-supports">
              <strong>
                <%= t("budgets.investments.investment.supports",
                      count: investment.total_votes) %>
              </strong>
            </span>
          </div>
        <% elsif investment.should_show_ballots? %>
          <div class="sidebar-divider"></div>
          <h2><%= t("budgets.investments.show.votes") %></h2>
          <div class="text-center">
            <div id="<%= dom_id(investment) %>_ballot">
              <%= render "ballot",
                         investment: investment,
                         investment_ids: investment_ids,
                         ballot: ballot %>
            </div>
          </div>
        <% end %>
      <% end %>

      <% if investment.unfeasible? && investment.valuation_finished? %>
        <div class="callout warning">
          <%= sanitize(t("budgets.investments.show.project_unfeasible")) %>
        </div>
      <% elsif investment.winner? && @budget.finished? %>
        <div class="callout success">
          <strong><%= t("budgets.investments.show.project_winner") %></strong>
        </div>
      <% elsif investment.selected? %>
        <div class="callout success">
          <%= sanitize(t("budgets.investments.show.project_selected")) %>
        </div>
      <% elsif @budget.balloting_or_later? %>
        <div class="callout warning">
          <%= sanitize(t("budgets.investments.show.project_not_selected")) %>
        </div>
      <% else %>
        <br>
        <div class="float-right">
          <span class="label-budget-investment float-left">
            <%= t("budgets.investments.show.title") %>
          </span>
          <span class="icon-budget"></span>
        </div>
      <% end %>
      <% if investment.should_show_price? %>
        <div class="sidebar-divider"></div>
        <h2><%= t("budgets.investments.show.price") %></h2>
        <div class="supports text-center">
          <p class="investment-project-amount">
            <%= investment.formatted_price %>
          </p>
        </div>
        <% if investment.should_show_price_explanation? %>
          <div class="text-center" data-magellan>
            <%= link_to t("budgets.investments.show.see_price_explanation"),
                        "#price_explanation",
                        class: "small" %>
          </div>
        <% end %>
      <% end %>

      <%= render "shared/social_share",
                 share_title: t("budgets.investments.show.share"),
                 title: investment.title,
                 image_url: image_absolute_url(investment.image, :thumb),
                 url: budget_investment_url(investment.budget, investment),
                 description: t("budgets.investments.share.message",
                                title: investment.title,
                                handle: setting["org_name"]),
                 mobile: t("budgets.investments.share.message",
                           title: investment.title,
                           handle: setting["twitter_handle"]) %>

      <% 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, investment) %>
      <% end %>

      <%= render "communities/access_button", community: investment.community %>

    </aside>
  </div>
</section>
