<div th:fragment="result">
  <div class="alert alert-danger" th:if="${errorMessage}" th:text="${errorMessage}"></div>
  <div th:if="${searchResult}">
    <div class="result-metrics">
      <div><span>임베딩</span><strong th:text="${searchResult.embeddingModel()}">로컬 임베딩(개발용)</strong></div>
      <div><span>검색 결과</span><strong th:text="${#lists.size(searchResult.rows()) + '건'}">0건</strong></div>
      <div><span>END USER</span><strong th:text="${searchResult.endUser() ?: searchResult.userLabel()}">-</strong></div>
    </div>
    <div class="next-action-card mt-3" th:classappend="${searchResult.success()} ? '' : ' border-warning'">
      <h3 th:text="${searchResult.title()}">권한 결과</h3>
      <p th:text="${searchResult.message()}">결과 요약</p>
      <small th:text="${'질문: ' + searchResult.query() + ' · 객체: ' + searchResult.objectName()}">검색 정보</small>
      <small class="d-block" th:if="${searchResult.oracleCode() != null}"
             th:text="${'Oracle code: ' + searchResult.oracleCode()}">Oracle code</small>
    </div>
    <div class="table-responsive mt-3" th:if="${searchResult.success() and searchResult.hasRows()}">
      <table class="table table-sm align-middle">
        <thead><tr><th>검색 단위</th><th>자료 ID</th><th>제목</th><th>업무 분류값</th><th>관련도</th><th>본문</th></tr></thead>
        <tbody>
        <tr th:each="row : ${searchResult.rows()}">
          <td th:text="${row['CHUNK_ID']}">28001</td>
          <td th:text="${row['DOCUMENT_ID']}">knowledge-001</td>
          <td th:text="${row['TITLE']}">제목</td>
          <td><code th:text="${row['TECH_TAG']}">ORDS</code></td>
          <td th:text="${row['SCORE']}">0.01</td>
          <td class="matrix-list" th:text="${row['CHUNK_TEXT']}">본문</td>
        </tr>
        </tbody>
      </table>
    </div>
    <div class="empty-result-guide" th:if="${searchResult.success() and !searchResult.hasRows()}">DATA GRANT를 통과한 검색 단위가 없습니다.</div>
    <details class="technical-details mt-3">
      <summary>기술 정보 보기</summary>
      <p class="mb-0">SESSION_USER: <code th:text="${searchResult.sessionUser() ?: '-'}">-</code> · ORA_END_USER_CONTEXT: <code th:text="${searchResult.endUser() ?: '-'}">-</code></p>
    </details>
    <section class="registration-result mt-3" th:if="${searchResult.sqlEvidence() != null}" aria-label="실행 근거">
      <div><strong>실행 근거</strong><span th:text="${searchResult.sqlEvidence().status()}">실행 근거</span></div>
      <dl th:if="${searchResult.sqlEvidence().available()}">
        <div><dt>SQL ID</dt><dd><code th:text="${searchResult.sqlEvidence().sqlId()}">sql id</code></dd></div>
        <div><dt>실행 시각</dt><dd th:text="${searchResult.sqlEvidence().lastActiveTime()}">time</dd></div>
        <div><dt>실행 횟수</dt><dd th:text="${searchResult.sqlEvidence().executions()}">0</dd></div>
      </dl>
      <details class="technical-details mt-2"><summary>실행 조건 보기</summary>
        <p><strong>실행 SQL</strong><br><code th:text="${searchResult.sqlEvidence().executedSql()}">statement</code></p>
        <p th:if="${searchResult.sqlEvidence().planPredicate()}">계획 predicate: <code th:text="${searchResult.sqlEvidence().planPredicate()}">predicate</code></p>
        <p class="mb-0" th:if="${searchResult.sqlEvidence().vpdPredicate()}">VPD predicate: <code th:text="${searchResult.sqlEvidence().vpdPredicate()}">predicate</code></p>
      </details>
    </section>
  </div>
</div>
