<section class="container-fluid">
	<div class="row">
		<div class="col-md-8">
			<div class="card bg-light-transparent" style="margin-bottom: 2rem;">
				<div class="card-header bg-white">
					<div class="float-left">
						<h5 class="card-title">Calendar</h5>
					</div>
				</div>
				<div class="card-body">
					<div class="card bg-white no-shadow">
						<div class="card-body">
							<div class="row">
								<div class="col-12">
									<div id="calendar"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="col-md-4">
			<div class="card bg-light-transparent" style="margin-bottom: 2rem;">
				<div class="card-header bg-white">
					<h5 class="card-title">Upcoming Flight Booking</h5>
				</div>
				<div class="card-body">
					<div class="card bg-white no-shadow">
						<div class="card-body">
							<?php if(!empty($upcoming_request)): foreach($upcoming_request as $upcoming): ?>
								<div class="row">
									<div class="col-auto">
										<p data-trigger="hover" data-tooltip="tooltip" title="<?php echo $upcoming['dept_name'].'['.$upcoming['branchName'].']'; ?>"><?php echo $upcoming['dept_name'].'/'.$upcoming['branchName']; ?></p>
									</div>
									<div class="col text-right">
										<p><?php echo date('d-m-Y',strtotime($upcoming['departure_date'])); ?></p>
									</div>
								</div>
							<?php endforeach;endif; ?>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<section class="container" style="padding-bottom: 2rem;">
	<div class="row">
		<div class="col-sm-12">
			<div class="tab-content" id="tabContent">
				<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
					<div class="card bg-light-transparent">
						<div class="card-header bg-light">
							<h4 class="card-title"><?php echo (empty($ID))?'New ':'Edit '; ?>Flight Booking Form</h4>
							<h6 class="card-title"><i>Instruction: Please make sure departure time before 48 hours.</i></h6>
						</div>
						<div class="card-body">
							<div class="card no-shadow">
								<div class="card-body">
									<?php if(!empty($ID)){ ?>
										<form id="flightForm" class="form" action="<?php echo base_url('hr/Serviceform/edit_flight_form') ?>" method="POST" onsubmit="return confirm('Confirm to update this form?')">
										<?php } else { ?>
											<form id="flightForm" class="form" action="<?php echo base_url('hr/Serviceform/save_flight_form') ?>" method="POST" onsubmit="return confirm('Confirm to proceed guest detail?')">
											<?php } ?>

											<input type="text" class="form-control" name="flightID" id="flightID" value="<?php echo $ID; ?>" hidden>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<h5><b>Requestor Info</b></h5>
														<hr>
														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label>Name</label>
																	<?php if($ID) { ?>
																		<?php if($getListFlightBookingByID) foreach($getListFlightBookingByID as $row){ ?>
																			<input type="text" class="form-control" name="name" id="name" value="<?php echo $row['created_name']; ?>" readonly/>	
																			<input type="text" class="form-control" name="name_id" id="name_id" value="<?php echo $row['createdBY']; ?>" hidden>
																		<?php } ?>
																	<?php } else { ?>
																		<input type="text" class="form-control" name="name" id="name" value="<?php echo $_SESSION['user']['name']; ?>" readonly>
																		<input type="text" class="form-control" name="name_id" id="name_id" value="<?php echo $_SESSION['user']['id']; ?>" hidden>
																	<?php } ?>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="email">Email Address</label>
																	<?php if(!empty($ID)){ ?>
																		<?php if(!empty($getListFlightBookingByID)) foreach($getListFlightBookingByID as $row){ ?>
																			<input type="text" class="form-control" name="email" id="email" value="<?php echo $row['created_email']; ?>" readonly/>
																		<?php } ?>
																	<?php } else { ?>
																		<input type="text" class="form-control" name="email" id="email" value="<?php echo $_SESSION['user']['email']; ?>" readonly/>
																	<?php } ?>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="department">Department</label>
																	<?php if(!empty($ID)){ ?>
																		<?php if(!empty($getListFlightBookingByID)) foreach($getListFlightBookingByID as $row){ ?>
																			<input type="text" class="form-control" name="department" id="department" value="<?php echo $row['created_dept_name'].' ['.$row['created_branchName'].']'; ?>" readonly/>
																			<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $row['created_department_id']; ?>" hidden>
																		<?php } ?>
																	<?php } else { ?>
																		<input type="text" class="form-control" name="department" id="department" value="<?php echo $_SESSION['user']['department_name'].' ['.$_SESSION['user']['branch_name'].']'; ?>" readonly/>
																		<input type="text" class="form-control" name="department_id" id="department_id" value="<?php echo $_SESSION['user']['department_id']; ?>" hidden>
																	<?php } ?>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="datereq">Date Request</label>
																	<?php if(!empty($ID)){ ?>
																		<?php if(!empty($getListFlightBookingByID)) foreach($getListFlightBookingByID as $row){ ?>
																			<input type="" class="form-control" name="datereq" id="datereq" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($row['createdTS'])):''; ?>" readonly/>
																		<?php } ?>
																	<?php } else { ?>
																		<input type="" class="form-control" name="datereq" id="datereq" value="<?php echo date('d-m-Y'); ?>" readonly/>
																	<?php } ?>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<h5><b>Flight Info</b></h5>
														<hr>
														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="departure">Type of Departure</label>
																	<div class="row">
																		<div class="col-sm-6">
																			<input type="radio" name="departure_type" value="0" <?php echo ($getListFlightBookingByID[0]['departure_type'] == 0)?'checked':''; ?> onclick="open_close_passport_column(this)"> International Departure
																		</div>
																		<div class="col-sm-6">
																			<input type="radio" name="departure_type" value="1" <?php echo ($getListFlightBookingByID[0]['departure_type'] == 1)?'checked':''; ?> onclick="open_close_passport_column(this)"> Domestic Departure
																		</div>
																	</div>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="ticket">Type of Ticket</label>
																	<div class="row">
																		<div class="col-sm-6">
																			<input type="radio" name="ticket_type" value="0" <?php echo ($getListFlightBookingByID[0]['ticket_type'] == 0)?'checked':''; ?> onclick="open_close_return_column(this)"> Two Way Ticket 
																		</div>
																		<div class="col-sm-6">
																			<input type="radio" name="ticket_type" value="1" <?php echo ($getListFlightBookingByID[0]['ticket_type'] == 1)?'checked':''; ?> onclick="open_close_return_column(this)"> One Way Ticket
																		</div>
																	</div>
																</div>
															</div>
														</div>

														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="origin">Origin</label>
																	<input type="text" class="form-control" name="origin" id="origin" value="<?php echo (!empty($ID))?$getListFlightBookingByID[0]['origin']:''; ?>" required>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="dest">Destination</label>
																	<input type="text" class="form-control" name="destination" id="destination" value="<?php echo (!empty($ID))?$getListFlightBookingByID[0]['destination']:''; ?>" required>
																</div>
															</div>

															<div class="col-12 col-sm-3">
																<div class="form-group">
																	<label for="datestart">Departure Date</label>
																	<input type="text" class="form-control datepicker" name="depart_date" id="depart_date" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($getListFlightBookingByID[0]['departure_date'])):''; ?>" required onchange="calculate_request_hour()">
																</div>
															</div>

															<div class="col-12 col-sm-3">
																<div class="form-group">
																	<label for="time"> Departure Time</label>
																	<input type="text" class="form-control timepicker" name="depart_time" id="depart_time" value="<?php echo (!empty($ID))?$getListFlightBookingByID[0]['departure_time']:''; ?>" required onchange="calculate_request_hour()">
																</div>
															</div>

															<div class="col-12 col-sm-3">
																<div class="form-group">
																	<label for="date">Return Date </label>
																	<input type="text" class="form-control datepicker" name="return_date" id="return_date" value="<?php echo (!empty($ID))?date('d-m-Y',strtotime($getListFlightBookingByID[0]['return_date'])):''; ?>" <?php echo ($getListFlightBookingByID[0]['ticket_type'] == 1)?'readonly':'required'; ?>>
																</div>
															</div>

															<div class="col-12 col-sm-3">
																<div class="form-group">
																	<label for="time">Return Time</label>
																	<input type="text" class="form-control timepicker" name="return_time" id="return_time" value="<?php echo (!empty($ID))?$getListFlightBookingByID[0]['return_time']:''; ?>" <?php echo ($getListFlightBookingByID[0]['ticket_type'] == 1)?'readonly':'required'; ?>>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="class">Class of Flight</label>
																	<select class="form-control" name="flightClass" id="flightClass" required>
																		<option value="" disabled selected>-- Please Select --</option>
																		<option value="First class" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['flight_class']) == 'First class')?'selected':''; ?>>First class</option>
																		<option value="Business class" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['flight_class']) == 'Business class')?'selected':''; ?>>Business class</option>
																		<option value="Economy class" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['flight_class']) == 'Economy class')?'selected':''; ?>>Economy class</option>		
																	</select>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label>Meal</label>
																	<div class="row">
																		<div class="col-sm-3">
																			<input type="radio" name="meal" value="0" <?php echo ($getListFlightBookingByID[0]['meal'] == 0)?'checked':''; ?>> No 
																		</div>
																		<div class="col-sm-3">
																			<input type="radio" name="meal" value="1" <?php echo ($getListFlightBookingByID[0]['meal'] == 1)?'checked':''; ?>> Yes
																		</div>
																	</div>
																</div>
															</div>

															<div class="col-12 col-md-6">
																<label>Baggage</label>
																<select name="baggage" id="baggage" class="form-control form-control" required>
																	<!-- <option value="0" disabled selected>--please select--</option> -->
																	<option value="" disabled selected>-- Please Select --</option>
																	<option value="15kg - RM26.50" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['baggage']) == '15kg - RM26.50')?'selected':''; ?>>15kg - RM26.50</option>
																	<option value="20kg - RM31.80" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['baggage']) == '20kg - RM31.80')?'selected':''; ?>>20kg - RM31.80</option>
																	<option value="25kg - Rm42.40" <?php echo (!empty($ID) && ($getListFlightBookingByID[0]['baggage']) == '25kg - Rm42.40')?'selected':''; ?>>25kg - Rm42.40</option>
																	<option value="other_bag">Other Baggage</option>
																</select>
															</div>

															<div class="col-12 col-md-6 mx-auto text-left mb-3">
																<label><p></p></label>
																<input type="text" id="other_baggage" name="other_baggage" value="<?php echo (!empty($ID))?$getListFlightBookingByID[0]['baggage']:'-- Please Select --'; ?>" class="form-control form-control-md" onkeyup="changeBaggage(this)" disabled required>
															</div>
															<br>
															<div class="col-12 ">
																<div class="form-group">
																	<p>Select Flight :</p>
																	<div class="row">
																		<div class="col-12 col-sm-3">
																			<img src="<?php echo base_url('assets/images/airasialogo.png'); ?>" width="150" height="90"><br>

																			<input type="radio" name="flightName" id="flightName" value="airasia" <?php echo ($getListFlightBookingByID[0]['flight_name'] == 'airasia')?'checked':''; ?>> AIR ASIA<br>
																		</div>

																		<div class="col-12 col-sm-3">
																			<img src="<?php echo base_url('assets/images/fireflylogo.png'); ?>" width="150" height="90"><br>

																			<input type="radio" name="flightName" id="flightName" value="firefly" <?php echo ($getListFlightBookingByID[0]['flight_name'] == 'firefly')?'checked':''; ?>> FIREFLY<br>
																		</div>

																		<div class="col-12 col-sm-3">
																			<img src="<?php echo base_url('assets/images/malindorairlogo.png'); ?>" width="150" height="90"><br>

																			<input type="radio" name="flightName" id="flightName" value="malindo" <?php echo ($getListFlightBookingByID[0]['flight_name'] == 'malindo')?'checked':''; ?>> MALINDO<br>
																		</div>

																		<div class="col-12 col-sm-3">
																			<img src="<?php echo base_url('assets/images/maslogo.png'); ?>" width="150" height="90"><br>

																			<input type="radio" name="flightName" id="flightName" value="mas" <?php echo ($getListFlightBookingByID[0]['flight_name'] == 'mas')?'checked':''; ?>> MAS
																		</div>

																		<div class="col-12 col-sm-6">
																			<div class="form-group">
																				<br>
																				<input type="checkbox" name="other_flight" id="other_flight" data-otherflight="other_flight" value="1" onchange="open_hidden_other_flightName(this);">
																				<label for="other_flight_name">Other Flight :</label>
																				<input type="text" class="form-control" name="other_flight_name" id="other_flight_name" disabled hidden>
																			</div>
																		</div>
																	</div>
																</div>
															</div>
														</div>

														<div class="form-row" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
															<div class="col-12">
																<h5><input type="checkbox" id="booking_checker" style="height: 1rem; width: 1rem;" onclick="checkbox(this)"> Please tick if you are booking for someone else.</h5>
															</div>
														</div>

														<div class="form-row">
															<div class="col-12 col-sm-6 d-none" id="guest_details_form">
																<div class="form-group">
																	<label for="guest_details">Passenger Name [Department]</label>
																	<select class="form-control select" name="guest_details" id="guest_details">
																		<option value="-1" selected disabled>-- Please Select --</option>
																		<?php if($listName) foreach($listName as $key => $gID){ 
																			$dept_sName =  ($gID['department_name'])?' ['.$gID['department_short_name'].'] ':' [N/A]';
																			?>
																			<?php if(($_SESSION['user']['name']) != $gID['name']){ ?>
																				<option value="<?php echo $gID['id']; ?>" data-did="$gID['department_id']"><?php echo $gID['name'].$dept_sName; ?></option>
																			<?php } ?>
																		<?php } ?>
																	</select>
																</div>
															</div>

															<?php if(!empty($ID) && !empty($getListFlightBookingByID)) foreach($getListFlightBookingByID as $row){ ?>
																<?php if($row['requester_id'] != $row['createdBY']){ ?>
																	<div class="col-12 col-sm-6">
																		<div class="form-group">
																			<label for="guest_details_input">Passenger Name [Department]</label>
																			<input type="text" class="form-control" name="guest_name_input" id="guest_name_input" value="<?php echo $row['requestor'].' ['.$row['department_short_name'].']' ?>" readonly>
																			<input type="text" class="form-control" name="guest_details_input" id="guest_details_input" value="<?php echo $row['requester_id']; ?>" hidden>
																		</div>
																	</div>
																<?php } ?>
															<?php } ?>
														</div>
													</div>
												</div>
											</div>

											<div class="form-row" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
												<div class="col-12" style="padding-top: 2rem;">
													<div class="float-left <?php echo ($ID)?'d-none':''; ?>">
														<table>
															<tbody>
																<tr>
																	<td class="text-center">
																		<label class="switch" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Send me a copy of this form">
																			<input type="checkbox" name="send_email_checkbox">
																			<span class="slider round"></span>
																		</label>
																	</td>
																	<td class="p-3 py-1"><b><h6 style="">Send me a copy of this form</h6></b></td>
																</tr>
															</tbody>
														</table>
													</div> 
													<div class="float-right">
														<a class="btn btn-light" href="<?php echo base_url('hr/serviceform/flight_list/'); ?>">Cancel</a>
														<button type="submit" id="submitBtn" class="btn btn-primary"><?php echo ($ID)?'Update':'Next'; ?></button>
													</div> 
												</div>
											</div>
										</form>
									</form>
								</div>
							</div>
						</div>

						<div class="card-body <?php echo (empty($ID))?'d-none':'' ?>" id="guest_detail">
							<div class="card no-shadow">
								<div class="card-body">
									<div class="form-row">
										<div class="col-12">
											<div class="form-group">
												<h5 class="float-left"><b>Passenger Details</b></h5>
												<div class="float-right btn-group" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
													<button type="button" class="btn btn-outline-dark btn-sm" data-toggle="modal" data-target="#newGuestDetails" data-trigger="hover" data-tooltip="tooltip" title="Add New Details"><i class="fas fa-plus"></i> Add New Details</button>
												</div>
												<br><hr>
												<table class="table table-bordered table-striped table-hover" id="table_guest_detail">
													<thead class="text-center">
														<th>#</th>
														<th>Staff Name</th>
														<th>Staff Detail</th>
														<th>Action</th>
													</thead>
													<tbody>
														<?php foreach($getListFlightBookingByID as $key_detail => $detail){ 
															if(!empty($detail['guest_id'])){
																$flight_guest_id 	= explode(',',$detail['flight_guest_id']);
																$guest_id 			= explode(',',$detail['guest_id']);
																$guest_name 		= explode(',',$detail['guest_name']);
																$guest_phone 		= explode(',',$detail['guest_phone']);
																$guest_passport 	= explode(',',$detail['guest_passport']);
																$guest_ic_no 		= explode(',',$detail['guest_ic_no']);

																foreach($guest_name as $key => $name){ ?>
																	<tr>
																		<td class="text-center"><?php echo $key+1; ?></td>
																		<td><?php echo $name; ?></td>
																		<td>
																			<div class="row">
																				<div class="col-3">Ic. No.</div>
																				<div class="col-1">:</div>
																				<div class="col-8"><?php echo $guest_ic_no[$key]; ?></div>
																			</div>
																			<div class="row">
																				<div class="col-3">Phone</div>
																				<div class="col-1">:</div>
																				<div class="col-8"><?php echo $guest_phone[$key]; ?></div>
																			</div>
																			<div class="row">
																				<div class="col-3">Passport</div>
																				<div class="col-1">:</div>
																				<div class="col-8"><?php echo $guest_passport[$key]; ?></div>
																			</div>
																		</td>
																		<td class="text-center">
																			<div class="btn-group">
																				<button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#editGuestDetails" data-trigger="hover" data-tooltip="tooltip" title="Edit Details" data-flightid="<?php echo $detail['ID'];?>" data-detailsid="<?php echo $flight_guest_id[$key];?>" data-guestid="<?php echo $guest_id[$key]; ?>" data-passport="<?php echo $guest_passport[$key];?>" onclick="editFlightDetail(this)"><i class="fas fa-edit"></i>
																				</button>
																				<button id="deleteButtonFlightDetail" type="button" class="btn btn-danger btn-sm" data-trigger="hover" data-tooltip="tooltip" title="Delete Details" data-flightid="<?php echo $detail['ID'];?>" data-detailsid="<?php echo $flight_guest_id[$key];?>" data-guestid="<?php echo $guest_id[$key];?>" onclick="deleteFlightDetail(this)"><i class="fas fa-trash"></i>
																				</button>
																			</div>
																		</td>
																	</tr>
																<?php } 
															} 
														} ?>
													</tbody>
												</table>
											</div>
										</div>

										<div class="col-12" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?> style="padding-top: 2rem;">
											<div class="float-right">
												<a class="btn btn-primary" href="<?php echo base_url('hr/serviceform/flight_list/submit'); ?>">Submit</a>
											</div> 
										</div>

									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<!-- add new guest -->
