- content_for :title, "Crop Wrangling"

%h1 Crop Wrangling

%nav.nav
  = link_to "Full crop hierarchy", hierarchy_crops_path, class: 'nav-link'
  = link_to "Add Crop", new_crop_path, class: 'btn'

%section.crop_wranglers
  %h2 Crop Wranglers
  - @crop_wranglers.each do |crop_wrangler|
    = render 'members/tiny', member: crop_wrangler

%hr/

%section
  %h2 Crops

  %ul#myTab.nav.nav-tabs{role: "tablist"}
    %li.nav-item
      %a#home-tab.nav-link{ href: admin_crops_path, role: "tab", class: ''}
        Recently edited
    %li.nav-item
      %a#home-tab.nav-link{ href: wrangle_crops_path, role: "tab", class: @approval_status.blank? ? 'active' : ''}
        Recently added
    %li.nav-item
      %a#profile-tab.nav-link{ href: wrangle_crops_path(approval_status: "pending"), role: "tab", class: @approval_status == "pending" ? 'active' : ''}
        Pending approval
    %li.nav-item
      %a#contact-tab.nav-link{ href: wrangle_crops_path(approval_status: "rejected"), role: "tab", class: @approval_status == "rejected" ? 'active' : ''} Rejected

  %table.table.table-striped.table-bordered.table-sm{id: @approval_status.blank? ? 'recently-added-crops' : "#{@approval_status}-crops" }
    %tr
      %th System name
      %th English Wikipedia URL
      %th Scientific names
      %th Requested by
      - if @approval_status == "rejected"
        %th Rejected by
      - if @approval_status != "rejected" && @approval_status != "pending"
        %th Added by
      %th When
    - @crops.each do |c|
      %tr
        %td
          = link_to edit_crop_path(c) do
            = icon 'fas', 'seedling'
            = c.name
        %td= link_to c.en_wikipedia_url, c.en_wikipedia_url
        %td
          - c.scientific_names.each do |s|
            = link_to s.name, s
            %br/
        %td= c.requester.present? ? (link_to c.requester, c.requester) : "N/A"
        - unless @approval_status == "pending"
          %td= c.creator.present? ? (link_to c.creator, c.creator) : "N/A"
        %td
          = distance_of_time_in_words(c.created_at, Time.zone.now)
          ago.

  = page_entries_info @crops
  = will_paginate @crops

