<%#
  # TODO: Reflect on content_type to pull `relates` relations instead of hard-coding each here.
%>

<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Location,
    content: content,
    relation_class: LocationLeadership,
    relation_class_id: :leader_id,
    relation_text: :leader_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Item,
    content: content,
    relation_class: MakerRelationship,
    relation_class_id: :maker_id,
    relation_text: :maker_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Item,
    content: content,
    relation_class: CurrentOwnership,
    relation_class_id: :current_owner_id,
    relation_text: :currently_owns
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Item,
    content: content,
    relation_class: PastOwnership,
    relation_class_id: :past_owner_id,
    relation_text: :previously_owned
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Item,
    content: content,
    relation_class: OriginalOwnership,
    relation_class_id: :original_owner_id,
    relation_text: :originally_owned
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Race,
    content: content,
    relation_class: FamousFigureship,
    relation_class_id: :famous_figure_id,
    relation_text: :famous_figure_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Religion,
    content: content,
    relation_class: ReligiousFigureship,
    relation_class_id: :notable_figure_id,
    relation_text: :famous_figure_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Religion,
    content: content,
    relation_class: Deityship,
    relation_class_id: :deity_id,
    relation_text: :deity_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Group,
    content: content,
    relation_class: GroupLeadership,
    relation_class_id: :leader_id,
    relation_text: :leader_of
  }
%>
<%=
  render partial: 'content/contexts/relation', locals: {
    content_type: Group,
    content: content,
    relation_class: GroupMembership,
    relation_class_id: :member_id,
    relation_text: :member_of
  }
%>

<% scenes = SceneCharactership.where(scene_character_id: content.id).map(&:scene).compact.select { |content| content && content.readable_by?(current_user || User.new) } %>
<% if scenes.any? %>
  <div class="col s12 m6 l4">
    <%= render partial: 'content/cards/in_universe_content_list', locals: {
      content_type: :scene,
      content_list: scenes,
      card_title: "In #{pluralize(scenes.count, 'scene')}"
    } %>
  </div>
<% end %>

<% @references.each do |content_type, relations| %>
  <% next unless relations.any? %>
  <%
  card_title = if relations.count == 1
    if relations.first.first.include? '<plural>'
      relations.first.first
    else
      [
        relations.first.first,
        ' ',
        pluralize(relations.count, "#{content_type.to_s.singularize}")
      ].join
    end
  else
    [
      'Related to ',
      pluralize(relations.count, "other #{content_type.to_s.singularize}")
    ].join
  end
  %>
  <div class="col s12 m6 l4">
    <%= render partial: 'content/cards/content_relation_list', locals: {
      content_type: content_type,
      relations:    relations,
      card_title:   card_title
    } %>
  </div>
<% end %>
