<!DOCTYPE html>
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}"
  xmlns:th="https://www.thymeleaf.org">

<head>
  <th:block th:insert="~{fragments/common :: head(title=#{pdfToImage.title}, header=#{pdfToImage.header})}"></th:block>
  <script th:inline="javascript">
    document.addEventListener("DOMContentLoaded", function () {
      const maxDPI = /*[[${maxDPI}]]*/ 500; // Maximum DPI for PDF to image conversion
      const maxDPILabelRaw = /*[[#{pdfToImage.dpi}]]*/ "DPI (The server limit is {0} dpi)";
      const maxDPILabel = maxDPILabelRaw.replace("{0}", maxDPI); // Replace with actual value from properties
      const dpilabel = document.querySelector('label[for="dpi"]');
      if (dpilabel) {
        dpilabel.textContent = maxDPILabel;
      }
      const maxDPIInput = document.getElementById("dpi");
      if (maxDPIInput) {
        maxDPIInput.setAttribute("max", maxDPI); // Set the maximum value for DPI input
      }
    });
  </script>
</head>

<body>
  <th:block th:insert="~{fragments/common :: game}"></th:block>
  <div id="page-container">
    <div id="content-wrap">
      <th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
      <br><br>
      <div class="container">
        <div class="row justify-content-center">
          <div class="col-md-6 bg-card">
            <div class="tool-header">
              <span class="material-symbols-rounded tool-header-icon convert">photo_library</span>
              <span class="tool-header-text" th:text="#{pdfToImage.header}"></span>
            </div>
            <p th:text="#{processTimeWarning}"></p>
            <p th:if="${!isPython}" th:text="#{pdfToImage.info}">Python is not installed. Required for WebP conversion.
            </p>
            <form method="post" enctype="multipart/form-data" th:action="@{'/api/v1/convert/pdf/img'}">
              <div
                th:replace="~{fragments/common :: fileSelector(name='fileInput', multipleInputsForSingleRequest=false, accept='application/pdf')}">
              </div>
              <div class="mb-3">
                <label th:text="#{pdfToImage.selectText}"></label>
                <select class="form-control" name="imageFormat">
                  <option value="png">PNG</option>
                  <option value="jpg">JPG</option>
                  <option value="gif">GIF</option>
                  <option value="tiff">TIFF</option>
                  <option value="bmp">BMP</option>
                  <option th:if="${isPython}" value="webp">WEBP</option>
                </select>
              </div>
              <div class="mb-3">
                <label th:text="#{pdfToImage.singleOrMultiple}"></label>
                <select class="form-control" name="singleOrMultiple">
                  <option value="multiple" th:text="#{pdfToImage.multi}"></option>
                  <option value="single" th:text="#{pdfToImage.single}"></option>
                </select>
              </div>

              <div class="mb-3" id="singleOptionSection">
                <label for="pageNumbers" th:text="#{pageSelectionPrompt}"></label>
                <input type="text" name="pageNumbers" class="form-control" id="pageNumbers" value="all"
                  th:placeholder="#{pdfToImage.placeholder}" required>
              </div>
              <div class="mb-3">
                <label th:text="#{pdfToImage.colorType}"></label>
                <select class="form-control" name="colorType">
                  <option value="color" th:text="#{pdfToImage.color}"></option>
                  <option value="greyscale" th:text="#{pdfToImage.grey}"></option>
                  <option value="blackwhite" th:text="#{pdfToImage.blackwhite}"></option>
                </select>
              </div>
              <div class="form-check mb-3">
                <input id="includeAnnotations" name="includeAnnotations" type="checkbox">
                <label for="includeAnnotations" th:text="#{pdfToImage.includeAnnotations}"></label>
              </div>
              <div class="mb-3">
                <label for="dpi">DPI:</label>
                <input type="number" name="dpi" class="form-control" id="dpi" min="1" step="1" value="300" required>
              </div>
              <button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{pdfToImage.submit}"></button>
            </form>
          </div>
        </div>
      </div>
    </div>
    <th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
  </div>

</body>

</html>