<!DOCTYPE html>

<html lang="fr">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

  <title>Retrait Colis - Pavé tactile</title>

  <style>

    * {

      box-sizing: border-box;

      margin: 0;

      padding: 0;

      user-select: none;

      -webkit-user-select: none;

      -webkit-touch-callout: none;

    }


    body {

      background-color: #0b0c10;

      color: #ffffff;

      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

      display: flex;

      flex-direction: column;

      align-items: center;

      justify-content: center;

      min-height: 100vh;

      padding: 24px 16px;

      overflow: hidden;

    }


    .container {

      width: 100%;

      max-width: 360px;

      display: flex;

      flex-direction: column;

      align-items: center;

      gap: 20px;

    }


    /* En-tête */

    .header {

      text-align: center;

    }


    .title {

      font-size: 32px;

      font-weight: 800;

      line-height: 1.15;

      letter-spacing: -0.5px;

      margin-bottom: 14px;

    }


    .subtitle {

      font-size: 16px;

      color: #9aa0a6;

      line-height: 1.35;

      max-width: 280px;

      margin: 0 auto;

    }


    /* Zone d'affichage du code */

    .code-display {

      background-color: #171a21;

      border: 1px solid #232733;

      border-radius: 16px;

      width: 100%;

      height: 72px;

      display: flex;

      align-items: center;

      justify-content: center;

      gap: 16px;

      margin: 8px 0 12px 0;

    }


    .slot {

      font-size: 28px;

      font-weight: 700;

      color: #ffffff;

      width: 24px;

      text-align: center;

      border-bottom: 3px solid #5a6275;

      height: 38px;

      display: flex;

      align-items: center;

      justify-content: center;

      transition: all 0.15s ease;

    }


    .slot.filled {

      border-bottom-color: #ffffff;

    }


    .slot.active {

      border-bottom-color: #4c8bf5;

    }


    /* Clavier 3x4 */

    .keypad {

      display: grid;

      grid-template-columns: repeat(3, 1fr);

      gap: 16px;

      width: 100%;

      justify-items: center;

    }


    .key {

      width: 82px;

      height: 82px;

      border-radius: 50%;

      background-color: #1f242d;

      border: none;

      color: #ffffff;

      font-size: 34px;

      font-weight: 600;

      cursor: pointer;

      display: flex;

      flex-direction: column;

      align-items: center;

      justify-content: center;

      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);

      transition: transform 0.08s ease, background-color 0.1s ease;

      touch-action: manipulation;

    }


    .key:active {

      transform: scale(0.92);

      background-color: #333a48;

    }


    /* Boutons spéciaux */

    .key.action-key {

      font-size: 13px;

      font-weight: 600;

      gap: 3px;

    }


    .key.action-key svg {

      width: 22px;

      height: 22px;

      fill: none;

      stroke: currentColor;

      stroke-width: 2;

    }


    .key.validate-key {

      background-color: #1e2638;

      border: 1px solid #2d3b59;

    }


    .key.validate-key:active {

      background-color: #2e4372;

    }


    .key.validate-key.ready {

      background-color: #1a56db;

      border-color: #3b82f6;

    }


    .sub-label {

      font-size: 11px;

      color: #8f98a8;

      margin-top: -2px;

    }

  </style>

</head>

<body>


  <div class="container">

    <div class="header">

      <h1 class="title">Récupérez<br>votre colis</h1>

      <p class="subtitle">Saisissez votre code à 6 chiffres reçu par email</p>

    </div>


    <!-- Affichage des 6 tirets / chiffres -->

    <div class="code-display" id="display">

      <div class="slot active" id="s0"></div>

      <div class="slot" id="s1"></div>

      <div class="slot" id="s2"></div>

      <div class="slot" id="s3"></div>

      <div class="slot" id="s4"></div>

      <div class="slot" id="s5"></div>

    </div>


    <!-- Clavier numérique rond -->

    <div class="keypad">

      <button class="key" onclick="pressDigit('1')">1</button>

      <button class="key" onclick="pressDigit('2')">2</button>

      <button class="key" onclick="pressDigit('3')">3</button>


      <button class="key" onclick="pressDigit('4')">4</button>

      <button class="key" onclick="pressDigit('5')">5</button>

      <button class="key" onclick="pressDigit('6')">6</button>


      <button class="key" onclick="pressDigit('7')">7</button>

      <button class="key" onclick="pressDigit('8')">8</button>

      <button class="key" onclick="pressDigit('9')">9</button>


      <!-- Effacer -->

      <button class="key action-key" onclick="clearCode()">

        <span>Effacer</span>

        <svg viewBox="0 0 24 24">

          <path d="M21 4H8l-7 8 7 8h13a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"></path>

          <line x1="18" y1="9" x2="12" y2="15"></line>

          <line x1="12" y1="9" x2="18" y2="15"></line>

        </svg>

      </button>


      <button class="key" onclick="pressDigit('0')">0</button>


      <!-- Valider -->

      <button class="key action-key validate-key" id="btnValidate" onclick="submitCode()">

        <span>Valider</span>

        <svg viewBox="0 0 24 24">

          <polyline points="20 6 9 17 4 12"></polyline>

        </svg>

        <span class="sub-label">Entrée</span>

      </button>

    </div>

  </div>


  <script>

    let code = "";

    const MAX_DIGITS = 6;


    function updateSlots() {

      for (let i = 0; i < MAX_DIGITS; i++) {

        const slot = document.getElementById("s" + i);

        if (i < code.length) {

          slot.innerText = code[i];

          slot.className = "slot filled";

        } else if (i === code.length) {

          slot.innerText = "";

          slot.className = "slot active";

        } else {

          slot.innerText = "";

          slot.className = "slot";

        }

      }


      const btn = document.getElementById("btnValidate");

      if (code.length === MAX_DIGITS) {

        btn.classList.add("ready");

      } else {

        btn.classList.remove("ready");

      }

    }


    function pressDigit(d) {

      if (code.length < MAX_DIGITS) {

        code += d;

        if (navigator.vibrate) navigator.vibrate(25);

        updateSlots();

      }

    }


    function clearCode() {

      if (code.length > 0) {

        code = code.slice(0, -1);

        if (navigator.vibrate) navigator.vibrate(20);

        updateSlots();

      }

    }


    function submitCode() {

      if (code.length === MAX_DIGITS) {

        if (navigator.vibrate) navigator.vibrate([40, 50, 40]);

        

        // Communication avec la micro-app LumApps

        window.parent.postMessage({

          type: "lumapps_component_submit",

          inputs: { code: code }

        }, "*");

      }

    }


    // Support du clavier physique si branché à la borne

    document.addEventListener("keydown", (e) => {

      if (/^[0-9]$/.test(e.key)) pressDigit(e.key);

      else if (e.key === "Backspace") clearCode();

      else if (e.key === "Enter") submitCode();

    });

  </script>

</body>

</html>