<!DOCTYPE html>
<html lang="en">
<head>
  <%= HeadTemplate.new(project_info, type) %>
  <meta name="repository-name" content="<%= project_info.name %>">
  <title><%= type.full_name %> - <%= project_info.name %> <%= project_info.version %></title>
  <script type="text/javascript">
    CrystalDocs.base_path = "<%= type.path_to "" %>";
  </script>
</head>
<body>

<%= Crystal::Doc::SVG_DEFS %>
<%= Crystal::Doc::SIDEBAR_BUTTON %>
<%= SidebarTemplate.new(project_info, types, type) %>

<div class="main-content">
<h1 class="type-name">
<% if type.program? %>
  <%= type.full_name.gsub("::", "::<wbr>") %>
<% else %>
  <span class="kind">
    <%= type.abstract? ? "abstract " : ""%><%= type.visibility.try(&.+(" ")) %><%= type.kind %>
  </span> <%= type.full_name.gsub("::", "::<wbr>") %>
<% end %>
</h1>

<% if type.superclass %>
  <%= type.superclass_hierarchy %>
<% end %>


<% if doc = type.formatted_doc %>
  <h2>
    <%= Crystal::Doc.anchor_link("overview") %>
    Overview
  </h2>

  <%= doc %>
<% end %>

<% if type.alias? %>
  <h2>
    <%= Crystal::Doc.anchor_link("alias-definition") %>
    Alias Definition
  </h2>
  <code><%= type.formatted_alias_definition %></code>
<% end %>

<% if type.type_def? %>
  <h2>
    <%= Crystal::Doc.anchor_link("type-definition") %>
    Type Definition
  </h2>
  <code><%= type.formatted_type_definition %></code>
<% end %>

<%= OtherTypesTemplate.new("Included Modules", type, type.included_modules) %>
<%= OtherTypesTemplate.new("Extended Modules", type, type.extended_modules) %>
<%= OtherTypesTemplate.new("Direct Known Subclasses", type, type.subclasses) %>
<%= OtherTypesTemplate.new("Direct including types", type, type.including_types) %>

<% if locations = type.locations %>
  <h2>
    <%= Crystal::Doc.anchor_link("defined-in") %>
    Defined in:
  </h2>
  <% locations.each do |location| %>
    <% if url = project_info.source_url(location) %>
      <a href="<%= url %>" target="_blank">
        <%= location.filename_in_project %><% if location.show_line_number %>:<%= location.line_number %><% end %>
      </a>
    <% else %>
      <%= location.filename_in_project %><% if location.show_line_number %>:<%= location.line_number %><% end %>
    <% end %>
    <br/>
  <% end %>
<% end %>

<% unless type.constants.empty? %>
  <% if type.enum? %>
    <h2>
      <%= Crystal::Doc.anchor_link("enum-members") %>
      Enum Members
    </h2>
  <% else %>
    <h2>
      <%= Crystal::Doc.anchor_link("constant-summary") %>
      Constant Summary
    </h2>
  <% end %>
  <dl>
    <% type.constants.each do |const| %>
      <dt class="entry-const" id="<%= const.id %>">
        <strong><%= const.name %></strong> = <code><%= const.formatted_value %></code>
      </dt>
      <% if doc = const.formatted_doc %>
      <dd class="entry-const-doc">
        <%= doc %>
      </dd>
      <% end %>
    <% end %>
  </dl>
<% end %>

<% if type.lib? %>
  <%= MethodSummaryTemplate.new("External Variable Summary", type.external_vars) %>
  <%= MethodSummaryTemplate.new("Function Summary", type.functions) %>
  <%= MethodDetailTemplate.new("External Variable Detail", type.external_vars) %>
  <%= MethodDetailTemplate.new("Function Detail", type.functions) %>
<% elsif !type.type_def? %>
  <%= MethodSummaryTemplate.new("Constructors", type.constructors) %>
  <%= MethodSummaryTemplate.new(type.program? ? "Method Summary" : "Class Method Summary", type.class_methods) %>
  <%= MethodSummaryTemplate.new("Macro Summary", type.macros) %>
  <%= MethodSummaryTemplate.new("Instance Method Summary", type.instance_methods) %>

  <div class="methods-inherited">
    <% type.ancestors.each do |ancestor| %>
      <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.instance_methods, "Instance") %>
      <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.constructors, "Constructor") %>
      <%= MethodsInheritedTemplate.new(type, ancestor, ancestor.class_methods, "Class") %>
      <%= MacrosInheritedTemplate.new(type, ancestor, ancestor.macros) %>
    <% end %>
  </div>

  <%= MethodDetailTemplate.new("Constructor Detail", type.constructors) %>
  <%= MethodDetailTemplate.new(type.program? ? "Method Detail" : "Class Method Detail", type.class_methods) %>
  <%= MethodDetailTemplate.new("Macro Detail", type.macros) %>
  <%= MethodDetailTemplate.new("Instance Method Detail", type.instance_methods) %>
<% end %>
</div>

</body>
</html>
