<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Trader Assort</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
      .price-box {
        display: flex;
        align-items: center;
        flex-direction: column;
        background-color: #f8f9fa;
        padding: 5px;
        border-radius: 5px;
        margin-bottom: 15px;
      }

      .price-box img {
        width: 30px;
        margin-right: 10px;
      }

      .price-box span {
        font-size: 1.2em;
        font-weight: bold;
      }

      .price-box small {
        font-size: 0.8em;
        color: #888;
      }

      .card {
        margin-bottom: 15px;
      }

      .card-header img {
        width: 45px;
        margin-right: 10px;
      }

      .barter-list {
        list-style-type: none;
        padding-left: 0;
        display: flex;
        flex-direction: row;
      }

      .barter-list li {
        display: flex;
        align-items: center;
      }

      .barter-list li img {
        width: 45px;
        margin-right: 10px;
      }

      .parts-tree {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
      }

      .parts-tree>li {
        margin-right: 10px;
      }

      .part-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        background-color: #f8f9fa;
        padding: 5px;
        border-radius: 5px;
        margin-bottom: 5px;
      }

      .part-item img {
        width: 30px;
        margin-right: 5px;
      }

      .card-body {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
      }

      .barter-section {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
      }

      .left-section {
        display: flex;
        flex-direction: column;
      }

    </style>
  </head>
  <body>
    <div class="container">
      <h1>Trader Assort</h1>
      <div class="list-group"> {% for item in items %} <div class="card">
          <div class="card-header d-flex align-items-center">
            <img src="{{ item.details.image512pxLink }}" alt="{{ item.details.name }}">
            <strong>{{ item.details.name }}</strong>
            <div class="ml-2 text-muted">{{ item.offer_name }}</div>
            <!-- Add offer name here -->
            <div class="price-box ml-auto">
              <div>
                <img src="{{ ruble_image.image512pxLink }}" alt="RUB">
                <span>{{ item.details.basePrice }} RUB</span>
              </div>
              <small>Base Price (for reference)</small>
            </div>
          </div>
          <div class="card-body">
            <div class="barter-section">
              <div class="left-section">
                {% if item.barter_scheme|length > 0 %}
                  <div>
                    <strong>Barter Requirements:</strong>
                  </div>
                  <ul class="barter-list"> {% for scheme in item.barter_scheme %} {% for req in scheme %} <li>
                      <span>{{ req.count }} ×</span>
                      <img src="{{ req.details.image512pxLink }}" alt="{{ req.details.name }}">
                    </li> {% endfor %} {% endfor %} </ul>
                {% endif %}
                {% if item.quest_requirement %}
                  <p>
                    <strong>Quest Requirement:</strong>
                    {{ item.quest_requirement.quest }} {% if item.quest_requirement.type == 'success' %} <i class="fas fa-check-circle text-success"></i> {% elif item.quest_requirement.type == 'fail' %} <i class="fas fa-times-circle text-danger"></i> {% elif item.quest_requirement.type == 'started' %} <i class="fas fa-question-circle text-primary"></i> {% endif %}
                  </p> 
                {% endif %}
              </div>
              <a href="{{ url_for('edit_item', item_id=item._id) }}" class="btn btn-primary btn-sm">Edit</a>
            </div>
            {% if item.parts|length > 0 %}
              <h2>
                <button class="btn btn-outline-primary" type="button" data-toggle="collapse" data-target="#parts-{{ item._id }}" aria-expanded="false" aria-controls="parts-{{ item._id }}"> Parts </button>
              </h2>
              <div>
                <div id="parts-{{ item._id }}" class="collapse">
                  <ul class="parts-tree"> {% include 'parts.html' with context %} </ul>
                </div>
              </div> 
            {% endif %}
          </div>
        </div> {% endfor %} 
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  </body>
</html>