<div class="modal fade d-print-none" id="newGuestDetails" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="exampleModalLongTitle">Add Passenger Details</h5>&emsp;
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form class="form" id="guestDetailForm" action="<?php echo base_url('hr/Serviceform/flight_save_guest_detail') ?>" method="POST" onsubmit="return confirm('Confirm to add new guest detail?')">
				<div class="modal-body">

					<input type="text" class="form-control" name="flight_ID" id="flight_ID" value="<?php echo $ID; ?>" hidden>

					<div class="row">
						<div class="col-12">
							<label for="gID">Passenger Name</label>
							<?php if(!empty($ID))
							{
								if($getListFlightBookingByID[0]['requester_id'] == $_SESSION['user']['id'])
								{
									$readonly = '';
								}else{
									$readonly = 'readonly';
								}
							}else{
								$readonly = '';
							}
							?>
							<select required data-parsley-error-message="Passenger name is required." class="form-control select" name="gID" id="gID" <?php echo $readonly; ?>>
								<option value="-1" selected disabled>-- Please Select --</option>
								<?php if($listName) foreach($listName as $key => $gID){ 
									$dept_sName =  ($gID['department_name'])?' ['.$gID['department_short_name'].'] ':' [N/A]';
									$ic_no =  ($gID['ic_no'])?' ['.$gID['ic_no'].'] ':' [N/A]';
									$phone =  ($gID['phone'])?' ['.$gID['phone'].'] ':' [N/A]';
									?>
									<option value="<?php echo $gID['id']; ?>"><?php echo $gID['name'].$dept_sName.$ic_no.$phone; ?></option>
								<?php } ?>
							</select>
						</div>
						<div style="margin-bottom: 6rem;"></div>
						<div class="col-12">
							<label for="passport">Passenger Passport No.</label>
							<input type="text" class="form-control" name="passport" id="passport" <?php echo ($getListFlightBookingByID[0]['departure_type'] == 1)?'disabled':'required'; ?>>
						</div>
					</div>
					<br>
					<div class="float-right" style="padding-bottom: 1rem;">
						<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
						<button type="submit" class="btn btn-primary">Save</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<!-- add new guest -->

