<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

//자동높이조절
apms_script('imagesloaded');
apms_script('height');

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$skin_url.'/style.css" media="screen">', 0);

// 버튼컬러
$btn1 = (isset($wset['btn1']) && $wset['btn1']) ? $wset['btn1'] : 'black';
$btn2 = (isset($wset['btn2']) && $wset['btn2']) ? $wset['btn2'] : 'color';

// 헤더 출력
if($header_skin)
	include_once('./header.php');

// 썸네일
$thumb_w = (isset($wset['thumb_w']) && $wset['thumb_w'] > 0) ? $wset['thumb_w'] : 400;
$thumb_h = (isset($wset['thumb_h']) && $wset['thumb_h'] > 0) ? $wset['thumb_h'] : 540;
$img_h = apms_img_height($thumb_w, $thumb_h, '135');

$wset['line'] = (isset($wset['line']) && $wset['line'] > 0) ? $wset['line'] : 2;
$line_height = 20 * $wset['line'];

// 간격
$gap_right = (isset($wset['gap']) && ($wset['gap'] > 0 || $wset['gap'] == "0")) ? $wset['gap'] : 15;
$minus_right = ($gap_right > 0) ? '-'.$gap_right : 0;

$gap_bottom = (isset($wset['gapb']) && ($wset['gapb'] > 0 || $wset['gapb'] == "0")) ? $wset['gapb'] : 30;
$minus_bottom = ($gap_bottom > 0) ? '-'.$gap_bottom : 0;

// 가로수
$item = (isset($wset['item']) && $wset['item'] > 0) ? $wset['item'] : 4;

// 반응형
if(_RESPONSIVE_) {
	$lg = (isset($wset['lg']) && $wset['lg'] > 0) ? $wset['lg'] : 3;
	$md = (isset($wset['md']) && $wset['md'] > 0) ? $wset['md'] : 3;
	$sm = (isset($wset['sm']) && $wset['sm'] > 0) ? $wset['sm'] : 2;
	$xs = (isset($wset['xs']) && $wset['xs'] > 0) ? $wset['xs'] : 2;
}

// 새상품
$is_new = (isset($wset['new']) && $wset['new']) ? $wset['new'] : 'red';
$new_item = ($wset['newtime']) ? $wset['newtime'] : 24;

// DC
$is_dc = (isset($wset['dc']) && $wset['dc']) ? $wset['dc'] : 'orangered';

// 그림자
$shadow_in = '';
$shadow_out = (isset($wset['shadow']) && $wset['shadow']) ? apms_shadow($wset['shadow']) : '';
if($shadow_out && isset($wset['inshadow']) && $wset['inshadow']) {
	$shadow_in = '<div class="in-shadow">'.$shadow_out.'</div>';
	$shadow_out = '';
}

$list_cnt = count($list);

include_once($skin_path.'/search.skin.form.php');

?>

<style>
	.list-wrap { margin-right:<?php echo $minus_right;?>px; margin-bottom:<?php echo $minus_bottom;?>px; }
	.list-wrap .item-row { width:<?php echo apms_img_width($item);?>%; }
	.list-wrap .item-list { margin-right:<?php echo $gap_right;?>px; margin-bottom:<?php echo $gap_bottom;?>px; }
	.list-wrap .item-name { height:<?php echo $line_height;?>px; }
	.list-wrap .img-wrap { padding-bottom:<?php echo $img_h;?>%; }
	<?php if(_RESPONSIVE_) { // 반응형일 때만 작동 ?>
		<?php if($lg) { ?>
		@media (max-width:1199px) {
			.responsive .list-wrap .item-row { width:<?php echo apms_img_width($lg);?>%; }
		}
		<?php } ?>
		<?php if($md) { ?>
		@media (max-width:991px) {
			.responsive .list-wrap .item-row { width:<?php echo apms_img_width($md);?>%; }
		}
		<?php } ?>
		<?php if($sm) { ?>
		@media (max-width:767px) {
			.responsive .list-wrap .item-row { width:<?php echo apms_img_width($sm);?>%; }
		}
		<?php } ?>
		<?php if($xs) { ?>
		@media (max-width:480px) {
			.responsive .list-wrap .item-row { width:<?php echo apms_img_width($xs);?>%; }
		}
		<?php } ?>
	<?php } ?>
</style>

<style>
	.nation_flag_img2 {
		width: 25px;
		height: 17px;
		margin-left: 0px;
		margin-right: 5px;
	}


	@media screen and (max-width: 600px) {
		.nation_flag_img2 {
			width: 25px;
			height: 17px;
			margin-left: 0px;
			margin-right: 5px;
		}
	}
</style>

