<%@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(USER_TYPE != 0) { %>
	     	PrintWriter script = response.getWriter();
			script.println("<script>");
			script.println("alert('올바르지 못한 접근.')");
			script.println("location.href = 'main.jsp'");
			script.println("</script>");
	     <%} 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>
			<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;">
	       		<!-- 글쓰기 창 -->
	       		<h4>&nbsp상품 수정</h4>
	       		<hr>
	       		<%
	       		Bbs bbs = new Bbs();
	       		BbsDAO b = new BbsDAO();
	       		int pnum = Integer.parseInt(request.getParameter("pro_num"));
	       		bbs = b.getBbs(pnum);
	       		%>
	       		<div class="container">
  				<div class="row">
  				<div class="col-12">
			      
			      <form action="updateAction.jsp?pnum=<%=pnum %>" method="post">
				  <div class="input-group mb-3">
				    <span class="input-group-text" id="basic-addon1">상품명</span>
				    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="proname" value="<%=bbs.getPro_name() %>">
				  </div>
				  <div class="input-group mb-3">
				    <span class="input-group-text" id="basic-addon1">분류</span>
				    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="kind" value="<%=bbs.getPro_kind() %>">
				  </div>
				  <div class="input-group mb-3">
				    <span class="input-group-text" id="basic-addon1">브랜드</span>
				    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="brand" value="<%=bbs.getBrand() %>">
				  </div>
				  <div class="input-group mb-3">
    <span class="input-group-text" id="basic-addon1">가격</span>
    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="price" value="<%=bbs.getPrice() %>">
</div>
<div class="input-group mb-3">
    <span class="input-group-text" id="basic-addon1">판매가격</span>
    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="rprice" value="<%=bbs.getReal_price() %>">
</div>
				  
				  <div class="input-group mb-3">
    <label class="input-group-text" for="inputGroupSelect01">분류</label>
    <select class="form-select" id="inputGroupSelect01" name="sType" onchange="toggleInput()">
    	<option selected>선택하세요</option>
        <option>직접 작성</option>
        <%
        BbsDAO bb = new BbsDAO();
		ArrayList<Bbs> list= bb.getType(); 
    		for(int i = 0; i < list.size(); i++) {
		%>
        <option value="<%=list.get(i).getPro_same() %>"><%=list.get(i).getPro_same() %></option>
        <%} %>
    </select>
</div>
<div class="input-group mb-3">
    <input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="basic-addon1" name="type" id="customInput" style="display:none;">
</div>

<script>
    function toggleInput() {
        var select = document.getElementById("inputGroupSelect01");
        var customInput = document.getElementById("customInput");

        if (select.value === "직접 작성") {
            customInput.style.display = "block";
            customInput.readOnly = false;
        } else {
            // 선택된 값을 가져와서 텍스트 입력 필드에 설정
            customInput.value = select.value;
            customInput.style.display = "none";
            customInput.readOnly = true;
        }
    }
</script>
 
                    
				  <div class="input-group mb-3">
				    <span class="input-group-text" id="basic-addon1">설명</span>
				    <textarea id="editor" class="form-control" rows="10" name="ex" ><%=bbs.getEx() %></textarea>
				  </div>
					<br>
					<input type="submit" class="btn btn-primary form-control"
						value="수정하기">
				</form>
			      
				</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>
	       	
	   	</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>

 