- page_title milestone.title, "Milestones"

- group = local_assigns[:group]

.detail-page-header
  %a.btn.btn-default.btn-grouped.pull-right.visible-xs-block.js-sidebar-toggle{ href: "#" }
    = icon('angle-double-left')

  .status-box{ class: "status-box-#{milestone.closed? ? 'closed' : 'open'}" }
    - if milestone.closed?
      Closed
    - elsif milestone.expired?
      Expired
    - else
      Open
  %span.identifier
    Milestone #{milestone.title}
  - if milestone.due_date || milestone.start_date
    %span.creator
      &middot;
      = milestone_date_range(milestone)
  - if group
    .pull-right
      - if can?(current_user, :admin_milestones, group)
        - if milestone.group_milestone?
          = link_to edit_group_milestone_path(group, milestone), class: "btn btn btn-grouped" do
            Edit
        - if milestone.active?
          = link_to 'Close Milestone', group_milestone_route(milestone, {state_event: :close }), method: :put, class: "btn btn-grouped btn-close"
        - else
          = link_to 'Reopen Milestone', group_milestone_route(milestone, {state_event: :activate }), method: :put, class: "btn btn-grouped btn-reopen"

.detail-page-description.milestone-detail
  %h2.title
    = markdown_field(milestone, :title)
  - if @milestone.group_milestone? && @milestone.description.present?
    %div
      .description
        .wiki
          = markdown_field(@milestone, :description)

- if milestone.complete?(current_user) && milestone.active?
  .alert.alert-success.prepend-top-default
    - close_msg = group ? 'You may close the milestone now.' : 'Navigate to the project to close the milestone.'
    %span All issues for this milestone are closed. #{close_msg}

- if @milestone.legacy_group_milestone? || @milestone.dashboard_milestone?
  .table-holder
    %table.table
      %thead
        %tr
          %th Project
          %th Open issues
          %th State
          %th Due date
      - milestone.milestones.each do |ms|
        %tr
          %td
            - project_name = group ? ms.project.name : ms.project.name_with_namespace
            = link_to project_name, project_milestone_path(ms.project, ms)
          %td
            = ms.issues_visible_to_user(current_user).opened.count
          %td
            - if ms.closed?
              Closed
            - else
              Open
          %td
            = ms.expires_at
- elsif @milestone.group_milestone?
  %br
  View
  = link_to 'Issues', issues_group_path(@group, milestone_title: milestone.title)
  or
  = link_to 'Merge Requests', merge_requests_group_path(@group, milestone_title: milestone.title)
  in this milestone
