<%@page import="cmn.Cmn"%>
<%@page import="cmn.CmnDAO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="bbs.BbsDAO"%>
<%@page import="bbs.Bbs"%>
<%@page import="user.UserDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TKmall</title>
<style>
        /* 스타일링을 위한 CSS 코드 */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        header {
            background-color: white;
            color: white;
            padding: 7px;
            text-align: right;
        }
        header a {
            color: #000;
            text-decoration: none;
            margin-left: 8px;
            font-size: 10px;
        }
    </style>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>
<body>
	<% 
		String ID = null;
		if (session.getAttribute("ID") != null) {
			ID = (String) session.getAttribute("ID");
		}
		
		int USER_TYPE = 1;
		UserDAO u = new UserDAO();
		USER_TYPE = u.fmanager(ID);
		
		String NAME = null;
		NAME = u.yourname(ID);
	%>
	<!-- 위의 헤더 -->
	<header>
	    <!-- 로그인 여부에 따라 다르게 표시 -->
	    <%	if(ID == null) { %>
	        <a href="login.jsp">로그인</a>
	        <a href="join.jsp">회원가입</a>
	        <a href="cart.jsp">장바구니</a>
	        
	     <% }else if(USER_TYPE == 1) { %>
	     	<a href="main.jsp"><%=NAME %>님 어서오세요</a>
	        <a href="logoutAction.jsp">로그아웃</a>
	        <a href="mypage.jsp">마이페이지</a>
	        <a href="cart.jsp">장바구니</a>
	     <%} else { %>
	    
	    <a href="main.jsp">관리자</a>
	    <a href="logoutAction.jsp">로그아웃</a>
	    <a href="site.jsp">사이트 관리</a>
	    <%} %>
	    &nbsp;&nbsp;&nbsp;
	</header>
	
	<!-- 로고와 검색창 -->
	<div class="container">
    	<div class="row align-items-center flex-row">
    	<!-- align-items-center은 로고와 검색창 위아래정렬 flex-row는 검색 단어 가로쓰기 변경-->
        	<div class="col-md-2">
            	<!-- 상위구획 1 : 로고 -->
            	<button type="button" class="btn" style="background-color: transparent; border: none;" onclick="location.href='main.jsp'">
            		<img src="./base/base_lo.png" class="img-fluid" alt="로고 이미지 손상">
          		</button>
        	</div>
        	<div class="col-md-1">
            	<!-- 상위구획 2 : 빈 공간 -->
            
        	</div>
        	<div class="col-md-6">
            	<!-- 상위구획 3 : 검색창 공간 -->
            	<form class="d-flex" role="search">
      				<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      				<button class="btn btn-outline-primary" type="submit">
      					<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
  						<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/>
						</svg>
      				</button>
    			</form>
        	</div>
        	<div class="col-md-3">
            	<!-- 상위구획 2 : 빈 공간 -->
            
        	</div>
    	</div>
	</div>
	<br>
	<!-- 카테고리창 -->
	<div class="container">
	    <div class="row align-items-center flex-row">
	    	<div class="col-md-1">
	            <!-- 빈 공간 -->
	            
	        </div>
	        <div class="col-md-10">
				<nav class="nav nav-pills nav-fill" style="border: 1px solid #dddddd; padding: 10px; background-color: #0d6efd;">
				  <a class="nav-link" href="blade.jsp"  style="color: white;">블레이드</a>
				  <a class="nav-link" href="rub.jsp" style="color: white;">러버</a>
				  <a class="nav-link" href="ball.jsp" style="color: white;">공</a>
				  <a class="nav-link" href="others.jsp" style="color: white;">기타 용품</a>
				  <a class="nav-link" href="uniform.jsp" style="color: white;">의류/신발</a>
				  <a class="nav-link" href="table.jsp" style="color: white;">탁구대</a>
				  <a class="nav-link disabled"  style="color: white;"><!-- aria-disabled="true" >-->세트</a>
				</nav>
			</div>
			<div class="col-md-1">
	            <!-- 빈 공간 -->
	            
	        </div>
	    </div>
	</div>
		<br>
	<!-- 홍보이미지칸 -->
	<div class="container">
	    <div class="row align-items-center flex-row">
	    	<div class="col-md-1">
	            <!-- 빈 공간 -->
	            
	        </div>
	        <div class="col-md-10">
				<!-- <img src="./base/base_ma.jpg" class="img-fluid" alt="대표 이미지 손상"> -->
				
				<div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel">
				<div class="carousel-indicators">
				    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
				    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
				<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
				  </div>
				  <div class="carousel-inner">
				    <div class="carousel-item active" data-bs-interval="5000">
				      <button type="button" class="btn" style="background-color: transparent; border: none;" onclick="location.href='main.jsp'">
				      <img src="./base/base_ma.jpg" class="d-block w-100 img-fluid" alt="..."></button>
				    </div>
				    <div class="carousel-item" data-bs-interval="5000">
				      <button type="button" class="btn" style="background-color: transparent; border: none;" onclick="location.href='main.jsp'">
				      <img src="./base/114.jpg" class="d-block w-100 img-fluid" alt="..."></button>
				    </div>
				    <div class="carousel-item" data-bs-interval="5000">
				      <button type="button" class="btn" style="background-color: transparent; border: none;" onclick="location.href='main.jsp'">
				      <img src="./base/113.jpg" class="d-block w-100 img-fluid" alt="..."></button>
				    </div>
				  </div>
				  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="prev">
				    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
				    <span class="visually-hidden">Previous</span>
				  </button>
				  <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleInterval" data-bs-slide="next">
				    <span class="carousel-control-next-icon" aria-hidden="true"></span>
				    <span class="visually-hidden">Next</span>
				  </button>
				</div>
				
				
			</div>
			<div class="col-md-1">
	            <!-- 빈 공간 -->
	            
	        </div>
	    </div>
	</div>
	<br>
	<!-- 본문칸 -->
	<div class="container">
	   	<div class="row align-items-start flex-row">
	   		<div class="col-md-1">
	           	<!-- 빈 공간 -->
	           
	       	</div>
	   		<div class="col-md-2 text-right" style=" border-radius: 8px; border: 1px solid #dddddd; padding: 3px; text-align: right; margin-right:1pt;">
	           	<!-- 브랜드 -->
	           	<nav class="nav nav-pills text-center" style="border-radius: 8px; border: 1px solid #0d6efd; padding: 3px; background-color: #0d6efd;">
	           	  <a style="color: white;">브랜드</a><br>
				</nav>
				<div class="brand-box ">
                <a href="bf.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">ButterFly</a>
            	</div>
            	<div class="brand-box">
                <a href="dhs.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">DHS</a>
            	</div>
            	<div class="brand-box">
                <a href="dn.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">Donic</a>
            	</div>
            	<div class="brand-box">
                <a href="ns.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">Nexy</a>
            	</div>
            	<div class="brand-box">
                <a href="st.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">STiga</a>
            	</div>
            	<div class="brand-box">
                <a href="tb.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">Tibhar</a>
            	</div>
            	<div class="brand-box">
                <a href="nt.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">Nittaku</a>
            	</div>
            	<%
				  if (USER_TYPE == 0) {
				%>
				    <nav class="nav nav-pills text-center" style="border-radius: 8px; border: 1px solid #0d6efd; padding: 3px; background-color: #0d6efd;">
				      <a style="color: white;">관리메뉴</a><br>
				    </nav>
				    <div class="brand-box">
				      <a href="userManage.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">회원 관리</a>
				    </div>
				    <div class="brand-box">
				      <a href="proManage.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">상품 관리</a>
				    </div>
				    <div class="brand-box">
				      <a href="mManage.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">매출 확인</a>
				    </div>
				    <div class="brand-box">
				      <a href="orderManage.jsp" class="brand-link" style="color: black; margin-right:5pt; text-decoration: none;">주문 관리</a>
				    </div>
				    <script>
				      document.getElementById("adminMenu").style.display = "block";
				    </script>
				<%
				  }
				%>
			</div>
	       	<div class="col-md-8" style="border: 1px solid #dddddd; padding: 3px; margin-left: 1pt;">
	       		<!-- 실 판매창 -->
	       		<%
	       		Bbs bbs = new Bbs();
	       		BbsDAO b = new BbsDAO();
	       		int pnum = Integer.parseInt(request.getParameter("pro_num"));
	       		bbs = b.getBbs(pnum);
	       		String fnum1 = String.format("%,d", bbs.getPrice());
	     		String fnum2 = String.format("%,d", bbs.getReal_price());
	       		%>

	       		<div class="container">
				  <div class="row">
				    <div class="col-6">
					  <img alt="사진 오류" src="./produc/<%=bbs.getP1() %>" width="100%" height="100%">
				    </div>
				    <div class="col-6">
				    <a><%=bbs.getPro_kind() %></a><br>
					  <a>브랜드 <%=bbs.getBrand() %></a><br>
					  <a style="float: right;"><h5><%=bbs.getPro_name() %>&nbsp&nbsp&nbsp&nbsp&nbsp</h5></a><br><br>
					  <a style="float: right;">정가 : <%=fnum1 %>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a><br>
					  <a style="float: right;">현재가&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a><br>
					  <a style="float: right;"><h5>\ <%=fnum2 %>&nbsp&nbsp&nbsp&nbsp&nbsp</h5></a><br><br>
					  <a>남은 수량</a>
					  <a style="float: right;"><%=bbs.getRemaining() %>개&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a><br>
					  <div class="row">
					  <div class="col-5">
					  <a style="float: left;">구매 수량</a><br>
					  </div>
	                  <div class="col-5">
					  <div><input type="number" class="form-control" aria-label="Sizing example input" oninput="validatePurchaseQuantity()" aria-describedby="inputGroup-sizing-sm" maxlength="2" min="1" max="<%=bbs.getRemaining() %>" value="1" id="number">
					  </div>
					  </div>
					  <div class="col-2">
					  <a>개</a></div>
					  <script>
    function validatePurchaseQuantity() {
        var purchaseQuantity = document.getElementById("number").value;
        var remainingQuantity = <%= bbs.getRemaining() %>;

        if (purchaseQuantity > remainingQuantity) {
            alert("남은 수량보다 큰 값을 입력할 수 없습니다.");
            document.getElementById("purchaseQuantity").value = remainingQuantity;
        }
    }
