<%@page import="bbs.Bbs"%>
<%@page import="java.util.ArrayList"%>
<%@page import="bbs.BbsDAO"%>
<%@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 ss = request.getParameter("ss");	
	
		String ID = null;
		if (session.getAttribute("ID") != null) {
			ID = (String) session.getAttribute("ID");
		}
		int pageNumber = 1;
		if (request.getParameter("pageNumber") != null) {
			pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
		}
		
		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 action="Search.jsp" method="post" class="d-flex">
      				<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name="ss">
      				<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='product.jsp?pro_num=7'">
				      <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='product.jsp?pro_num=2'">
				      <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='product.jsp?pro_num=8'">
				      <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;">
	       		<!-- 실 판매창 -->
	       		<div class="container">
				  <div class="row">
	       		<%
	       		BbsDAO bbsDAO = new BbsDAO();
						ArrayList<Bbs> list= bbsDAO.getsList(ss);
						for(int i = 0; i < list.size(); i++) {
				%>
	       		
				    <div class="col-3">
					  <div class="card" style="width: 100%; height: 100%;">
					    <a href="product.jsp?pro_num=<%=list.get(i).getPro_num()%>"><img src="./produc/<%= list.get(i).getP1()%>" class="card-img-top" alt="<%= list.get(i).getP1()%>"></a>
					    <div class="card-body">
					      <a><h5 style="font-size: 0.9em; font-weight: bold;"><%= list.get(i).getBrand()%></h5></a>
					      <a style="text-decoration: none; color: black;" href="product.jsp?pro_num=<%=list.get(i).getPro_num()%>"><h5 class="card-title"><%= list.get(i).getPro_name()%></h5></a>
					     	<%
					     		String fnum1 = String.format("%,d", list.get(i).getPrice());
					     		String fnum2 = String.format("%,d", list.get(i).getReal_price());
					     	%>
					      <a style="text-decoration: none; color: black;" href="product.jsp?pro_num=<%=list.get(i).getPro_num()%>"><h5 style="font-size: 0.8em;">정가 : <%=fnum1 %></h5></a>
					      <a style="text-decoration: none; color: black;" href="product.jsp?pro_num=<%=list.get(i).getPro_num()%>"><h5><%=fnum2 %>원</h5></a>
					    </div>
					  </div>
					</div>
					<%} %>
				    
				    
				  </div>
				</div>
	       		<br>
	       		<br>
	       		<!-- 넘버링 -->
				<%
    int recordsPerPage = 10; // 한 페이지당 표시할 레코드 수
    int totalRecords = bbsDAO.getTotalRecords(); // 전체 레코드 수 (전체 게시물 수)

    int totalPages = (int) Math.ceil((double) totalRecords / recordsPerPage); // 전체 페이지 수
    int currentPage = pageNumber; // 현재 페이지 번호
    int pageStart = currentPage - (currentPage - 1) % 10; // 현재 페이지가 속한 페이지 그룹의 시작 페이지 번호
    int pageEnd = Math.min(pageStart + 9, totalPages); // 현재 페이지가 속한 페이지 그룹의 끝 페이지 번호

    // '이전' 링크
    if (pageStart > 1) {
%>
				
	<nav aria-label="Page navigation example">
	<ul class="pagination justify-content-center">
        <li class="page-item">
            <a class="page-link" href="main.jsp?pageNumber=<%= pageStart - 1 %>">이전</a>
        </li>
<%
    } else {
%>
	<nav aria-label="Page navigation example">
	<ul class="pagination justify-content-center">
        <li class="page-item disabled">
            <a class="page-link">이전</a>
        </li>
<%
    }

    // 페이지 번호 링크
    for (int i = pageStart; i <= pageEnd; i++) {
%>
        <li class="page-item">
            <a class="page-link <% if (i == currentPage) {%> active <%} %>" href="main.jsp?pageNumber=<%= i %>"><%= i %></a>
        </li>
<%
    }

    // '다음' 링크
    if (pageEnd < totalPages) {
%>
        <li class="page-item">
            <a class="page-link" href="main.jsp?pageNumber=<%= pageEnd + 1 %>">다음</a>
        </li>
        </ul>
				</nav>
<%
    } else {
%>
        <li class="page-item disabled">
            <a class="page-link">다음</a>
        </li>
        </ul>
				</nav>
<%
    }
%>
				
			</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>
	<br><br><br>
	<hr>
	<div class="container">
	   	<div class="row">
	   	<div class="col-2">
	   	</div>
	   	
	   	<div class="col-8">
	   	<div class="row">
	   	<div class="col-4">
	   	<h5 style="font-size: 0.8em;">상호명 및 호스팅 서비스 제공 : TKmall(주)</h5>
		<h5 style="font-size: 0.8em;">대표이사 : 없음</h5>
		<h5 style="font-size: 0.8em;">서울시 중구 광화문로 007</h5>
		<h5 style="font-size: 0.8em;">사업자 등록번호 : 120-01-12345</h5>
		<h5 style="font-size: 0.8em;">통신판매업신고 : 2023-서울중부-0001</h5>
		<h5 style="font-size: 0.8em;">사업자정보 확인 > 불가능</h5>
	   	</div>
	   	<div class="col-4">
	   	<h5 style="font-size: 0.8em;">365고객센터 | 전자금융거래분쟁처리담당</h5>
		<h5>1577-7011 (통화불가)</h5>
		<h5 style="font-size: 0.8em;">서울시 중구 광화문로 007</h5>
		<h5 style="font-size: 0.8em;">email : help@isnotdomain.com</h5>
	   	</div>
	   	<div class="col-4">
	   	<h5>가짜은행 채무지급보증 안내</h5>
		<h5 style="font-size: 0.8em;">당사는 고객님이 현금 결제한 금액에 대해</h5>
		<h5 style="font-size: 0.8em;">없는 은행과 채무지급보증 계약을 체결하여</h5>
		<h5 style="font-size: 0.8em;">안전거래를 보장하지 않고 있습니다.</h5>
		<h5 style="font-size: 0.8em;">서비스 가입사실 확인 > 불가능</h5>
	   	</div>
	   	</div>
	   	</div>
	   	
	   	<div class="col-2">
	   	</div>
	</div>
	</div>
	<br>&nbsp
	
	<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>

	