- page_title @milestone.title, "Milestones"
= render "header_title"

.detail-page-header
  .status-box{ class: "status-box-#{@milestone.closed? ? 'closed' : 'open'}" }
    - if @milestone.closed?
      Closed
    - else
      Open
  %span.identifier
    Milestone #{@milestone.title}
  .pull-right
    - if can?(current_user, :admin_milestones, @group)
      - if @milestone.active?
        = link_to 'Close Milestone', group_milestone_path(@group, @milestone.safe_title, title: @milestone.title, milestone: {state_event: :close }), method: :put, class: "btn btn-grouped btn-close"
      - else
        = link_to 'Reopen Milestone', group_milestone_path(@group, @milestone.safe_title, title: @milestone.title, milestone: {state_event: :activate }), method: :put, class: "btn btn-grouped btn-reopen"

.detail-page-description.gray-content-block.second-block
  %h2.title
    = markdown escape_once(@milestone.title), pipeline: :single_line

- if @milestone.complete? && @milestone.active?
  .alert.alert-success.prepend-top-default
    %span All issues for this milestone are closed. You may close the milestone now.

.table-holder
  %table.table
    %thead
      %tr
        %th Project
        %th Open issues
        %th State
        %th Due date
    - @milestone.milestones.each do |milestone|
      %tr
        %td
          = link_to "#{milestone.project.name}", namespace_project_milestone_path(milestone.project.namespace, milestone.project, milestone)
        %td
          = milestone.issues.opened.count
        %td
          - if milestone.closed?
            Closed
          - else
            Open
        %td
          = milestone.expires_at

.context
  .milestone-summary
    %h4 Progress
    %strong= @milestone.issues.size
    issues:
    %span.milestone-stat
      %strong= @milestone.opened_issues.size
      open and
      %strong= @milestone.closed_issues.size
      closed
    %span.milestone-stat
      %strong== #{@milestone.percent_complete}%
      complete

  = milestone_progress_bar(@milestone)

%ul.nav-links.no-top.no-bottom
  %li.active
    = link_to '#tab-issues', 'data-toggle' => 'tab' do
      Issues
      %span.badge= @milestone.issues_count
  %li
    = link_to '#tab-merge-requests', 'data-toggle' => 'tab' do
      Merge Requests
      %span.badge= @milestone.merge_requests_count
  %li
    = link_to '#tab-participants', 'data-toggle' => 'tab' do
      Participants
      %span.badge= @milestone.participants.count
  %li
    = link_to '#tab-labels', 'data-toggle' => 'tab', 'data-show' => '.tab-issues-buttons' do
      Labels
      %span.badge= @milestone.labels.count

.tab-content.milestone-content
  .tab-pane.active#tab-issues
    = render 'shared/milestones/issues_tab', unassigned: @milestone.opened_issues.unassigned, assigned: @milestone.opened_issues.assigned, closed: @milestone.closed_issues, show_project_name: true
  .tab-pane#tab-merge-requests
    = render 'shared/milestones/merge_requests_tab', unassigned: @milestone.opened_merge_requests.unassigned, assigned: @milestone.opened_merge_requests.assigned, closed: @milestone.merge_requests.closed, merged: @milestone.merge_requests.merged, show_project_name: true
  .tab-pane#tab-participants
    = render 'shared/milestones/participants_tab', users: @milestone.participants
  .tab-pane#tab-labels
    = render 'shared/milestones/labels_tab', labels: @milestone.labels, show_project_name: true
