=stylesheet_link_tag 'gamecard', media: 'all'

body(class="B5")
body(class="B5")
input(name="team_id", type="hidden" value="#{team_id}")
input(name="event.id", type="hidden" value="#{event.id}")
	#page-1.sheet.gamecard
		section#todays-game
			.grid-container
				.section-header
					#todays-game-header.bar-left.event-title
						| #{event.formatted_title} 
						| #{event.start_date} 
						| #{event.start_date}
					.bar-right.homeaway #{event.game_type}
					.bar-span.gametitle
				#offense-pane.left
					table#starting-lineup-offense
						tbody
							- for i in 0...11
								- if (event_lineup_entries_offense[i])?)
									tr
										th(rowspan='2') #{i+1}
										td(id="offense-slot-#{i}-name" class="player-name") #{event_lineup_entries_offense[i].member.last_name}
										td(id="offense-slot-#{i}-jersey-number" class="jersey-number") #{event_lineup_entries_offense[i].member.jersey_number}
										td(id="offense-slot-#{i}-position" class="position") #{event_lineup_entries_offense[i].label}
									tr.substitute
										td
										td
										td
								- else 
									tr
										th(rowspan='2')
										td(id="offense-slot-#{i}-name" class="player-name")
										td(id="offense-slot-#{i}-jersey-number" class="jersey-number")
										td(id="offense-slot-#{i}-position" class="position")
									tr.substitute
										td
										td
										td
							
				#defense-pane.right
					.container
						.field-container
							image(src='/media/baseball-diamond.svg')
								.row(style='justify-content: center')
									.defense-slot-set
										table
											tr
												th.position CF
												td#defense-slot-CF-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("CF")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
								.row(style='justify-content: space-between')
									.defense-slot-set
										table
											tr
												th.position LF
												td#defense-slot-LF-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("LF")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
									.defense-slot-set
										table
											tr
												th.position RF
												td#defense-slot-RF-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("RF")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
								.row(style='justify-content: space-around')
									.defense-slot-set
										table
											tr
												th.position SS
												td#defense-slot-SS-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("SS")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
									.defense-slot-set
										table
											tr
												th.position 2B
												td#defense-slot-2B-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("2B")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
								.row(style='justify-content: space-between')
									.defense-slot-set
										table
											tr
												th.position 3B
												td#defense-slot-3B-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("3B")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
									.defense-slot-set
										table
											tr
												th.position 1B
												td#defense-slot-1B-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("1B")) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
								.row(style='justify-content: center')
									.defense-slot-set
										table
											tr
												th.position C
												td#defense-slot-C-name.player-name
													| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("C") && !lue.label.startsWith("CF") ) || {"member":{}}).member.last_name}
											tr
												td(colspan='2')
											tr
												td(colspan='2')
						.pitching-container
							.defense-slot-set
								table
									tr
										th.position P
										td#defense-slot-P-name.player-name
											| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("P")) || {"member":{}}).member.last_name}
										td.jersey-number
											| #{(event_lineup_entries.find((lue)=>lue.label.startsWith("P")) || {"member":{}}).member.jersey_number}
										td.position
									tr
										th.position RP
										td#defense-slot-RP1-name.player-name
										td
										td
									tr
										th.position RP
										td#defense-slot-RP2-name.player-name
										td
										td
				.footer
					table
						tr
							th Notes
						td
						tr
							td
						tr
							td
		section#roster-and-history
			div
				table
					thead
						tr
							th#today-availability(colspan='3') Available (
								| #{availability_summaries.find((e)=>e.id==event.id).player_going_count}|
								| #{availability_summaries.find((e)=>e.id==event.id).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 event_future, i in events_future
								th(id="avail-header-today-plus-#{i+1}" class="availability future")
									.rotate #{event_future.start_date}
							- for event_past, i in events_past
								th(id="avail-header-today-minus-#{i+1}" class="availability past")
									.rotate #{event_past.start_date}
					tbody
						- for row, index in availabilities.filter((e)=>e.event.id==event.id && !e.member.is_non_player)
							tr(id="roster-history-slot-#{index+1}" class="")
								td(class="is-present-checkbox available-status-code-#{row.status_code}")
									span &#x25A0;
								td(
									class="jersey-number border-left available-status-code-#{row.status_code} #{event_lineup_entries.find((lue)=>lue.member.id==row.member.id) !== undefined ? "starting" : ""}") 
											| #{row.member.jersey_number}
								td(
									class="player-name  available-status-code-#{row.status_code} #{event_lineup_entries.find((lue)=>lue.member.id==row.member.id) !== undefined ? "starting" : ""}") 
											| #{row.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 #{row.member.position.includes("P") ? "\u2713" : ""}
								td.position-capability.catcher #{row.member.position.includes("C") ? "\u2713" : ""}
								td.position-capability.infield #{row.member.position.includes("IF") ? "\u2713" : ""}
								td.position-capability.outfield #{row.member.position.includes("OF") ? "\u2713" : ""}
								- var future_availability
								- var future_lineup_entry
								- for future_event, i in events_future
									- future_availability =    availabilities.find((el)=>el.event.id ==future_event.id && el.memberId==row.member.id)
									- future_lineup_entry = all_lineup_entries.find((el)=>el.event.id ==future_event.id && el.member.id==row.member.id)
									- console.log(future_availability)
									td(id="avail-#{row.member}-today-plus-#{i+1}" class="row future availabilityavailable-status-code-#{future_availability.status_code}")
											if future_lineupEntry
												|#{future_lineupEntry.label.slice(0,2)}
											else
												|#{future_availability.status[0]}
								- var past_availability
								- var past_lineupEntry
								- for past_event, i in events_past
									- past_availability =    availabilities.find((el)=>el.event.id==past_event.id && el.memberId==row.memberId)
									- past_lineupEntry = all_lineup_entries.find((el)=>el.event.id==past_event.id && el.member.id==row.member.id)
									td(id="avail-#{row.member}-today-minus-#{i+1}" class="row past availabilityavailable-status-code-#{past_availability.status_code}#{past_lineupEntry ? "started" : ""}")
											if past_lineupEntry
												|#{past_lineupEntry.label.slice(0,2)}
											else
												|#{past_availability.status[0]}
					tfoot
						tr
							th(colspan='3')
							th
							th(colspan='4')
							- for event_future, i in events_future
								th(class="availability future")
									.rotate #{availabilitySummaries.find((el)=>el.event.id == event_future.id).playerGoingCount}
							th.today-minus-1
								.rotate
							th.today-minus-2
								.rotate
							th.today-minus-3
								.rotate
							th.today-minus-4
								.rotate
		section#lineup-card-dugout.lineup-card
			.grid-container
				.section-header
					.bar-left.event-title
						| #{event.formattedTitle}
					.bar-right.homeaway #{event.game_type}
				.starting-lineup-table
					table
						thead
							tr
								th(colspan='4') Starting
						tbody
							- for i in [0,1,2,3,4,5,6,7,8,9,10]
								- if (typeof(event_lineup_entries_offense[i]) !== 'undefined'){
									tr
										th.sequence.label #{event_lineup_entries_offense[i].sequence +1}
										td.player-name #{event_lineup_entries_offense[i].member.last_name}
										td.jersey-number #{event_lineup_entries_offense[i].member.jersey_number}
										td.position #{event_lineup_entries_offense[i].label}
								- } else {
									tr
										th.sequence.label 
										td.player-name 
										td.jersey-number 
										td.position
									tr
										td
										td
										td
										td
								- }
								
				.substitution-table
					table(style='width: 100%')
						thead
							tr
								th Substitution
						tbody
							- for i in 0...11
								tr
									td.substitution
								tr
									td.substitution
		section#lineup-card-exchange.lineup-card
			.grid-container
				.section-header.event-title #{event.formatted_title_for_multi_team}
				.starting-lineup-table
					table.starting-lineup-table
						thead
							tr
								th
								th.player-name Name
								th.jersey-number Num
								th.position Pos
						tbody
							- for i in 0...10
								- if (typeof(event_lineup_entries_offense[i]) !== 'undefined'){
									tr
										th.sequence.label #{event_lineup_entries_offense[i].sequence+1}
										td.player-name #{event_lineup_entries_offense[i].member.last_name}
										td.jersey-number #{event_lineup_entries_offense[i].member.jersey_number}
										td.position #{event_lineup_entries_offense[i].label}
								- } else {
									tr
										th.sequence.label 
										td.player-name 
										td.jersey-number 
										td.position
									tr
										td
										td
										td
										td
								- }
	#page-2.sheet.gamecard
		section#back-cover
		section#front-cover
			div.grid-container
				.section-header
					.bar-right.homeaway #{event.game_type}
					.event-title
						| #{event.startDate}, 
						| #{event.startDate}
						br
						| #{event.locationName}
				div.team
					|#{event.team.name}
				div.opponent
					|#{event.opponent.name}
		section#lineup-card-dugout-empty.lineup-card
			.grid-container
				.section-header
				.starting-lineup-table
					table
						thead
							tr
								th(colspan='4') Starting
						tbody
							- for _ in 0...12
								tr
									th.sequence.label
									td.player-name
									td.jersey-number
									td.position
				.substitution-table
					table(style='width: 100%')
						thead
							tr
								th Substitution
						tbody
							- for _ in 0...11
								tr
									td.substitution
								tr
									td.substitution
		section#lineup-card-exchange-empty.lineup-card
			.grid-container
				.section-header
				.starting-lineup-table
					table.starting-lineup-table
						thead
							tr
								th
								th.player-name Name
								th.jersey-number Num
								th.position Pos
						tbody
							- for _ in 0...12
								tr
									th.sequence.label
									td.player-name
									td.jersey-number
									td.position
	