<div class="list-wrap">
	<?php
	// 리스트
	for ($i=0; $i < $list_cnt; $i++) {

	// 경매상품이면 상품상세페이지 URL이 다르므로 변경시켜 줌 convertUrl() 함수는 이 파일 하단에 있음 JSLEE {
	if ($list[$i]['ca_id'] == '20') { // 경매카테고리ID
		$list[$i]['href'] = convertUrl($list[$i]['href']);
	}
	// 경매상품이면 상품상세페이지 URL이 다르므로 변경시켜 줌 convertUrl() 함수는 이 파일 하단에 있음 JSLEE }

		// DC
		$cur_price = $dc_per = '';
		if($list[$i]['it_cust_price'] > 0 && $list[$i]['it_price'] > 0) {
			$cur_price = '<strike>&nbsp;'.number_format($list[$i]['it_cust_price']).'&nbsp;</strike>';
			$dc_per = round((($list[$i]['it_cust_price'] - $list[$i]['it_price']) / $list[$i]['it_cust_price']) * 100);
		}

		// 라벨
		$item_label = '';

	if ($list[$i]['ca_id'] == '20') { // 경매카테고리ID
		if($dc_per || $list[$i]['it_type5']) {
			$item_label = '<div class="label-cap-opacity50 bg-red">DC</div>';
		} else if($list[$i]['it_type3'] || $list[$i]['pt_num'] >= (G5_SERVER_TIME - ($new_item * 3600))) {
			$item_label = '<div class="label-cap-opacity50 bg-'.$wset['new'].'">New</div>';
		}
	} else {
		if($dc_per || $list[$i]['it_type5']) {
			$item_label = '<div class="label-cap bg-red">DC</div>';
		} else if($list[$i]['it_type3'] || $list[$i]['pt_num'] >= (G5_SERVER_TIME - ($new_item * 3600))) {
			$item_label = '<div class="label-cap bg-'.$wset['new'].'">New</div>';
		}
	}

	// 아이콘
	$item_icon = item_icon($list[$i]);
	$item_icon = ($item_icon) ? '<div class="label-tack">'.$item_icon.'</div>' : '';

	// 이미지
	$img = apms_it_thumbnail($list[$i], $thumb_w, $thumb_h, false, true);

	// 경매정보 이미지 위에 표시 {
	if ($list[$i]['auction_on'] == '1') {

		$row1_tmp = sql_fetch(" select * from `{$g5['write_auction_table']}` where pcnum = '{$list[$i]['it_id']}' order by wr_id desc limit 1 ");
		get_info_auction($row1_tmp['wr_id'], $row1_tmp); // 이 함수 호출로 인해 최신의 경매상태정보를 변경시킴
		$row1 = sql_fetch(" select * from `{$g5['write_auction_table']}` where pcnum = '{$list[$i]['it_id']}' order by wr_id desc limit 1 ");
		$row2 = sql_fetch(" select * from `{$g5['write_auction_tender_table']}` where pcnum = '{$list[$i]['it_id']}' order by td_tender_point desc limit 1 ");

		if ($row2['td_tender_point'] === null || $row2['td_tender_point'] == 0) {

			$list[$i]['last_auction_price'] = $row1['wr_4']; // 경매 시작가
			$list[$i]['buy_it_now_price'] = $row1['wr_5']; // 경매 상한가 (즉구가)

			// 0=시작전, 1=진행중, 2=종료[낙찰], 3=종료[유찰]
			switch($row1['wr_8']) {
				case '0' : $od_status = '경매시작전'; $od_status_display = '<span style="color:silver">경매시작전</span>'; break;
				case '1' : $od_status = '경매진행중'; $od_status_display = '<span style="color:#66FF66">경매진행중</span>'; break;
				case '2' : $od_status = '경매종료[낙찰]'; $od_status_display = '<span style="color:#FFFF66">경매종료[낙찰]</span>'; break;
				case '3' : $od_status = '경매종료[유찰]'; $od_status_display = '<span style="color:silver">경매종료[유찰]</span>'; break;
				default  : $od_status = '경매취소'; $od_status_display = '<span style="color:silver">경매취소</span>'; break;
			}
			$list[$i]['last_auction_status'] = $od_status; // 경매 진행상태
			$list[$i]['last_auction_status_display'] = $od_status_display; // 경매 진행상태
			$list[$i]['rpc_rental_hours'] = (int)(isset($row1['rpc_rental_hours']) ? $row1['rpc_rental_hours'] : $row1['rpc_rental_days']);
			if($list[$i]['rpc_rental_hours'] < 1) {
				$list[$i]['rpc_rental_hours'] = 1;
			}
			$list[$i]['rpc_rental_days'] = $list[$i]['rpc_rental_hours']; // 경매 대여기간(시간)

			// 경매시작일시 주어진 시간 변수 (예: "2024-07-16 12:23:15")
			$auction_term_start = $row1['wr_1']; // 경매시작일시
			// 현재 시간
			$current_time = new DateTime();
			// 주어진 시간을 DateTime 객체로 변환
			$auction_term_start_dt = new DateTime($auction_term_start);
			// 두 시간의 차이 계산
			$interval = $current_time->diff($auction_term_start_dt);
			// 경과한 시간 형식 지정
			$auction_term_start_display = '';
			$start_display_flag = true;
			if ($interval->y > 0) {
				$auction_term_start_display .= $interval->y . '년 ';
				$start_display_flag = false;
			}
			if ($interval->m > 0) {
				$auction_term_start_display .= $interval->m . '개월 ';
				$start_display_flag = false;
			}
			if ($interval->d > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->d . '일 ';
				$start_display_flag = false;
			}
			if ($interval->h > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->h . '시간 ';
			}
			if ($interval->i > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->i . '분 ';
			}
			if ($interval->s > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->s . '초 ';
			}
			// 경과한 시간이 없다면 "0초" 표시
			if (empty($auction_term_start_display)) {
				$auction_term_start_display = '0초';
			}
			if ($start_display_flag) {
				if ((strtotime($auction_term_start)-G5_SERVER_TIME) < 0) {
					$term_start_tail_display = "경과";
				} else {
					$term_start_tail_display = "남음";
				}
			} else {
				if ((strtotime($auction_term_start)-G5_SERVER_TIME) < 0) {
					$term_start_tail_display = "이상 경과";
				} else {
					$term_start_tail_display = "이상 남음";
				}
			}

			// 경매종료일시 주어진 시간 변수 (예: "2024-07-16 12:23:15")
			$auction_term_stop = $row1['wr_2']; // 경매종료일시
			// 현재 시간
			$current_time = new DateTime();
			// 주어진 시간을 DateTime 객체로 변환
			$auction_term_stop_dt = new DateTime($auction_term_stop);
			// 두 시간의 차이 계산
			$interval = $current_time->diff($auction_term_stop_dt);
			// 경과한 시간 형식 지정
			$auction_term_stop_display = '';
			$stop_display_flag = true;
			if ($interval->y > 0) {
				$auction_term_stop_display .= $interval->y . '년 ';
				$stop_display_flag = false;
			}
			if ($interval->m > 0) {
				$auction_term_stop_display .= $interval->m . '개월 ';
				$stop_display_flag = false;
			}
			if ($interval->d > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->d . '일 ';
				$stop_display_flag = false;
			}
			if ($interval->h > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->h . '시간 ';
			}
			if ($interval->i > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->i . '분 ';
			}
			if ($interval->s > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->s . '초 ';
			}
			// 경과한 시간이 없다면 "0초" 표시
			if (empty($auction_term_stop_display)) {
				$auction_term_stop_display = '0초';
			}
			if ($stop_display_flag) {
				if ((strtotime($auction_term_stop)-G5_SERVER_TIME) < 0) {
					$term_stop_tail_display = "경과";
				} else {
					$term_stop_tail_display = "남음";
				}
			} else {
				if ((strtotime($auction_term_stop)-G5_SERVER_TIME) < 0) {
					$term_stop_tail_display = "이상 경과";
				} else {
					$term_stop_tail_display = "이상 남음";
				}
			}
			$list[$i]['rpc_auction_expire_remaintime'] = $auction_term_stop_display . $term_stop_tail_display; // 경매 종료시간

			$list[$i]['rpc_auction_expire_date'] = $row1['wr_2']; // 경매 종료시간

			$list[$i]['rpc_auction_term_stop'] = strtotime($auction_term_stop) * 1000; // 자바스크립트에서 사용할 밀리초 단위 시간

		} else {

			$list[$i]['last_auction_price'] = $row2['td_tender_point']; // 경매 시작가
			$list[$i]['buy_it_now_price'] = $row1['wr_5']; // 경매 상한가 (즉구가)

			// 0=시작전, 1=진행중, 2=종료[낙찰], 3=종료[유찰]
			switch($row2['td_status']) {
				case '0' : $od_status = '경매시작전'; $od_status_display = '<span style="color:silver">경매시작전</span>'; break;
				case '1' : $od_status = '경매진행중'; $od_status_display = '<span style="color:#66FF66">경매진행중</span>'; break;
				case '2' : $od_status = '경매종료[낙찰]'; $od_status_display = '<span style="color:#FFFF66">경매종료[낙찰]</span>'; break;
				case '3' : $od_status = '경매종료[유찰]'; $od_status_display = '<span style="color:silver">경매종료[유찰]</span>'; break;
				default  : $od_status = '경매취소'; $od_status_display = '<span style="color:silver">경매취소</span>'; break;
			}
			$list[$i]['last_auction_status'] = $od_status; // 경매 진행상태
			$list[$i]['last_auction_status_display'] = $od_status_display; // 경매 진행상태
			$list[$i]['rpc_rental_hours'] = (int)(isset($row1['rpc_rental_hours']) ? $row1['rpc_rental_hours'] : $row1['rpc_rental_days']);
			if($list[$i]['rpc_rental_hours'] < 1) {
				$list[$i]['rpc_rental_hours'] = 1;
			}
			$list[$i]['rpc_rental_days'] = $list[$i]['rpc_rental_hours']; // 경매 대여기간(시간)

			// 경매시작일시 주어진 시간 변수 (예: "2024-07-16 12:23:15")
			$auction_term_start = $row1['wr_1']; // 경매시작일시
			// 현재 시간
			$current_time = new DateTime();
			// 주어진 시간을 DateTime 객체로 변환
			$auction_term_start_dt = new DateTime($auction_term_start);
			// 두 시간의 차이 계산
			$interval = $current_time->diff($auction_term_start_dt);
			// 경과한 시간 형식 지정
			$auction_term_start_display = '';
			$start_display_flag = true;
			if ($interval->y > 0) {
				$auction_term_start_display .= $interval->y . '년 ';
				$start_display_flag = false;
			}
			if ($interval->m > 0) {
				$auction_term_start_display .= $interval->m . '개월 ';
				$start_display_flag = false;
			}
			if ($interval->d > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->d . '일 ';
				$start_display_flag = false;
			}
			if ($interval->h > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->h . '시간 ';
			}
			if ($interval->i > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->i . '분 ';
			}
			if ($interval->s > 0 && $start_display_flag) {
				$auction_term_start_display .= $interval->s . '초 ';
			}
			// 경과한 시간이 없다면 "0초" 표시
			if (empty($auction_term_start_display)) {
				$auction_term_start_display = '0초';
			}
			if ($start_display_flag) {
				if ((strtotime($auction_term_start)-G5_SERVER_TIME) < 0) {
					$term_start_tail_display = "경과";
				} else {
					$term_start_tail_display = "남음";
				}
			} else {
				if ((strtotime($auction_term_start)-G5_SERVER_TIME) < 0) {
					$term_start_tail_display = "이상 경과";
				} else {
					$term_start_tail_display = "이상 남음";
				}
			}

			// 경매종료일시 주어진 시간 변수 (예: "2024-07-16 12:23:15")
			$auction_term_stop = $row1['wr_2']; // 경매종료일시
			// 현재 시간
			$current_time = new DateTime();
			// 주어진 시간을 DateTime 객체로 변환
			$auction_term_stop_dt = new DateTime($auction_term_stop);
			// 두 시간의 차이 계산
			$interval = $current_time->diff($auction_term_stop_dt);
			// 경과한 시간 형식 지정
			$auction_term_stop_display = '';
			$stop_display_flag = true;
			if ($interval->y > 0) {
				$auction_term_stop_display .= $interval->y . '년 ';
				$stop_display_flag = false;
			}
			if ($interval->m > 0) {
				$auction_term_stop_display .= $interval->m . '개월 ';
				$stop_display_flag = false;
			}
			if ($interval->d > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->d . '일 ';
				$stop_display_flag = false;
			}
			if ($interval->h > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->h . '시간 ';
			}
			if ($interval->i > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->i . '분 ';
			}
			if ($interval->s > 0 && $stop_display_flag) {
				$auction_term_stop_display .= $interval->s . '초 ';
			}
			// 경과한 시간이 없다면 "0초" 표시
			if (empty($auction_term_stop_display)) {
				$auction_term_stop_display = '0초';
			}
			if ($stop_display_flag) {
				if ((strtotime($auction_term_stop)-G5_SERVER_TIME) < 0) {
					$term_stop_tail_display = "경과";
				} else {
					$term_stop_tail_display = "남음";
				}
			} else {
				if ((strtotime($auction_term_stop)-G5_SERVER_TIME) < 0) {
					$term_stop_tail_display = "이상 경과";
				} else {
					$term_stop_tail_display = "이상 남음";
				}
			}
			$list[$i]['rpc_auction_expire_remaintime'] = $auction_term_stop_display . $term_stop_tail_display; // 경매 종료시간

			$list[$i]['rpc_auction_expire_date'] = $row1['wr_2']; // 경매 종료시간

			$list[$i]['rpc_auction_term_stop'] = strtotime($auction_term_stop) * 1000; // 자바스크립트에서 사용할 밀리초 단위 시간

		}
	}
	// 경매정보 이미지 위에 표시 }
?>

		<div class="item-row">
			<div class="item-list">
				<div class="item-image">
					<a href="<?php echo $list[$i]['href'];?>">
						<div class="img-wrap">
							<?php echo $shadow_in;?>
							<?php echo $item_label;?>
							<?php echo $item_icon;?>
							<div class="img-item">
								<img src="<?php echo $img['src'];?>" alt="<?php echo $img['alt'];?>">
							<?php if ($list[$i]['rpc_auction_expire_date']) { ?>
								<div class="overlay-text" style="position: absolute; top: 13px; left: 50%; transform: translate(-50%, -50%); font-size: 1rem; font-weight: bold; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:left; width:98%; background:rgba(0,0,0,0.25); padding:2px 5px;">
									<?php echo $list[$i]['last_auction_status_display']?>
								</div>
								<div class="overlay-text" style="position: absolute; top: 13px; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 1rem; font-weight: bold; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:right; width:98%; padding:2px 5px;">
									<span class="auction_remain_timer" data-expire-time="<?php echo $list[$i]['rpc_auction_term_stop'] ?>" style='font-weight:normal; font-size:0.9rem;'></span>
								</div>
								<!--
								<div class="overlay-text" style="position: absolute; top: 35px; left: 50%; transform: translate(-50%, -50%); color: silver; font-size: 0.9rem; font-weight: normal; text-shadow: 2px 2px 4px rgba(0, 0, 0, 1); white-space: nowrap; text-align:center; width:98%;">
									<?php
										$auction_hours = (int)(isset($list[$i]['rpc_rental_hours']) ? $list[$i]['rpc_rental_hours'] : $list[$i]['rpc_rental_days']);
										echo "즉시구매가 ".number_format($list[$i]['buy_it_now_price'])." Point / ".apms_contract_hours_text($auction_hours);
									?>
								</div>
								-->
								<div class="overlay-text" style="position: absolute; bottom: -10px; left: 50%; transform: translate(-50%, -50%); color: silver; font-size: 0.9rem; font-weight: normal; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:left; width:98%; padding:2px 5px;">
									<?php echo get_pt_seller_name($list[$i]['pt_id']); ?>
								</div>
								<div class="overlay-text" style="position: absolute; bottom: -10px; left: 50%; transform: translate(-50%, -50%); color: silver; font-size: 0.9rem; font-weight: normal; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:right; width:98%; padding:2px 5px;">
									<?php //echo "매너온도 " . get_pt_manner_temperature($list[$i]['pt_id']); ?>
									<?php echo apms_get_star($list[$i]['it_use_avg'], $wset['star']); //평균별점 ?>
								</div>
							<?php } else { ?>
								<div class="overlay-text" style="position: absolute; bottom: -10px; left: 50%; transform: translate(-50%, -50%); color: silver; font-size: 0.9rem; font-weight: normal; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:left; width:98%; padding:2px 5px;">
									<?php echo get_pt_seller_name($list[$i]['pt_id']); ?>
								</div>
								<div class="overlay-text" style="position: absolute; bottom: -10px; left: 50%; transform: translate(-50%, -50%); color: silver; font-size: 0.9rem; font-weight: normal; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); white-space: nowrap; text-align:right; width:98%; padding:2px 5px;">
									<?php //echo "매너온도 " . get_pt_manner_temperature($list[$i]['pt_id']); ?>
									<?php echo apms_get_star($list[$i]['it_use_avg'], $wset['star']); //평균별점 ?>
								</div>
							<?php } ?>
							</div>
						</div>
					</a>
					<?php echo $shadow_out;?>
				</div>
				<div class="item-content">
					<?php if($wset['star']) { ?>
						<div class="item-star">
							<?php echo apms_get_star($list[$i]['it_use_avg'], $wset['star']); //평균별점 ?>
						</div>
					<?php } ?>
					<div class="item-name" style="height:25px;">
					<a href="<?php echo $list[$i]['href'];?>">
						<b><?php echo ($list[$i]['ca_id'] == '20') ? "[Auction] " . $list[$i]['it_name'] : $list[$i]['it_name'];?></b>
						<!-- <div class="item-text">
							<?php echo ($list[$i]['it_basic']) ? $list[$i]['it_basic'] : apms_cut_text($list[$i]['it_explan'], 120); ?>
						</div> -->
					</a>
				</div>
			<div class="list_skin">
				<style>
					/* 마우스가 올라갔을 때 tr 스타일 */
					.list_skin table tr:hover {
						background-color: #333; /* 다른 배경색으로 변경 */
						color: #fff; /* 텍스트 색상 변경 */
					}
					/* 셀 스타일 */
					.list_skin table td, .list_skin table th {
						white-space: nowrap;
						padding: 0 5px;
						border: none;
						overflow: hidden;
						text-overflow: ellipsis;
						font-size: 0.7em;
						text-align: left;
					}
					.list_skin table th {
						max-width: 150px;
					}
					.list_skin table td {
						width: 20%;
						max-width: 50px;
					}
				</style>
				<a href="<?php echo $list[$i]['href'];?>">
					<table style="width: 100%; margin-top: 0px; border-collapse: collapse; border: 1px solid #ddd;">
						<?php
						$headers = ["", "OS", "CPU", "GPU", "IP", "RAM", "SSD", "HDD", "USB"];
						$rows = [];

						$result_api_data = sql_query("SELECT * FROM {$g5['g5_shop_item_table']} WHERE it_id='{$list[$i]['it_id']}' ORDER BY it_id DESC LIMIT 1");
						while($api_data = sql_fetch_array($result_api_data)){
							$it_id = $api_data['it_id'];
							$it_origin_mgr_from_api = $api_data['it_origin_mgr_from_api'];
							$M_storeid = explode("Ž",$api_data['it_origin_mgr_from_api'])[0]." ".explode("Ž",$api_data['it_origin_mgr_from_api'])[1];
							$M_storename = explode("Ž",$api_data['it_origin_mgr_from_api'])[2];
							// $extIP = $api_data['extIP'];
							// JSON 데이터
							$jsonData_it_spec_remote_sw = $api_data['it_spec_remote_sw'];

							// JSON 데이터를 배열로 디코드
							$dataArray_it_spec_remote_sw = json_decode($jsonData_it_spec_remote_sw, true);

							// RemoteIP 값을 추출하여 $extIP 변수에 저장
							$extIP = isset($dataArray_it_spec_remote_sw[0]['RemoteIP__0']) ? $dataArray_it_spec_remote_sw[0]['RemoteIP__0'] : null;
							$remote_ip_org = explode(" ", $extIP)[0];
							$remote_ip_parts = explode(".", $remote_ip_org); // IP 주소를 점(.)으로 분리
							// 각 부분을 3자리로 맞추기 위해 앞에 0을 추가
							foreach ($remote_ip_parts as &$part) {
								$part = str_pad($part, 3, '0', STR_PAD_LEFT);
							}
							// 마스킹할 부분을 선택
							$remote_ip_parts[1] = '***';
							$remote_ip_parts[3] = '***';
							// 마스킹된 IP 주소를 다시 조합
							$masked_ip = implode(".", $remote_ip_parts);
							$remote_ip = $masked_ip; // 출력: 111.***.022.***

							$remote_ip_country_code = strtolower($dataArray_it_spec_remote_sw[0]['RemoteIP_CountryCode__0']);
							$remote_ip_country_name = $dataArray_it_spec_remote_sw[0]['RemoteIP_CountryName__0'];
							$remote_ip_city_name = $dataArray_it_spec_remote_sw[0]['RemoteIP_City__0'];
							$remote_ip_country_flag = "<img src='" . G5_DATA_URL . "/item/img_nation_flag/svg/{$remote_ip_country_code}.svg' class='nation_flag_img2'>";

							//$it_spec_cpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)", "Intel", "AMD", "with Radeon Graphics", "with Radeon Vega Graphics", "CPU", "Core ", " Cores", "Eight-Processor"), array("", "", "", "", "", "", "", "", "C", ""), $api_data['it_spec_cpu'])));
							$it_spec_cpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)", "with Radeon Graphics", "with Radeon Vega Graphics", "CPU", "Core ", "Eight-Processor"), array("", "", "", "", "", "", ""), $api_data['it_spec_cpu'])));
							if (count($it_spec_cpu_arr) == 1) {
								$it_spec_cpu = $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 2) {
								$it_spec_cpu = "[Dual] " . $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 3) {
								$it_spec_cpu = "[Triple] " . $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 4) {
								$it_spec_cpu = "[Quad] " . $it_spec_cpu_arr[0];
							}
							if (stripos($it_spec_cpu, 'intel') !== false) {
								$logo_cpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_intel.png' class='cpu_logo_img2'>";
							} else if (stripos($it_spec_cpu, 'amd') !== false) {
								$logo_cpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_amd.png' class='cpu_logo_img2'>";
							} else {
								$logo_cpu = "";
							}

							// CPU 데이터
							$cpu_data = $api_data['it_spec_cpu'];

							// 정규식을 사용하여 괄호 속에 "Cores"라는 단어가 포함된 숫자를 추출
							if (preg_match('/\((\d+) Cores\)/', $cpu_data, $matches)) {
								// 추출된 숫자를 $cpu_core 변수에 저장
								$cpu_core = $matches[1];
							} else {
								// "Cores"가 포함된 문자열이 없는 경우
								$cpu_core = null;
							}
							$it_spec_mainboard = $api_data['it_spec_mainboard'];
							$it_spec_ram = $api_data['it_spec_ram'];
							$it_spec_ram_type = $api_data['it_spec_ram_type'];
							//$SSDinfo = $api_data['SSDinfo'];
							$it_spec_ssd =  $api_data['it_spec_ssd'] === "0 GB" ? "<div style='width:100%; min-width:40px; text-align:left;'>Not installed</div>" : $api_data['it_spec_ssd'];
							$it_spec_ssd_type = $api_data['it_spec_ssd_type'];
							//$SSD = $api_data['SSD'];
							//$HDDinfo = $api_data['HDDinfo'];
							$it_spec_hdd = $api_data['it_spec_hdd'] === "0 GB" ? "<div style='width:100%; min-width:40px; text-align:left;'>Not installed</div>" : $api_data['it_spec_hdd'];
							$it_spec_hdd_type = $api_data['it_spec_hdd_type'];
							//$HDD = $api_data['HDD'];
							$it_spec_gpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)"), array("", ""), $api_data['it_spec_gpu'])));
							if (count($it_spec_gpu_arr) == 1) {
								$it_spec_gpu = $it_spec_gpu_arr[0];
							} else if (count($it_spec_gpu_arr) > 1) {
								if ((strpos($it_spec_gpu_arr[0], "NVIDIA") !== false) || (strpos($it_spec_gpu_arr[0], "AMD") !== false)) {
									$it_spec_gpu = $it_spec_gpu_arr[0];
								} else if ((strpos($it_spec_gpu_arr[1], "NVIDIA") !== false) || (strpos($it_spec_gpu_arr[1], "AMD") !== false)) {
									$it_spec_gpu = $it_spec_gpu_arr[1];
								} else {
									$it_spec_gpu = $it_spec_gpu_arr[0] . "<br>" . $it_spec_gpu_arr[1];
								}
							}
							if (stripos($it_spec_gpu, 'nvidia') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia.png' class='gpu_logo_img2'>";
							}
							if (stripos($it_spec_gpu, 'quadro') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia_quadro.png' class='gpu_logo_img2'>";
							} else if (stripos($it_spec_gpu, 'geforce') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia_geforce.png' class='gpu_logo_img2'>";
							}

							if (stripos($it_spec_gpu, 'radeon') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_amd_radeon.png' class='gpu_logo_img2'>";
							} else {
								$logo_gpu = "";
							}

							//$gpu_ram = $api_data['gpu_ram'];

							//$it_spec_os = trim(str_ireplace(array("Microsoft", "Windows", "(64Bit)"), array("", "Win", ""), $api_data['it_spec_os']));
							$it_spec_os = trim($api_data['it_spec_os']);
							if (stripos($it_spec_os, 'Windows 11') !== false || stripos($it_spec_os, 'Windows11') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows11.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 10') !== false || stripos($it_spec_os, 'Windows10') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows10.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 8') !== false || stripos($it_spec_os, 'Windows8') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows8.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 7') !== false || stripos($it_spec_os, 'Windows7') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows7.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows Server 2016') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/WindowsServer2016.png' class='os_img2'>";
							} else {
								$OS_flag = "";
							}

							$rantal_fee_type = $api_data['rantal_fee_type'];
							$rental_fee = $api_data['rental_fee'];
							$rental_setting_fee = $api_data['rental_setting_fee'];
							$rental_fee_first_daily = round(($rental_fee + $rental_setting_fee) / 30);
							$rental_fee_ext_daily = round(($rental_fee) / 30);
							$rental_stat = $api_data['rental_stat'];
							$client_number = $api_data['client_number'];
							$cpu_clock = $api_data['cpu_clock'];
							$AppVer = $api_data['AppVer'];

							$it_spec_keyboard = !empty(trim($api_data['it_spec_keyboard'])) ? "KEYBOARD" : "";
							$it_spec_mouse = !empty(trim($api_data['it_spec_mouse'])) ? "MOUSE" : "";

							// Initialize the array
							$it_spec_device_arr = [];

							// Check if $it_spec_keyboard is not empty and add to array
							if (!empty(trim($it_spec_keyboard))) {
								$it_spec_device_arr[] = "KEYBOARD(O)";
							} else {
								$it_spec_device_arr[] = "KEYBOARD(X)";
							}

							// Check if $it_spec_mouse is not empty and add to array
							if (!empty(trim($it_spec_mouse))) {
								$it_spec_device_arr[] = "MOUSE(O)";
							} else {
								$it_spec_device_arr[] = "MOUSE(X)";
							}

							// Join array elements with a comma if there are multiple elements
							$it_spec_devices = (count($it_spec_device_arr) > 0) ? implode(', ', $it_spec_device_arr) : "KEYBOARD(X) , MOUSE(X)";

							$rows[] = [
								!empty(trim($remote_ip_country_name)) ? !empty($remote_ip_city_name) ? $remote_ip_country_flag . $remote_ip_country_name . " / " . $remote_ip_city_name : $remote_ip_country_flag . $remote_ip_country_name : "",
								$it_spec_os,
								$it_spec_cpu,
								$it_spec_gpu,
								!empty(trim($remote_ip_country_name)) ? $remote_ip : $remote_ip,
								$it_spec_ram . (!empty($it_spec_ram_type) ? " ($it_spec_ram_type)" : ""),
								$it_spec_ssd . (!empty($it_spec_ssd_type) ? " ($it_spec_ssd_type)" : ""),
								$it_spec_hdd . (!empty($it_spec_hdd_type) ? " ($it_spec_hdd_type)" : ""),
								$it_spec_devices
							];
						}

						$ignore_headers = ["IP", "RAM", "SSD", "HDD", "USB"];
						foreach ($headers as $index => $header) {
							echo "<tr>";
							if (!in_array($header, $ignore_headers)) {
								foreach ($rows as $row) {
									echo "<th colspan='2'>{$row[$index]}</th>";
								}
							} else {
								echo "<td>$header </td>";
								foreach ($rows as $row) {
									echo "<th>{$row[$index]}</th>";
								}
							}

							echo "</tr>";
						}
						?>
					</table>
				</a>
			</div>

				<div class="item-price en">
					<?php if($list[$i]['it_tel_inq']) { ?>
						<b>Call</b>
					<?php } else { ?>
						<?php echo $cur_price;?>
						<?php if ($list[$i]['ca_id'] == '20') { ?>
							<b><!--<i class="fa fa-krw"></i>--><?php echo number_format($list[$i]['last_auction_price']);?> Point</b><small>/ 최종입찰</small>
						<?php } else { ?>
							<b><!--<i class="fa fa-krw"></i>--><?php echo number_format($list[$i]['it_price']);?> Point</b><small>/ 1일</small>
							<?php $min_contract_hours = apms_buy_qty_to_hours($list[$i]['it_buy_min_qty']); ?>
							<span class="item-sp darkgray">
								<i class="fa fa-bolt"></i>
								<?php echo 'Minimum '.apms_contract_hours_text($min_contract_hours).' required'; ?>
							</span>
						<?php } ?>
					<?php } ?>
				</div>
				<div class="item-details en">
					<?php if($wset['cmt'] && $list[$i]['pt_comment']) { ?>
						<span class="item-sp red">
							<i class="fa fa-comment"></i>
							<?php echo number_format($list[$i]['pt_comment']);?>
						</span>
					<?php } ?>
					<?php if($wset['buy'] && $list[$i]['it_sum_qty']) { ?>
						<span class="item-sp blue">
							<i class="fa fa-shopping-cart"></i>
							<?php echo number_format($list[$i]['it_sum_qty']);?>
						</span>
					<?php } ?>
					<?php if($wset['hit'] && $list[$i]['it_hit']) { ?>
						<span class="item-sp gray">
							<i class="fa fa-eye"></i>
							<?php echo number_format($list[$i]['it_hit']);?>
						</span>
					<?php } ?>

					<?php if ($list[$i]['ca_id'] == '20') { ?>
						<span class="item-sp blue">
							<i class="fa fa-tags"></i>
							<?php echo round((1 - ($list[$i]['last_auction_price'] / $list[$i]['buy_it_now_price'])) * 100) . "% Discount";?>
						</span>
					<?php } else { ?>
						<?php if($list[$i]['it_point']) { ?>
							<span class="item-sp green">
								<i class="fa fa-gift"></i>
									<?php echo ($list[$i]['it_point_type'] == 2) ? $list[$i]['it_point'].'% Get Points' : number_format(get_item_point($list[$i]));?>
							</span>
						<?php } ?>
					<?php } ?>

					<?php if($dc_per) { ?>
						<span class="item-sp orangered">
							<i class="fa fa-bolt"></i>
							<?php echo $dc_per;?>% DC
						</span>
					<?php } ?>
				</div>
			</div>
			<?php if($wset['sns']) { ?>
				<div class="item-sns">
					<?php
						$sns_url  = G5_SHOP_URL.'/item.php?it_id='.$list[$i]['it_id'];
						$sns_title = get_text($list[$i]['it_name']);
						$sns_img = $skin_url.'/img';
						echo  get_sns_share_link('facebook', $sns_url, $sns_title, $sns_img.'/sns_fb.png').' ';
						echo  get_sns_share_link('twitter', $sns_url, $sns_title, $sns_img.'/sns_twt.png').' ';
						echo  get_sns_share_link('googleplus', $sns_url, $sns_title, $sns_img.'/sns_goo.png').' ';
						echo  get_sns_share_link('kakaostory', $sns_url, $sns_title, $sns_img.'/sns_kakaostory.png').' ';
						echo  get_sns_share_link('kakaotalk', $sns_url, $sns_title, $sns_img.'/sns_kakao.png').' ';
						echo  get_sns_share_link('naverband', $sns_url, $sns_title, $sns_img.'/sns_naverband.png').' ';
					?>
				</div>
			<?php } ?>
		</div>
	</div>
	<?php } // end for ?>
	<?php if(!$list_cnt) { ?>
		<div class="list-none">등록된 상품이 없습니다.</div>
	<?php } ?>

	<?php
	// 경매상품이면 상품상세페이지 URL이 다르므로 변경시켜 주는 함수 JSLEE {
	function convertUrl($url) {
		global $g5;

		// URL을 파싱하여 쿼리 문자열을 추출
		$parsedUrl = parse_url($url);
		parse_str($parsedUrl['query'], $queryParams);

		// it_id 값을 추출
		$it_id = $queryParams['it_id'];

		// write_auction_table 에서 wr_id 확인
		$row = sql_fetch("SELECT wr_id FROM {$g5['write_auction_table']} WHERE pcnum = '$it_id' ");
		// 새로운 URL을 생성
		$newUrl = G5_BBS_URL . "/board.php?bo_table=auction&wr_id=" . $row['wr_id'] . "&s=&pcnum=" . $it_id;

		return $newUrl;
	}
	// 경매상품이면 상품상세페이지 URL이 다르므로 변경시켜 주는 함수 JSLEE }
	?>

	<script>
		document.addEventListener("DOMContentLoaded", function() {
			function updateAuctionTime() {
				const elements = document.querySelectorAll('.auction_remain_timer');
				elements.forEach(function(element) {
					const expireTime = parseInt(element.getAttribute('data-expire-time'), 10);
					const currentTime = new Date().getTime();
					const timeRemaining = expireTime - currentTime;

					if (timeRemaining > 0) {
						const seconds = Math.floor((timeRemaining / 1000) % 60);
						const minutes = Math.floor((timeRemaining / (1000 * 60)) % 60);
						const hours = Math.floor((timeRemaining / (1000 * 60 * 60)) % 24);
						const days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));

						let displayTime = '';
						if (days > 0) displayTime += days + '일 ';
						// 시,분,초를 2자리로 표시하고, 값이 0일 때도 항상 출력되도록 설정
						if (days > 0) {
							displayTime += ('0' + hours).slice(-1) + '시간 ';
						} else {
							if (hours > 0) displayTime += hours + '시간 ';
						}
						displayTime += ('0' + minutes).slice(-2) + '분 ';
						displayTime += ('0' + seconds).slice(-2) + '초 ';

						// element.textContent = displayTime + "남음";
						element.textContent = displayTime;
					} else {
						element.textContent = "종료";
					}
				});
			}

			// 매 1초마다 남은 시간을 업데이트
			setInterval(updateAuctionTime, 1000);

			// 페이지 로드 후 즉시 시간 업데이트
			updateAuctionTime();
		});
	</script>

	<div class="clearfix"></div>
</div>
<script>
$(document).ready(function(){
	$('.list-wrap').imagesLoaded(function(){
		$('.list-wrap .item-content').matchHeight();
	});
});
</script>

<div class="list-page text-center">
	<ul class="pagination en">
		<?php echo apms_paging($write_pages, $page, $total_page, $list_page); ?>
	</ul>
	<div class="clearfix"></div>
</div>

<?php if ($is_admin || $setup_href) { ?>
	<div class="text-center">
		<?php if($is_admin) { ?>
			<a class="btn btn-<?php echo $btn1;?> btn-sm" href="<?php echo G5_ADMIN_URL;?>/apms_admin/apms.admin.php?ap=thema"><i class="fa fa-cog"></i> 설정</a>
		<?php } ?>
		<?php if($setup_href) { ?>
			<a class="btn btn-<?php echo $btn2;?> btn-sm win_memo" href="<?php echo $setup_href;?>"><i class="fa fa-cogs"></i> 스킨설정</a>
		<?php } ?>
		<div class="h30"></div>
	</div>
<?php } ?>
