<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{{ object.type }}</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" />
    <style>
      body {
        font-size: 0.875rem;
        background-color: #f8f9fa;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
      }
      .custom-container {
        background-color: #ffffff;
        border-radius: 10px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
        padding: 30px;
        margin-top: 30px;
        flex-grow: 1;
      }
      .section-title {
        color: #7a9f4f;
        border-bottom: 2px solid #9cc666;
        padding-bottom: 10px;
        margin-bottom: 20px;
        font-size: 1.5em;
      }
      .info-row {
        margin-bottom: 10px;
      }
      .info-label {
        font-weight: bold;
        color: #545f71;
      }
      .info-value {
        color: #333;
      }
      .component-card {
        background-color: #f8f9fa;
        border-left: 4px solid #9cc666;
        margin-bottom: 15px;
        transition: all 0.3s ease;
      }
      .component-card:hover {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        transform: translateY(-2px);
      }
      .hash-value {
        word-break: break-all;
        background-color: #f3f3f3;
        padding: 5px;
        border-radius: 4px;
        font-family: monospace;
        font-size: 0.9em;
        border: 1px solid #e0e0e0;
      }
      .card-title {
        color: #9cc666;
      }
      .btn-primary {
        background-color: #9cc666;
        border-color: #9cc666;
        padding: 0.1em 2em;
        font-weight: 700;
      }
      .btn-primary:hover {
        background-color: #8ab555;
        border-color: #8ab555;
      }
      .btn-green-user {
        background-color: #c7e3a3;
      }
      .btn-grey {
        background-color: #f3f3f3;
      }
      footer {
        background-color: #545f71;
        color: #ffffff;
        text-align: center;
        padding: 10px 0;
        margin-top: 20px;
      }
    </style>
  </head>
  <body>
    <div class="container custom-container">
      <nav class="header-nav ms-auto">
        <div class="d-flex align-items-right">
          <span class="nav-item">
              {% if not roles and user.is_anonymous %}
              <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#validateModal">Validate</button>
              {% else %}
              <button class="btn btn-primary" id="buttonRole" data-bs-toggle="modal" data-bs-target="#rolesModal">Select your role</button>
              <a class="btn btn-primary" href="{% url 'login:logout' %}?next={{ path }}">Logout</a>
              {% endif %}
          </span>
        </div>
        {% if role %}
        <div class="d-flex justify-content-end">
          <span class="nav-item">
          Current Role: {{ role }}
          </span>
        </div>
        {% endif %}
      </nav>

      <h1 class="text-center mb-4" style="color: #545f71;">{{ object.manufacturer }} {{ object.type }} {{ object.model }}</h1>

      <div class="row">
        <div class="col-lg-6">
          {% if manuals.details.logo %}
            <img style="max-width: 50px; margin-right: 15px;" src="{{ manuals.details.logo }}" />
          {% endif %}
	</div>
        <div class="col-lg-6">
          {% if manuals.details.image %}
            <img style="width: 100px;" src="{{ manuals.details.image }}" />
          {% endif %}
	</div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <h2 class="section-title">Details</h2>
          <div class="info-row row">
            <div class="col-md-4 info-label">Phid</div>
            <div class="col-md-8 info-value">
              <div class="hash-value">{{ object.id }}</div>
            </div>
          </div>
          <div class="info-row row">
            <div class="col-md-4 info-label">Type</div>
            <div class="col-md-8 info-value">{{ object.type }}</div>
          </div>

          {% if object.is_websnapshot %}
            {% for snapshot_key, snapshot_value in object.last_user_evidence %}
              <div class="info-row row">
                <div class="col-md-4 info-label">{{ snapshot_key }}</div>
                <div class="col-md-8 info-value">{{ snapshot_value|default:'' }}</div>
              </div>
            {% endfor %}
          {% else %}
            <div class="info-row row">
              <div class="col-md-4 info-label">Manufacturer</div>
              <div class="col-md-8 info-value">{{ object.manufacturer|default:'' }}</div>
            </div>
            <div class="info-row row">
              <div class="col-md-4 info-label">Model</div>
              <div class="col-md-8 info-value">{{ object.model|default:'' }}</div>
            </div>
            {% if user.is_authenticated %}
              <div class="info-row row">
                <div class="col-md-4 info-label">Serial Number</div>
                <div class="col-md-8 info-value">{{ object.serial_number|default:'' }}</div>
              </div>
            {% endif %}
          {% endif %}
        </div>

        <div class="col-lg-6">
          <h2 class="section-title">Identifiers</h2>
          {% for chid in object.hids %}
            <div class="info-row">
              <div class="hash-value">{{ chid|default:'' }}</div>
            </div>
          {% endfor %}
        </div>
      </div>
      <h2 class="section-title mt-5">Components</h2>
      <div class="row">
        {% for component in object.components %}
          <div class="col-md-6 mb-3">
            <div class="card component-card">
              <div class="card-body">
                <h5 class="card-title">{{ component.type }}</h5>
                <p class="card-text">
                  {% for component_key, component_value in component.items %}
                    {% if component_key not in 'actions,type' %}
                      {% if component_key != 'serialNumber' or user.is_authenticated %}
                        <strong>{{ component_key }}:</strong> {{ component_value }}<br />
                      {% endif %}
                    {% endif %}
                  {% endfor %}
                </p>
              </div>
            </div>
          </div>
        {% endfor %}
      </div>
      {% if manuals.icecat %}
       <h5 class="card-title">Icecat data sheet</h5>
        <div class="row">
          <div class="col-12 list-group-item d-flex align-items-center">
            {% if manuals.details.logo %}
              <img style="max-width: 50px; margin-right: 15px;" src="{{ manuals.details.logo }}" />
            {% endif %}
            {% if manuals.details.image %}
              <img style="max-width: 100px; margin-right: 15px;" src="{{ manuals.details.image }}" />
            {% endif %}
            {% if manuals.details.pdf %}
              <a href="{{ manuals.details.pdf }}" target="_blank">{{ manuals.details.title }}</a><br />
            {% else %}
              {{ manuals.details.title }}<br />
            {% endif %}
          </div>
          <div class="col-12 accordion-item">
            <h5 class="card-title accordion-header">
              <button class="accordion-button collapsed" data-bs-target="#manuals-icecat" type="button"
                data-bs-toggle="collapse" aria-expanded="false">
                More examples
              </button>
            </h5>
            <div id="manuals-icecat" class="row accordion-collapse collapse">
              <div class="accordion-body">
                {% for m in manuals.icecat %}
                <div class="list-group-item d-flex align-items-center">
                  {% if m.logo %}
                    <img style="max-width: 50px; margin-right: 15px;" src="{{ m.logo }}" />
                  {% endif %}
                  {% if m.pdf %}
                    <a href="{{ m.pdf }}" target="_blank">{{ m.title }}</a><br />
                  {% else %}
                    {{ m.title }}<br />
                  {% endif %}
                </div>
                {% endfor %}
              </div>
            </div>
          </div>
        </div>
      {% endif %}
              {% if manuals.laer %}
              <div class="row mt-3">
                <div class="col-12">
                  <h5 class="card-title">Recycled Content</h5>
		    
                  <div class="row mb-3">
                    <div class="col-sm-2">
                      Metal
                    </div>
                    <div class="col-sm-10">
                			<div class="progress">
		  
                			  <div class="progress-bar"
                			       role="progressbar"
                			       style="width: {{ manuals.laer.0.metal }}%"
                			       aria-valuenow="{{ manuals.laer.0.metal }}"
                			       aria-valuemin="0"
                			       aria-valuemax="100">{{ manuals.laer.0.metal }}%
                			  </div>
                      </div>
                    </div>
             	    </div>
                  <div class="row mb-3">
                    <div class="col-sm-2">
                      Plastic post Consumer
                    </div>
                    <div class="col-sm-10">
                			<div class="progress">
                			  <div class="progress-bar"
                			       role="progressbar"
                			       style="width: {{ manuals.laer.0.plastic_post_consumer }}%"
                			       aria-valuenow="{{ manuals.laer.0.plastic_post_consumer }}"
                			       aria-valuemin="0"
                			       aria-valuemax="100">{{ manuals.laer.0.plastic_post_consumer }}%
                			  </div>
              			  </div>
              			</div>
             	    </div>
                  <div class="row mb-3">
                    <div class="col-sm-2">
                      Plastic post Industry
                    </div>
                    <div class="col-sm-10">
                			<div class="progress">
                			  <div class="progress-bar"
                			       role="progressbar"
                			       style="width: {{ manuals.laer.0.plastic_post_industry }}%"
                			       aria-valuenow="{{ manuals.laer.0.plastic_post_industry }}"
                			       aria-valuemin="0"
                			       aria-valuemax="100">{{ manuals.laer.0.plastic_post_industry }}%
                			  </div>
              			  </div>
                    </div>
             	    </div>
           	    </div>
         	    </div>
              {% endif %}

              {% if manuals.energystar %}
              <div class="row mt-3">
                <div class="col-12">
                  <h5 class="card-title">Energy spent</h5>
		    
                  {% if manuals.energystar.long_idle_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Consumption when inactivity power function is activated (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.long_idle_watts }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.short_idle_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Consumption when inactivity power function is not activated (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.short_idle_watts }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.sleep_mode_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      sleep_mode_watts
                      Consumption when computer goes into sleep mode (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.sleep_mode_watts }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.off_mode_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Consumption when the computer is off (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.off_mode_watts }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.tec_allowance_kwh %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Power allocation for normal operation (kwh)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.tec_allowance_kwh }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.tec_of_model_kwh %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                       Consumption of the model configuration (kwh)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.tec_of_model_kwh }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.tec_requirement_kwh %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Energy allowance provided (kwh)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.tec_requirement_kwh }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.work_off_mode_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      The lowest power mode which cannot be switched off (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.work_off_mode_watts }}
                    </div>
             	    </div>
                  {% endif %}

                  {% if manuals.energystar.work_weighted_power_of_model_watts %}
                  <div class="row mb-3">
                    <div class="col-sm-10">
                      Weighted energy consumption from all its states (watts)
                    </div>
                    <div class="col-sm-2">
                      {{ manuals.energystar.work_weighted_power_of_model_watts }}
                    </div>
             	    </div>
                  {% endif %}

           	    </div>
         	    </div>
              {% endif %}


              {% if manuals.ifixit %}
              <div class="row">
                <div class="col-12 accordion-item">
                  <h5 class="card-title accordion-header">
                    <button class="accordion-button collapsed" data-bs-target="#manuals-repair" type="button"
                      data-bs-toggle="collapse" aria-expanded="false">
                      Repair manuals
                    </button>
                  </h5>
                  <div id="manuals-repair" class="row accordion-collapse collapse">
                    <div class="list-group col">
                      {% for m in manuals.ifixit %}
                      <div class="list-group-item d-flex align-items-center">
                        {% if m.image %}
                          <img style="max-width: 100px; margin-right: 15px;" src="{{ m.image }}" />
                        {% endif %}
                        {% if m.url %}
                          <a href="{{ m.url }}" target="_blank">{{ m.title }}</a><br />
                        {% else %}
                          {{ m.title }}<br />
                        {% endif %}
                      </div>
                      {% endfor %}
                    </div>
                  </div>
                </div>
              </div>
              {% endif %}
    <footer>
      <p>
        &copy;{% now 'Y' %}eReuse. All rights reserved.
      </p>
    </footer>
{% if user.is_anonymous and not roles %}
<div class="modal fade" id="validateModal" tabindex="-1" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">

      <div class="modal-header">
        <h5 class="modal-title">Validate as <span id="title-action"></span></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <div class="modal-body">
        <a class="btn btn-primary" type="button" 
          href="{% url 'login:login' %}?next={{ path }}">
          User of system
        </a>
        {% if oidc %}
        <br />
        <a class="btn btn-primary mt-3" type="button" href="{# url 'oidc:login_other_inventory' #}?next={{ path }}">
          User of other inventory
        </a>
        {% endif %}
      </div>

      <div class="modal-footer"></div>

    </div>
  </div>
</div>
{% else %}
<div class="modal fade" id="rolesModal" tabindex="-1" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">

      <form action="{{ path }}" method="get">
      <div class="modal-header">
        <h5 class="modal-title">Select your Role <span id="title-action"></span></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>

      <div class="modal-body">
          <select name="role">
            {% for k, v in roles %}
            <option value="{{ k }}" {% if v == role %}selected=selected{% endif %}>{{ v }}</option>
            {% endfor %}
          </select>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <input type="submit" class="btn btn-primary" value="Send" />
      </div>
      </form>

    </div>
  </div>
</div>
{% endif %}

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
  </body>
</html>