<!-- edit guest -->
<div class="modal fade d-print-none" id="editGuestDetails" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title" id="exampleModalLongTitle">Edit Passenger Details</h5>&emsp;
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>
			<form class="form" id="editguestDetailForm" action="<?php echo base_url('hr/Serviceform/flight_edit_guest_detail') ?>" method="POST" onsubmit="return confirm('Confirm to update guest detail?')">
				<div class="modal-body">

					<input type="text" class="form-control" name="flight_id" id="flight_id" hidden>
					<input type="text" class="form-control" name="flight_detail_ID" id="flight_detail_ID" hidden>

					<div class="row">
						<div class="col-12">
							<label for="edit_gID">Passenger Name</label>
							<?php if(!empty($ID))
							{
								if($getListFlightBookingByID[0]['requester_id'] == $_SESSION['user']['id'])
								{
									$readonly = '';
								}else{
									$readonly = 'readonly';
								}
							}else{
								$readonly = '';
							}
							?>
							<select required data-parsley-error-message="Passenger name is required." class="form-control select" name="edit_gID" id="edit_gID" <?php echo $readonly; ?>>
								<option value="-1" selected disabled>-- Please Select --</option>
								<?php if($listName) foreach($listName as $key => $gID){ 
									$dept_sName =  ($gID['department_name'])?' ['.$gID['department_short_name'].'] ':' [N/A]';
									$ic_no =  ($gID['ic_no'])?' ['.$gID['ic_no'].'] ':' [N/A]';
									$phone =  ($gID['phone'])?' ['.$gID['phone'].'] ':' [N/A]';
									?>
									<option value="<?php echo $gID['id']; ?>"><?php echo $gID['name'].$dept_sName.$ic_no.$phone; ?></option>
								<?php } ?>
							</select>
						</div>
						<div style="margin-bottom: 6rem;"></div>
						<div class="col-12">
							<label for="edit_passport">Passenger Passport No.</label>
							<input type="text" class="form-control" name="edit_passport" id="edit_passport" <?php echo ($getListFlightBookingByID[0]['departure_type'] == 1)?'disabled':'required'; ?>>
						</div>
					</div>
					<br>
					<div class="float-right" style="padding-bottom: 1rem;">
						<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
						<button type="submit" class="btn btn-primary">Update</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<!-- edit guest -->