</script>
					  </div>
					  <hr>
					  <a>옵션</a>
<div class="input-group mb-3">
    <label class="input-group-text" for="inputGroupSelect01">분류</label>
    <select class="form-select" id="inputGroupSelect01" name="bbType" onchange="redirectToPage()">
        <option selected value="동종 상품 변경시 선택하세요">동종 상품 변경시 선택하세요</option>
        <%
            BbsDAO bb = new BbsDAO();
            ArrayList<Bbs> list = bb.getSame(bbs.getPro_num());
            for (int i = 0; i < list.size(); i++) {
                int pum = bb.getpnum(list.get(i).getPro_name());
        %>
            <option value="<%=pum %>"><%=list.get(i).getPro_name() %></option>
        <% } %>
    </select>
</div>

<!-- Hidden input 추가 -->
<input type="hidden" id="count" name="count" value="">

<!-- 스크립트를 head 태그 내로 이동 -->
<script>
    function redirectToPage() {
        // 선택된 옵션의 값 가져오기
        var selectedValue = document.getElementById("inputGroupSelect01").value;

        // Hidden input에 값을 설정
        var purchaseQuantity = ""; // 실제로 필요한 값을 할당하세요
        document.getElementById("count").value = purchaseQuantity;

        // 선택된 값이 '동종 상품 변경시 선택하세요'가 아닌 경우에만 이동
        if (selectedValue !== "동종 상품 변경시 선택하세요") {
            // 페이지 이동
            window.location.href = "product.jsp?pro_num=" + encodeURIComponent(selectedValue);
        }
    }
