<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<link rel="stylesheet" href="<c:url value="/xit/xit-db-exec.css"/>" />

<!-- Main body -->
<div class="main_body">
    <section id="section8" class="main_bars">
        <div class="bgs-main">
            <section id="section5">
                <div class="sub_title"></div>

                <div class="db-query-container">
                    <div class="db-card query-card">
                        <div class="db-card-header">
                            <h3>쿼리 작성</h3>
                        </div>
                        <div class="db-card-body">
                            <div class="transaction-controls">
                                <span id="transactionStatus" class="transaction-status">트랜잭션: 없음</span>
                                <div class="transaction-buttons">
                                    <button id="commitButton" class="db-btn db-btn-success" disabled>커밋</button>
                                    <button id="rollbackButton" class="db-btn db-btn-danger" disabled>롤백</button>
                                </div>
                            </div>

                            <div class="query-form">
                                <div class="query-type-container" style="display: none;">
                                    <label for="queryType">쿼리 유형:</label>
                                    <select id="queryType" class="db-select">
                                        <option value="SELECT">SELECT</option>
                                        <option value="INSERT">INSERT</option>
                                        <option value="UPDATE">UPDATE</option>
                                        <option value="DELETE">DELETE</option>
                                    </select>
                                </div>

                                <!-- 자동 감지된 쿼리 타입 표시 영역 -->
                                <div class="detected-query-type-container">
                                    <label>감지된 쿼리 유형:</label>
                                    <span id="detectedQueryType" class="detected-query-type">-</span>
                                </div>

                                <div class="query-input-container">
                                    <textarea id="queryInput" class="db-textarea" placeholder="SQL 쿼리를 입력하세요..."></textarea>
                                </div>

                                <div class="query-button-container">
                                    <button id="executeButton" class="db-btn db-btn-primary">실행</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="db-card results-card">
                        <div class="db-card-header">
                            <h3>쿼리 결과</h3>
                        </div>
                        <div class="db-card-body">
                            <div class="db-results-container">
                                <div class="db-results-section">
                                    <h4>실행 결과</h4>
                                    <div id="resultInfo" class="result-info"></div>
                                    <div id="resultTable" class="result-table-container"></div>
                                </div>

                                <div class="db-results-section">
                                    <h4>쿼리 이력</h4>
                                    <div id="queryHistory" class="query-history-list"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <script>
                const queryExecUrl = '<c:url value="/db/exec/queryexec.do"/>';
                </script>
                <script src="<c:url value="/xit/xit-db-exec.js"/>" charset="UTF-8"></script>
            </section>
        </div>
    </section>
</div>
<!-- /Main body -->