<?php echo (!empty($approval) && $mode != "guest_detail")?$approval:''; ?>

<style type="text/css">
.tooltipevent
{
	width:auto;
	height:auto;
	background:rgba(0,0,0,0.75);
	position:absolute;
	color: #fff;
	z-index:10001;
	padding:10px 10px 10px 10px ;  
	line-height: 200%;
}
</style>

<script>

	$('#baggage').change(function(){

		let baggage = $('#baggage').val();

		if(baggage != 'other_bag')
		{
			$('#other_baggage').val(baggage);
			$( "#other_baggage" ).prop( "disabled", true );
		}else{
			$('#other_baggage').val('');
			$( "#other_baggage" ).prop( "disabled", false );
		}
	});

	function changeBaggage(elem) 
	{
		$('#other_baggage_write').val($(elem).val());    
	}

	function open_hidden_other_flightName(elem) 
	{
		let checked 		= $(elem).val();
		let input_name_id	= $(elem).data('otherflight');

		if(document.getElementById(input_name_id).checked)
		{
			$('#other_flight_name').removeAttr('disabled');
			$('#other_flight_name').removeAttr('hidden');
		}else {
			$('#other_flight_name').attr('disabled','disabled');
			$('#other_flight_name').attr('hidden','hidden');
		}
	}

	function confirmation() {
		confirm('Do you really want to submit the form?');
	}

	$(document).ready(function(){

		$('#table_flight').DataTable().destroy();

		var fc_event= '';
		var resource = <?php echo $resource;?>;

		var fullcalendar = $('#calendar').fullCalendar({ 
			themeSystem: 'bootstrap4',
			header: 
			{
				left: 'prev,next today',
				center: 'title',
				right: 'month,listMonth'
			},
			buttonText: {
				today: 'Today',
				month: 'Calendar',
				listMonth: 'List'
			},

            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: <?php echo $fc_event; ?>,

            eventMouseover: function (data, event, param, resource = <?php echo $resource;?>) {
            	var js_res = JSON.parse(JSON.stringify(resource));
            	var hover_item = js_res[data.id];
            	var title = JSON.stringify(data.title);
            	var depart_date = moment(hover_item.departure_date).format('DD-MM-YYYY');
            	var return_date = moment(hover_item.return_date).format('DD-MM-YYYY');
                // var depart_time = moment(hover_item.departure_time).format('00-00-00');
                // var return_time = moment(hover_item.return_time).format('00-00-00');

                tooltip = '<div class="tooltipevent"> Flight name : '+hover_item.flight_name+' <br/> Origin : '+hover_item.origin+'<br/> Destination : '+hover_item.destination+'<br/> Departure Date : '+depart_date+'<br/> Return Date : '+return_date+'<br/>Departure Time : '+hover_item.departure_time+' <br/> Return Time : '+hover_item.return_time+' </div>';

                $("body").append(tooltip);
                $(this).mouseover(function (e) {
                	$(this).css('z-index', 10000);
                	$('.tooltipevent').fadeIn('500');
                	$('.tooltipevent').fadeTo('10', 1.9);
                }).mousemove(function (e) {
                	$('.tooltipevent').css('top', e.pageY + 10);
                	$('.tooltipevent').css('left', e.pageX + 20);
                });
             },

             eventMouseout: function(data, event) {
             	$(this).css('z-index', 8);
             	$('.tooltipevent').remove();
             },
          });

		fullcalendar.fullCalendar();

		var mode = '<?php echo $mode ?>';
		if(mode != '' &&  mode == 'guest_detail')
		{
			$('html, body').animate({
				scrollTop: $("#guest_detail").offset().top
			}, 0);
		}
	});

	function open_close_passport_column(elem)
	{
		let departure_type = $(elem).val();

		if(departure_type == 1)
		{
			$('#passport').attr('readonly','readonly');
			$('#passport').removeAttr('required');
		}else{
			$('#passport').removeAttr('readonly');
			$('#passport').attr('required','required');
		}
	}

	function open_close_return_column(elem)
	{
		let ticket_type = $(elem).val();

		if(ticket_type == 1)
		{
			$('#return_date').attr('readonly','readonly');
			$('#return_time').attr('readonly','readonly');
			$('#return_date').removeAttr('required');
			$('#return_time').removeAttr('required');
		}else{
			$('#return_date').removeAttr('readonly');
			$('#return_time').removeAttr('readonly');
			$('#return_date').attr('required','required');
			$('#return_time').attr('required','required');
		}
	}

	function checkbox(elem)
	{
		var booking_checker = document.getElementById("booking_checker");

		if(booking_checker.checked == true)
		{
			$('#guest_details_form').removeClass('d-none');
			$('#guest_details').attr('required','required');
		}else{
			$('#guest_details_form').addClass('d-none');
			$('#guest_details').removeAttr('required');
			$('#guest_details').prop('selectedIndex',0);
		}
	}

	function editFlightDetail(elem)
	{
		let flight_id 	= $(elem).data('flightid');
		let detail_id 	= $(elem).data('detailsid');
		let guest_id 	= $(elem).data('guestid');
		let passport 	= $(elem).data('passport');

		$('#flight_id').val(flight_id);
		$('#flight_detail_ID').val(detail_id);
		$('#edit_gID').val(guest_id);
		$('#edit_gID').trigger('change');
		$('#edit_passport').val(passport);
	}

	function deleteFlightDetail(elem)
	{
		let flight_id 	= $(elem).data('flightid');
		let detail_id 	= $(elem).data('detailsid');
		let guest_id 	= $(elem).data('guestid');

		validateForm("#deleteButtonFlightDetail", "Delete this list?", function() {
			$.ajax({
				url:'<?php echo base_url('hr/serviceform/flight_delete_guest_detail') ?>',
				data: {
					flight_id 	: flight_id,
					detail_id 	: detail_id,
					guest_id 	: guest_id
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "Success") {

						localStorage.setItem("status", data.status);
						localStorage.setItem("msg", data.msg);

						location.replace(data.redirect);

                    // redirect(base_url('hr/serviceform/hotel_list'));
                 }
              }
           });
		});
	}

	function calculate_request_hour()
	{
		var checkin_date = $('#depart_date').val();
		var checkin_time = $('#depart_time').val();
		var server_date	= '<?php echo date("Y-m-d H:i:s"); ?>';

		if(checkin_date != '' && checkin_date != null)
		{
			$.ajax({
				url:'<?php echo base_url('hr/serviceform/change_date_format') ?>',
				data: {
					checkin_date : checkin_date,
					checkin_time : checkin_time
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "success") {

						var date_request 	= moment(data.date_time); 
						var date_server 	= moment(server_date); 
						var date_diff		= Math.floor((date_request-date_server)/36e5);
						if(date_diff < 48)
						{
							iziToast.error({
								title: 'Error',
								message: "Departure time less than 48 hours. Please update to new time. Thank you.",
							});

							$('#submitBtn').attr('disabled','disabled');
							$('#submitBtn').css("cursor","not-allowed");
						}else{
							iziToast.success({
								title: 'Success',
								message: "Success",
							});

							$('#submitBtn').removeAttr('disabled');
							$('#submitBtn').css("cursor","pointer");
						}
	                }
	          	}
	       	});
		}
	}
</script>