- page_title "Groups"
.row.prepend-top-default
  .col-lg-3.settings-sidebar
    %h4.prepend-top-0
      Share project with other groups
    %p
      Projects can be stored in only one group at once. However you can share a project with other groups here.
  .col-lg-9
    %h5.prepend-top-0
      Set a group to share
    = form_tag namespace_project_group_links_path(@project.namespace, @project), method: :post do
      .form-group
        = label_tag :link_group_id, "Group", class: "label-light"
        = groups_select_tag(:link_group_id, skip_group: @project.group.try(:path))
      .form-group
        = label_tag :link_group_access, "Max access level", class: "label-light"
        .select-wrapper
          = select_tag :link_group_access, options_for_select(ProjectGroupLink.access_options, ProjectGroupLink.default_access), class: "form-control select-control"
          %span.caret
      .form-group
        = label_tag :expires_at, 'Access expiration date', class: 'label-light'
        .clearable-input
          = text_field_tag :expires_at, nil, class: 'form-control js-access-expiration-date', placeholder: 'Select access expiration date'
          %i.clear-icon.js-clear-input
        .help-block
          On this date, all users in the group will automatically lose access to this project.
      = submit_tag "Share", class: "btn btn-create"
  .col-lg-9.col-lg-offset-3
    %hr
  .col-lg-9.col-lg-offset-3.append-bottom-default.enabled-groups
    %h5.prepend-top-0
      Groups you share with (#{@group_links.size})
    - if @group_links.present?
      %ul.well-list
        - @group_links.each do |group_link|
          - group = group_link.group
          %li
            .pull-left.append-right-10.hidden-xs
              = icon("folder-open-o", class: "settings-list-icon")
            .pull-left
              = link_to group do
                = group.name
              %br
              up to #{group_link.human_access}
              - if group_link.expires?
                ยท
                %span{ class: ('text-warning' if group_link.expires_soon?) }
                  expires in #{distance_of_time_in_words_to_now(group_link.expires_at)}
            .pull-right
              = link_to namespace_project_group_link_path(@project.namespace, @project, group_link), method: :delete, class: "btn btn-transparent" do
                %span.sr-only disable sharing
                = icon("trash")
    - else
      .settings-message.text-center
        There are no groups with access to your project, add one in the form above