
{% load i18n %}
{% load static %}
{% load basefilters %}
{% load horillafilters %}

<span name="" id="filterEmployee" style="display: none" hx-get="{% url 'employee-filter-view' %}?{{pd}}" hx-target="#view-container"></span>
<div class="d-flex flex-row-reverse m-2">
  <span class="" onclick="$('[name=working_today]').val('false'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
    <span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span>
    {% trans "Offline" %}
  </span>
  <span class="me-3" onclick="$('[name=working_today]').val('true'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
    <span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span>
    {% trans "Online" %}
  </span>
</div>
<div id="relatedModel"></div>
{% if messages %}
    <div class="oh-alert-container">
        {% for message in messages %}
        <div class="oh-alert oh-alert--animated {{message.tags}}">
              {{ message }}
        </div>
        {% endfor %}
    </div>
    {% endif %}
{% include 'filter_tags.html' %}

<style>

  .profile-picture {
    transition: transform 0.3s;
    z-index:9999
    ;
  }

  .profile-picture:hover {
      transform: scale(2.4);
  }

</style>

<div class="oh-layout--grid-3">
  {% if data %}
    {% for emp in data %}
        <div  class="oh-kanban-card" style="color: inherit;text-decoration: none;{% if emp.employee_work_info.reporting_manager_id == request.user.employee_get %} background-color: hsl(38.08deg 100% 50% / 8%);{% endif %}"
          onclick="window.location.href = `{% url 'employee-view-individual' emp.id %}`"
        >
          <div class="oh-kanban-card__avatar">
            <div class="oh-kanban-card__profile-container {% if emp.employee_profile %} profile-picture {% endif %}">
              <img
              src="{{emp.get_avatar}}"
              class="oh-kanban-card__profile-image"
              alt=""
              />
            </div>
          </div>

          <div class="oh-kanban-card__details">
            <span class="oh-kanban-card__title" {% if emp.email|length >= 30 %}title = "{{emp}}" {% endif %}>{{emp|truncatechars:30}}</span>
            <span class="oh-kanban-card__subtitle" {% if emp.email|length >= 35 %}title = "{{emp.email}}" {% endif %}>{{emp.email|truncatechars:35}}</span><br>
            <span class="oh-kanban-card__subtitle">{{emp.employee_work_info.job_position_id}}</span>
            <div class="oh-kanban-card__subtitle">
              {% if "attendance"|app_installed %}
                {% if emp.check_online %}
                  <span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span> {% trans "Online" %}
                {% else %}
                  <span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span> {% trans "Offline" %}
                {% endif %}
              {% endif %}
            </div>
          </div>

          {% if perms.employee.change_employee or perms.employee.delete_employee or request.user|check_manager:emp %}
            <div class="oh-kanban-card__dots" onclick="event.stopPropagation()">
              <div class="oh-dropdown" x-data="{show: false}">
                <button class="oh-btn oh-btn--transparent text-muted p-3" @click="show = !show" title='{% trans "Actions" %}'>
                  <ion-icon name="ellipsis-vertical-sharp" role="img" class="md hydrated" aria-label="ellipsis vertical sharp"></ion-icon>
                </button>
                <div class="oh-dropdown__menu oh-dropdown__menu--dark-border oh-dropdown__menu--right" x-show="show" @click.outside="show = false" style="display: none;">
                  <ul class="oh-dropdown__items">
                    {% if perms.employee.change_employee or request.user|check_manager:emp %}
                      <li class="oh-dropdown__item">
                        <a href="{% url 'employee-view-update' emp.id %}" class="oh-dropdown__link">{% trans "Edit" %}</a>
                      </li>
                    {% endif %}
                    {% if perms.employee.delete_employee %}
                      <li class="oh-dropdown__item">
                        {% if emp.is_active %}
                          <a hx-confirm="{% trans 'Do you want to archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}?{{pd}}" hx-target="#relatedModel" class="oh-dropdown__link">
                            {% trans "Archive" %}
                          </a>
                          {% else %}
                          <a hx-confirm="{% trans 'Do you want to un archive this employee?' %}" hx-post="{% url 'employee-archive' emp.id %}" hx-target="#relatedModel" class="oh-dropdown__link">
                            {% trans "Un-Archive" %}
                          </a>
                        {% endif %}
                      </li>
                    {% endif %}
                    {% if perms.employee.delete_employee %}
                      <li class="oh-dropdown__item">
                        <form action="{% url 'employee-delete' emp.id %}?view=card" method="post"
                          onsubmit="return confirm('{% trans "All non-active contracts of the employee will also be deleted. Do you want to continue ?" %}')">
                          {% csrf_token %}
                          <button type="submit" class="oh-dropdown__link oh-dropdown__link--danger">{% trans "Delete" %}</button>
                        </form>
                      </li>
                    {% endif %}
                  </ul>
                </div>
              </div>
            </div>
          {% endif %}
        </div>
    {% endfor %}
      </div>


  <div class="oh-pagination">
    <span
      class="oh-pagination__page"
      >
      {% trans "Page" %} {{ data.number }} {% trans "of" %} {{ data.paginator.num_pages }}.
      </span
    >
    <nav class="oh-pagination__nav">
      <div class="oh-pagination__input-container me-3">
        <span class="oh-pagination__label me-1">{% trans "Page" %}</span>
        <input
          type="number"
          name="page"
          class="oh-pagination__input"
          value="{{data.number}}"
          hx-get="{% url 'employee-filter-view' %}?{{pd}}"
          hx-target="#view-container"
          min="1"
        />
        <span class="oh-pagination__label">{% trans "of" %} {{data.paginator.num_pages}}</span>
      </div>
      <ul class="oh-pagination__items">
        {% if data.has_previous %}
        <li class="oh-pagination__item oh-pagination__item--wide">
          <a hx-target='#view-container' hx-get="{% url 'employee-filter-view' %}?{{pd}}&page=1" class="oh-pagination__link">{% trans "First" %}</a>
        </li>
        <li class="oh-pagination__item oh-pagination__item--wide">
          <a hx-target='#view-container' hx-get="{% url 'employee-filter-view' %}?{{pd}}&page={{ data.previous_page_number }}" class="oh-pagination__link">{% trans "Previous" %}</a>
        </li>
        {% endif %}
        {% if data.has_next %}
        <li class="oh-pagination__item oh-pagination__item--wide">
          <a hx-target='#view-container' hx-get="{% url 'employee-filter-view' %}?{{pd}}&page={{ data.next_page_number }}" class="oh-pagination__link">{% trans "Next" %}</a>
        </li>
        <li class="oh-pagination__item oh-pagination__item--wide">
          <a hx-target='#view-container' hx-get="{% url 'employee-filter-view' %}?{{pd}}&page={{ data.paginator.num_pages }}" class="oh-pagination__link">{% trans "Last" %}</a>
        </li>
        {% endif %}

      </ul>
    </nav>
  </div>
{% else %}
  <!-- start of empty page -->
  <div class="oh-404">
    <img
      style="width: 150px; height: 150px"
      src="{% static 'images/ui/no-results.png' %}"
      class="oh-404__image mb-4"
    />
    <h5 class="oh-404__subtitle">
      {% trans "No search result found!" %}
    </h5>
  </div>
  <!-- end of empty page -->
{% endif %}