</script>
	                  <hr>
	                  <div class="row">
	                  <div class="col-6">
	                <form action="buyfast.jsp?pro_num=<%=bbs.getPro_num()%>" method="post">
				    <input type="hidden" name="count" value="1" id="count">
    				<input type="hidden" name="pr" value="<%= bbs.getReal_price() %>" id="price">
	                  <button type="submit" class="btn btn-outline-primary" style="width: 100%">구매하기</button>
					</from>
	                  </div>
	                  
	                  <div class="col-6">
	                  <a href="cartadd.jsp?pro_num=<%=bbs.getPro_num()%>" class="btn btn-outline-info" style="width: 100%">장바구니</a>
	                  </div>
	                  </div>
	                  </div>
	                  <br> &nbsp
	                  <div class="col-12">
	                  <nav class="nav nav-pills nav-fill" style="border: 1px solid #dddddd; padding: 10px; background-color: #0d6efd;">
					    <a class="nav-link" href="blade.jsp"  style="color: white;">평점</a>
					    <a class="nav-link" href="rub.jsp" style="color: white;">제품상세</a>
					    <a class="nav-link" href="ball.jsp" style="color: white;">주의사항</a>
					  </nav>
	                  </div>
	                  <br>&nbsp
	                  <div class="col-12">
	                  <h4>평점</h4><hr>
	                  <div class="col-6">
	                  <%
	                  CmnDAO cm = new CmnDAO();
	                  double vg = cm.rvg(bbs.getPro_num());
	                  %>
	                  <h4>평균평점 : <%=vg %></h4></div>
	                  
	                  
	                  <input type="hidden" name="bbsID" value="<%= ID %>">
			<table class="table table-striped" style="text-align: center; border: 1px solid #dddddd">
				<thead>	<!-- 테이블 헤드 -->
					<tr>	<!-- 한줄 -->
						<th colspan="8" style="background-color: #eeeeee; text-align: center;">리뷰</th>
					</tr>
				</thead>
				<tbody>
					<%
						CmnDAO cmnDAO = new CmnDAO();
						ArrayList<Cmn> listc = cmnDAO.getList(bbs.getPro_num());
						for(int i = 0; i < listc.size(); i++) {
					%>
					<tr>
						<td colspan="6" style="text-align: left;">&nbsp&nbsp&nbsp<%= listc.get(i).getComm() %></td>
						<td colspan="2" style="text-align: right;"><%= listc.get(i).getRpoint() %></td>
					 </tr>
					<%
						}
					%>
					<tr>
					</tr>
					</tbody>
					</table>
					
					
					</div>
	                  <hr>
	                  <h4>제품상세</h4><hr>
	                  <div class="col-12">
	                  <%=bbs.getEx() %><br>
	                  <img alt="사진 오류" src="./produc/<%=bbs.getP2() %>" width="100%">
	                  </div>
	                  
	                  <div class="col-12">
	                  <h4>주의사항</h4><hr>
	                  발송 후 24시간 후에 배송완료됩니다.<br>
	                  교환 환불은 어떻게든 될겁니다.
	                  </div>
				  </div>
				</div>
	       		<br>
	       		<br>
	       		
				
			</div>

			<div class="col-md-1">
	           	<!-- 빈 공간 -->
	           
	       	</div>
	   	</div>
	   	<div class="row align-items-center flex-row">
	   		<div class="col-md-1">
	           <!-- 빈 공간 -->
	       	</div>
	       	<br><br>
	       	
	       	
	   	</div>
	   	<br><br>
	</div>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>