=stylesheet_link_tag 'gamecard', media: 'all'

body.B5
  #page-1.sheet.gamecard
    section#todays-game
      header
        .event-title.float-left
          | #{event.formatted_title} – #{event.start_date.strftime("%a, %b %e %l:%M %p")}
        .homeaway.float-right
          | #{event.game_type}
      .grid-container
        #offense-pane
          table#starting-lineup-offense
            tbody
              .slot-set
                - offensive_lineup_entries = by_member.select{|m,d| d[:event_lineup_entry] and d[:event_lineup_entry].label.exclude?("[PO]")}.sort_by{|m,d| d[:event_lineup_entry].sequence}.each_with_index do |(member, d), i|
                  - if i < 11
                    tr.slot
                      th.sequence(rowspan="2")
                        | #{i+1}
                      td.player-name
                        | #{member.last_name}
                      td.jersey-number
                        | #{member.jersey_number}
                      td.position
                        | #{d[:event_lineup_entry].label}
                    tr.slot.substitute
                      td
                      td
                      td
        #defense-pane
          .field-container
            img[src="/assets/baseball-diamond.svg"]
            - for pos in ["CF", "LF", "RF", "SS", "2B", "3B", "1B", "C"]
              - (member, d) = by_member.find{|m,d| d[:event_lineup_entry] and d[:event_lineup_entry].label == pos}
              div class="slot-set pos-slot-#{pos}"
                table
                  tbody
                    tr.slot
                      th.position
                      td.player-name
                        | #{member.last_name}
                    tr.slot.substitute
                      th
                      td
                    tr.slot.substitute
                      th
                      td
            - (member, d) = by_member.find{|m,d| d[:event_lineup_entry] and (d[:event_lineup_entry].label == "P" or d[:event_lineup_entry].label == "P [PO]")}
            div class="slot-set pos-slot-p"
              table
                tr
                  th.position
                  td.player-name #{!member.nil? ? member.last_name : ""}
                  td.jersey-number #{!member.nil? ? member.jersey_number : ""}
                  td.jersey-number
                tr
                  th.position.pos-slot-rp-1
                  td.player-name
                  td.jersey-number
                  td.jersey-number
                tr
                  th.position.pos-slot-rp-2
                  td.player-name
                  td.jersey-number
                  td.jersey-number
        .footer
          table.notes
            tbody
              tr
                th
                  | Notes
              tr
                td
              tr
                td
              tr
                td
    section#roster-and-history
      div
        table
          thead
            tr
              th#today-availability[colspan="3"]
                | Available (#{availability_summary.player_going_count}|#{availability_summary.player_maybe_count})
              th.player-stats
                span.decimal-point
                  | .
                | AVG 
                span.delimiter
                  | /
                span.decimal-point
                  | .
                | OBP 
                span.delimiter
                  | /
                span.decimal-point
                  | .
                | SLG 
                span.delimiter
                  | :
                | PA 
              th.position-capability.pitcher
                | P
              th.position-capability.catcher
                | C
              th.position-capability.infield
                | I
              th.position-capability.outfield
                | O
              - for timepoint, i in timeline.select{|tp| tp[:comparison_to_selected]>0}.sort{|tp| -tp[:comparison_to_selected]}.each_with_index
                th class="avail-today-plus-#{timepoint[:comparison_to_selected]} future availability"
                  div
                    | #{timepoint[:event].start_date.strftime("%a")}
              - for timepoint, i in timeline.select{|tp| tp[:comparison_to_selected]<0}.sort{|tp| tp[:comparison_to_selected]}.each_with_index
                th class="avail-today-minus-#{timepoint[:comparison_to_selected].abs}  past availability available-status-code-#{timepoint[:by_member][member][:availability].status_code}"
                  div
                    | #{timepoint[:event].start_date.strftime("%a")}

          tbody
            - by_member.select{|m,d| !m.is_non_player}.each_with_index do |(member, d), i|
              tr id="roster-history-slot-#{i}"
                td class="is-present-checkbox available-status-code-#{d[:availability].status_code}"
                  span
                    | ■
                td class="jersey-number border-left available-status-code-#{d[:availability].status_code} #{!d[:event_lineup_entry].nil? ? 'starting' : ''}"
                  |  #{member.jersey_number}
                td class="player-name available-status-code-#{d[:availability].status_code} #{!d[:event_lineup_entry].nil? ? 'starting' : ''}"
                  |  #{member.last_name}
                td.player-stats.border-left.border-right
                  span.decimal-point
                    | .
                  span.avg
                    | 000
                  span.delimiter
                    | /
                  span.decimal-point
                    | .
                  span.obp
                    | 000
                  span.delimiter
                    | /
                  span.decimal-point
                    | .
                  span.slg
                    | 000
                  span.delimiter
                    | :
                  span.pa
                    | 00
                td.position-capability.pitcher
                  | #{member.position.split(",",-1).include?("P") ? "\u2713" : ""}
                td.position-capability.catcher
                  | #{member.position.split(",",-1).include?("C") ? "\u2713" : ""}
                td.position-capability.infield
                  | #{member.position.split(",",-1).include?("IF") ? "\u2713" : ""}
                td.position-capability.outfield
                  | #{member.position.split(",",-1).include?("OF") ? "\u2713" : ""}
                
                - for timepoint, i in timeline.select{|tp| tp[:comparison_to_selected]>0}.sort{|tp| -tp[:comparison_to_selected]}.each_with_index
                  td class="avail-today-plus-#{timepoint[:comparison_to_selected]} future availability available-status-code-#{timepoint[:by_member][member][:availability].status_code}"
                    | #{timepoint[:by_member][member][:event_lineup_entry] ? timepoint[:by_member][member][:event_lineup_entry].label : timepoint[:by_member][member][:availability].status[0]}
                - for timepoint, i in timeline.select{|tp| tp[:comparison_to_selected]<0}.sort{|tp| -tp[:comparison_to_selected]}.each_with_index
                  td class="avail-today-minus-#{timepoint[:comparison_to_selected].abs} past availability available-status-code-#{timepoint[:by_member][member][:availability].status_code}"
                    | #{timepoint[:by_member][member][:event_lineup_entry] ? timepoint[:by_member][member][:event_lineup_entry].label : timepoint[:by_member][member][:availability].status[0]}
    -for section_name in ["lineup-card-dugout", "lineup-card-exchange"]
      section.lineup-card id="#{section_name}"
        header
          .float-left.event-title
            | #{event.formatted_title}
          .float-right.homeaway
            | #{event.game_type}
        .starting-lineup-table
          table
            thead
              tr
                th[colspan="4"]
                  | Starting
                th.substitution
                  | Substitution
            tbody
              - offensive_lineup_entries = by_member.select{|m,d| d[:event_lineup_entry] and d[:event_lineup_entry].label.exclude?("[PO]")}.sort_by{|m,d| d[:event_lineup_entry].sequence}
              - num_entries = offensive_lineup_entries.length
              - for i in (0...12)
                tr.slot
                  th.sequence
                    | #{i<num_entries ? i+1 : nil}
                  td.player-name
                    | #{i<num_entries ? offensive_lineup_entries[i][0].last_name : nil}
                  td.jersey-number
                    | #{i<num_entries ? offensive_lineup_entries[i][0].jersey_number : nil}
                  td.position
                    | #{i<num_entries ? offensive_lineup_entries[i][1][:event_lineup_entry].label : nil}
                  td.substitution
              
  #page-2.sheet.gamecard
    section#back-cover
    section#front-cover
      header
        .float-left.homeaway
          | #{event.game_type[0]}
        .event-title
          | #{event.start_date.strftime('%A %b %-d, %l:%M %P')}
          br
          | #{event.location_name} 
      .container
        .team
          | #{team.name} 
        div vs.
        .opponent
          | #{event.opponent_name} 
    -for section_name in ["lineup-card-dugout-blank", "lineup-card-exchange-blank"]
      section.lineup-card id="#{section_name}"
        header
          .float-left.event-title
          .float-right.homeaway
        .starting-lineup-table
          table
            thead
              tr
                th[colspan="4"]
                  | Starting
                th.substitution
                  | Substitution
            tbody
              - for i in (0...12)
                tr.slot
                  th.sequence
                  td.player-name
                  td.jersey-number
                  td.position
                  td.substitution