<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>Añadir registro | Weight Tracker</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link th:href="@{/vendor/fontawesome-free/css/all.min.css}" rel="stylesheet">
  <link th:href="@{/css/sb-admin-2.min.css}" rel="stylesheet">
  <link rel="icon" href="data:,">

  <!-- Flatpickr CSS -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/plugins/confirmDate/confirmDate.css">
</head>

<body id="page-top">
  <div id="wrapper">
    <div th:replace="~{fragments/fragment-menu :: menu}"></div>

    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content" class="p-4">

        <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
          <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
            <i class="fa fa-bars"></i>
          </button>
          <h1 class="h4 mb-0 text-gray-800">Añadir registro</h1>
        </nav>

        <form th:action="@{/registros/guardar}" th:object="${registro}" method="post" class="row g-3">
          <input type="hidden" th:field="*{id}" />

          <div class="col-12 col-md-6">
            <label class="form-label">Fecha y hora</label>
            <input type="datetime-local" th:field="*{date}" class="form-control" required />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">Peso (kg)</label>
            <input type="number" step="0.1" th:field="*{weight}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">% Grasa corporal</label>
            <input type="number" step="0.1" th:field="*{bodyFat}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">% Agua</label>
            <input type="number" step="0.1" th:field="*{waterPercent}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">Masa muscular (kg)</label>
            <input type="number" step="0.1" th:field="*{muscleMass}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">Edad metabólica</label>
            <input type="number" th:field="*{metabolicAge}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">Grasa visceral</label>
            <input type="number" th:field="*{visceralFat}" class="form-control" />
          </div>

          <div class="col-12 col-md-6">
            <label class="form-label">IMC (BMI)</label>
            <input type="number" step="0.1" th:field="*{bmi}" class="form-control" />
          </div>

          <div class="col-12">
            <label class="form-label">Notas</label>
            <textarea th:field="*{notes}" class="form-control" rows="3" placeholder="Observaciones opcionales..."></textarea>
          </div>

          <div class="col-12">
            <button type="submit" class="btn btn-primary mt-3">Guardar</button>
          </div>
        </form>

      </div>
    </div>
  </div>

  <!-- Flatpickr scripts -->
  <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
  <script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/plugins/confirmDate/confirmDate.js"></script>
  <script>
    flatpickr("input[type=datetime-local]", {
      enableTime: true,
      time_24hr: true,
      dateFormat: "Y-m-d\\TH:i",
      plugins: [new confirmDatePlugin({
        confirmText: "OK",
        showAlways: false,
        theme: "light",
        confirmIcon: "",
        showNow: true,
        nowText: "Ahora"
      })]
    });
  </script>

  <script th:src="@{/vendor/jquery/jquery.min.js}"></script>
  <script th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>
  <script th:src="@{/js/sb-admin-2.min.js}"></script>
</body>
</html>
