<?php
include_once('./_common.php');
//error_reporting( E_ALL);
//ini_set("display_errors",1);

/*
불당동 : 평일(오전11시 ~ 오후8시), 주말(오전11시 ~ 오후8시)이고 30분 단위로 예약
신부동 : 평일(오전10시 ~ 오후8시), 주말(오전10시 ~ 오후6시)이고 30분 단위로 예약
*/
$ck_rent_wr_id	= get_cookie("ck_rent_wr_id");
$sql	= " select wr_8 from g5_write_cloth_rent where wr_id = '{$ck_rent_wr_id}' ";
$row	= sql_fetch($sql);

$currdate = $_GET["currdate"];
if(!$currdate) { $currdate = date("Ymd"); }

//$nowdate = date("Ymd",strtotime("20150119"));
$nowdate = date("Ymd",time());
$day_type = date("N",strtotime($currdate)); // 1~5 평일, 6 토요일

//20190410의 데이터 가져와서  wr_1(날짜)  wr_2(시간) 이니까 이거 이용시  예약한지안한지 확인 가능. 
$checkdate	= date("Y년 m월 d일", strtotime($currdate));
$sql2	= " select a.wr_name,b.wr_2 from g5_write_cloth_rent a, g5_write_cloth_rent3 b where a.wr_id = b.wr_5 and a.wr_8 = '{$row['wr_8']}' and b.wr_1 = '{$checkdate}' and a.wr_9 = '1' ";
$result2	= sql_query($sql2);
$result_date = array();
$i = 0;
while($row2 = sql_fetch_array($result2)) {
	array_push($result_date,"{$row2['wr_2']}---{$row2['wr_name']}");
}

if($row['wr_8'] == "스플랜디노(불당동)") {
	$time_array[1] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[2] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[3] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[4] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[5] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[6] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[7] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
} else {
	$time_array[1] = array("10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[2] = array("10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[3] = array("10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[4] = array("10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[5] = array("10:00","10:30","11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00","18:30","19:00","19:30","20:00");
	$time_array[6] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00");
	$time_array[7] = array("11:00","11:30","13:00","13:30","14:00","14:30","15:00","15:30","16:00","16:30","17:00","17:30","18:00");
}
?>

<div class="schedule">
	<div class="time">
		<div class="time_list" id="time_list">
			<ul class="bu4" id="time_list2">
<?php
	foreach($time_array[$day_type] as $k=>$v)
	{
		$time_type = "오전";
		$reservation_yn = "Y";

		if($v >= "12:00") {
			$time_type = "오후";
		}
		
		// 고객이 선택한 날짜는 예약 불가
		foreach($result_date as $compareDate) {
			$compare_explode	= explode("---",$compareDate);
			$compareDate		= $compare_explode[0];
			//$compareName		= mb_substr($compare_explode[1], '0', -1)."O";
			$compareName		= preg_replace('/.(?!.)/u', 'O', $compare_explode[1]);
			if($compareDate == $time_type." ".$v) {
				$reservation_yn="N";
				$no_date_value	= "예약불가 {$compareName}";
			}
		}
		// 오늘날짜는 예약 불가
		if($currdate == date("Ymd")) { $reservation_yn="N"; $no_date_value	= "예약불가";}
?>				
				<li class="time_cls {currtime:'<?php echo $time_type." ".$v?>',reservation_yn:'<?php echo $reservation_yn?>'}"><a href="javascript:void(0);"><?php echo $time_type." ".$v?> <?php echo $reservation_yn=="Y"?"(예약가능)":"({$no_date_value})"?></a></li>
<?php
	}
?>				
				<!-- <li>&nbsp;</li> -->
			</ul>
		</div>
	</div>
</div>
<div class="date_ok timedate">
	<span class="date_choice time_class"></span><span>을 선택하셨습니다.</span>
</div>

<script>

// 2022.03.09 예약불가에 CSS 적용하기
// time li 접근
 let timeEndLi = document.querySelectorAll('.time_cls');

//  li tag 전체 접근
	timeEndLi.forEach(function(e){

		// li의 첫번째 자식 태그의 텍스트에 접근
	 const timeText = e.firstChild.innerText;

	//  텍스트에서 9번째에서 15번째 텍스트 자르기
	 const timeTextSlice = timeText.slice(9, 15);

	//  만약에 텍스트에 예약불가 있으면 아래에 css 적용
		if(timeTextSlice == '(예약불가)'){
			e.firstChild.style.opacity = "0.4";
			e.firstChild.style.textDecoration = "line-through";
 }
	})

 

</script>
