<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Lobby</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css"
    />
    <style>
      html,
      body {
        height: 100%;
        margin: 0;
        padding: 0;
        background-color: lightgray;
      }

      /* Stil für den Kopfbereich */
      .header {
        background-color: #333;
        color: white;
        padding: 10px;
        text-align: center;
      }

      /* Stil für die Buttons im Kopfbereich */
      .header button {
        margin: 10px;
      }

      .container-fluid {
        background-color: lightgray;
      }
    </style>
  </head>

  <body>
    <!-- Kopfzeile mit Buttons -->
    <div class="header">
      <div class="row g-0 align-items-center">
        <div class="col-md-6">
          <h1
            class="text-center font-weight-bold border-bottom border-2 border-primary p-3 shadow rounded"
          >
            Gamelobby for {{game.name}}
          </h1>
        </div>
        <div class="col-md-6">
          {%if game.gamemaster == user.username%}

          <form
            class="m-2"
            action="{% url 'startGame' gameid=game.id username=user.username%}"
            method="post"
          >
            {% csrf_token %}

            <input
              class="btn btn-success col-md-12"
              type="submit"
              value="start game"
              id="startGame"
              name="action"
            />
          </form>
          {%else%}
          <form
            class="m-2"
            action="{% url 'gamerules' gameid=game.id%}"
            method="get"
          >
            {% csrf_token %}
            <input
              class="btn btn-primary col-md-12"
              type="submit"
              value="view gamerules"
              id="viewgamerules"
              name="action"
            />
          </form>
          {%endif%}
        </div>
      </div>
    </div>
    <div class="container-fluid overflow-y-auto">
      <div class="row">
        <div class="col">
          <h1
            class="col-md-6 bg-secondary-subtle text-center font-weight-bold border-bottom border-2 border-primary p-3 mt-3 shadow rounded"
          >
            Game ID: {{game.id}}
          </h1>
          <h1
            class="col-md-6 bg-secondary-subtle text-center font-weight-bold border-bottom border-2 border-primary p-3 mt-3 shadow rounded"
          >
            Gamemaster: {{game.gamemaster}}
          </h1>
          <ul class="list-group mb-3">
            <li class="list-group-item bg-secondary-subtle">
              <h1
                class="text-center bg-secondary-subtle font-weight-bold border-bottom border-2 border-primary p-3 mt-3 shadow rounded"
              >
                Joined Players:
              </h1>
            </li>
            {%for player in game.participants.all%}

            <li class="list-group-item bg-secondary-subtle fs-4">
              {{player.name}}
            </li>
            {% endfor %}
          </ul>
        </div>

        <div class="col">
          <h1
            class="text-center bg-secondary-subtle font-weight-bold border-bottom border-2 border-primary p-3 mt-3 shadow rounded"
          >
            Gamesettings:
          </h1>
          {%if game.gamemaster == user.username%}
          <form
            action="{% url 'lobby' gameid=game.id username=user.username%}"
            method="post"
          >
            {% csrf_token %}
            <ul class="list-group">
              <li class="list-group-item bg-secondary-subtle">
                Number of rounds: {{ gamesettingsform.rounds }}
              </li>
              <li class="list-group-item bg-secondary-subtle">
                Roundtimer: {{ gamesettingsform.timer }}
              </li>
              <li class="list-group-item bg-secondary-subtle">
                Ordermarket size: {{ gamesettingsform.ordermarketsize }}
              </li>
            </ul>
            <div class="d-grid gap-2 mt-2">
              <button
                class="btn btn-primary"
                type="submit"
                value="changesettings"
                id="changesettings"
                name="action"
              >
                save settings
              </button>
            </div>
          </form>
          {%else%}
          <ul class="list-group">
            <li class="list-group-item bg-secondary-subtle">
              Number of rounds: {{gamesettingsform.rounds.initial}}
            </li>
            <li class="list-group-item bg-secondary-subtle">
              Roundtimer: {{gamesettingsform.timer.initial}}
            </li>
            <li class="list-group-item bg-secondary-subtle">
              Ordermarket size: {{gamesettingsform.ordermarketsize.initial}}
            </li>
          </ul>
        </div>
        {%endif%}
      </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.min.js"></script>
  </body>
</html>
