{% extends "layouts/base.html" %}

{% block title %} AWS Accounts {% endblock %}

<!-- Specific Page CSS goes HERE  -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}

<main class="content">

    {% include 'includes/navigation.html' %}
    <div class="preloader bg-soft flex-column justify-content-center align-items-center">
        <img class="loader-element animate__animated animate__jackInTheBox" src="/static/assets/img/brand/light.svg"
            height="90" alt="Volt logo">
    </div>

    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center py-4">
        <div class="d-block mb-4 mb-md-0">
            <nav aria-label="breadcrumb" class="d-none d-md-inline-block">
                <ol class="breadcrumb breadcrumb-dark breadcrumb-transparent">
                    <li class="breadcrumb-item"><a href="#"><span class="fas fa-home"></span></a></li>
                    <li class="breadcrumb-item"><a href="#">Accounts</a></li>
                    <li class="breadcrumb-item"><a href="#">AWS</a></li>
                    <li class="breadcrumb-item active" aria-current="page">List</li>
                </ol>
            </nav>
            <h2 class="h4">All aws accounts</h2>
            <p class="mb-0">List all aws accounts</p>
        </div>
        <div class="btn-toolbar mb-2 mb-md-0">
            <div class="btn-group">
            </div>
        </div>
    </div>
    <div class="table-settings mb-4">
        <div class="row align-items-center justify-content-between">
            <div class="col col-md-6 col-lg-3 col-xl-4">
                <div class="input-group">
                    <span class="input-group-text" id="basic-addon2"><span class="fas fa-search"></span></span>
                    <input type="text" class="form-control" id="myInput" onkeyup="search()" placeholder="Search"
                        aria-label="Search" aria-describedby="basic-addon2">
                </div>
            </div>

            <div class="col-4 col-md-2 col-xl-1 pl-md-0 text-right">
                <div class="btn-group">
                    <button class="btn btn-link text-dark dropdown-toggle dropdown-toggle-split m-0 p-0"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <span class="icon icon-sm icon-gray">
                            <span class="fas fa-cog"></span>
                        </span>
                        <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <div class="dropdown-menu dropdown-menu-xs dropdown-menu-right">
                        <span class="dropdown-item font-weight-bold text-dark">Show</span>
                        <a class="dropdown-item d-flex font-weight-bold" href="#">5 <span
                                class="icon icon-small ml-auto"><span class="fas fa-check"></span></span></a>
                        <a class="dropdown-item font-weight-bold" href="#">20</a>
                        <a class="dropdown-item font-weight-bold" href="#">30</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="card card-body border-light shadow-sm table-wrapper table-responsive pt-0">
        <table class="table table-striped" id="table">
            <thead class="thead-dark">
                <tr>
                    <th>ID</th>
                    <th>Account Name</th>
                    <th>Squad</th>
                    <th>Environment</th>
                    <th>Default Region</th>
                    <th>Role Arn</th>
                    <th>Extra Variables</th>
                    <th></th>
                </tr>
            </thead>
            <tbody id="myTable">
                <!-- Item -->
                {% for aws_account in aws %}
                <tr>
                    </td>
                    <td><span class="font-weight-normal">{{ aws_account.id }}</span></td>
                    <td><span class="tag-style">{{ aws_account.squad }}_{{ aws_account.environment}}</span></td>
                    <td><span class="font-weight-normal">{{ aws_account.squad }}</span></td>
                    <td><span class="font-weight-normal">{{ aws_account.environment }}</span></td>
                    <td><span class="font-weight-normal">{{ aws_account.default_region }}</span></td>
<td>
    <span class="font-weight-normal">
        {% if aws_account.role_arn %}
            {{ aws_account.role_arn }}
        {% else %}
            -
        {% endif %}
    </span>
</td>
<td>
    <span class="font-weight-normal" title="{% if aws_account.extra_variables %}{{ ', '.join(aws_account.extra_variables.keys()) }}{% endif %}">
        {% if aws_account.extra_variables %}
            {% set truncated_variables = aws_account.extra_variables.keys() | join(', ') | truncate(30, True, '...') %}
            {{ truncated_variables }}
        {% else %}
            -
        {% endif %}
    </span>
</td>
                    <td>
                        <div class="btn-group">
                            {% if "yoda" in current_user.role %}
                            <button class="btn btn-link text-dark dropdown-toggle dropdown-toggle-split m-0 p-0"
                                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <span class="icon icon-sm">
                                    <span class="fas fa-ellipsis-h icon-dark"></span>
                                </span>
                                <span class="sr-only">Toggle Dropdown</span>
                            </button>
                            <div class="dropdown-menu">
                                <a class="dropdown-item" 
                                    href="{{ url_for('.edit_aws_account', account_id=aws_account.id)}}"><span 
                                    class="fas fa-edit mr-2"></span>Edit</a>
                                <a class="dropdown-item text-danger"
                                    href="{{ url_for('.delete_aws_account', aws_account_id=aws_account.id)}}"><span
                                        class="fas fa-trash-alt mr-2"></span>Remove</a>
                            {% endif %}
                        </div>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div class="card-footer px-3 border-0 d-flex align-items-center justify-content-between">
            <nav aria-label="Page navigation example">
                <ul class="pagination mb-0">
                    <li class="page-item">
                    </li>
                    <li class="page-item active">
                    </li>
                    <li class="page-item">
                    </li>
                    <li class="page-item">
                    </li>
                    <li class="page-item">
                    </li>
                    <li class="page-item">
                    </li>
                    <li class="page-item">
                    </li>
                </ul>
            </nav>
            <div class="font-weight-bold small"><b></b><b></b></div>
        </div>
    </div>
 <!-- Pagination
<nav>
  <ul class="pagination">
    <li class="page-item" id="previous-page"><a class="page-link" href="#">Previous</a></li>
    <li class="page-item" id="next-page"><a class="page-link" href="#">Next</a></li>
  </ul>
</nav> 
-->
    {% include 'includes/footer.html' %}

</main>

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}
<!-- <script src="/static/assets/js/pagination.js"></script> -->
<script src="/static/assets/js/search.js"></script>
{% endblock javascripts %}

