<!doctype html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="result">
  <div class="alert alert-danger" th:if="${errorMessage}" th:text="${errorMessage}">Reasoning 실행에 실패했습니다.</div>
  <div th:if="${result}">
  <div class="section-heading">
    <h2>Reasoning 결과</h2>
    <span class="badge"
          th:classappend="${result.modelStatus() == 'SUCCESS'} ? ' text-bg-success' : ' text-bg-warning'"
          th:text="${result.modelStatus()}">SUCCESS</span>
  </div>

  <div class="meta-row">
    <span>Tool: <code th:text="${result.toolName()}">tool</code></span>
    <span>ORDS Status: <strong th:text="${result.probeResult().status()}">SUCCESS</strong></span>
    <span>Rows: <strong th:text="${result.probeResult().rowCount()}">0</strong></span>
    <span th:if="${!#lists.isEmpty(result.probeResult().maskedColumns())}">
      Masked: <code th:text="${#strings.listJoin(result.probeResult().maskedColumns(), ', ')}"></code>
    </span>
  </div>

  <section class="ai-answer">
    <h3>요약 및 판단</h3>
    <div class="markdown-view" data-markdown-view th:text="${result.answer()}">answer</div>
  </section>

  <div class="probe-exchange-grid">
    <section class="probe-exchange">
      <h3>Prompt</h3>
      <pre th:text="${result.prompt()}">prompt</pre>
    </section>
    <section class="probe-exchange">
      <h3>Tool Evidence JSON</h3>
      <pre th:text="${result.evidenceJson()}">{}</pre>
    </section>
  </div>

  <div class="probe-exchange-grid">
    <section class="probe-exchange">
      <h3>Request Headers</h3>
      <pre th:text="${result.probeResult().requestHeaders()} ?: '{}'">{}</pre>
    </section>
    <section class="probe-exchange">
      <h3>Response Body</h3>
      <pre th:text="${result.probeResult().responseBody()} ?: ''"></pre>
    </section>
  </div>

  <div class="table-responsive" th:if="${!#lists.isEmpty(result.probeResult().rows())}">
    <table class="table table-sm table-striped align-middle">
      <thead>
      <tr>
        <th th:each="column : ${result.probeResult().columns()}" th:text="${column}">column</th>
      </tr>
      </thead>
      <tbody>
      <tr th:each="row : ${result.probeResult().rows()}">
        <td th:each="column : ${result.probeResult().columns()}" th:text="${row.get(column)}">value</td>
      </tr>
      </tbody>
    </table>
  </div>
  </div>
</div>
</body>
</html>
