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

{% from "helpers/_forms.html" import render_field %}

{% block title %} New AWS Account {% 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="py-4">
        <nav aria-label="breadcrumb">
            <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="/aws-list">Accounts</a></li>
                <li class="breadcrumb-item"><a href="/aws-list">AWS</a></li>
                <li class="breadcrumb-item active" aria-current="page">New</li>
            </ol>
        </nav>
        <div class="d-flex justify-content-between w-100 flex-wrap">
            <div class="mb-3 mb-lg-0">
                <h1 class="h4">Add New AWS Account</h1>
                <p class="mb-0">Add account by squad and environment</p>
            </div>
            <div>
                <a href="" class="btn btn-outline-gray"><i class="far fa-question-circle mr-1"></i> Accounts Docs</a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12 mb-4">
            <div class="card border-light shadow-sm components-section">
                <div class="card-body">
                    <div class="row mb-4">
                        <div class="col-lg-4 col-sm-6">
                            <!-- Form -->
                            <div class="col-md-12 col-md-offset-1">
                                <form class="" method="post">
                                    <div class="form-group">
                                        {{ render_field(form.squad, class='form-control', placeholder='Squad Name') }}
                                    </div>

                                    <div class="form-group">
                                        {{ render_field(form.environment, class='form-control', placeholder='Environment Name') }}
                                    </div>

                                    <div class="form-group">
                                        {{ render_field(form.access_key_id, class='form-control', placeholder='aws access_key_id') }}
                                    </div>

                                    <div class="form-group">
                                        {{ render_field(form.secret_access_key, class='form-control', placeholder='aws secret_access_key') }}
                                    </div>

                                    <div class="form-group">
                                        {{ render_field(form.default_region, class='form-control',value='eu-west-1') }}
                                    </div>

                                    <div class="form-group">
                                        {{ render_field(form.role_arn, class='form-control', placeholder='role_arn') }}
                                    </div>

                                    <!-- Add custom variables -->
                                    <div class="border-top my-4"></div>
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <div id="inputFormRow">
                                            </div>

                                            <div id="newRow"></div>
                                            <button id="addRow"
                                                    type="button"
                                                    class="btn btn-info btn-sm"
                                                    title="Add extra secrets varibles like TF_VAR_secreto: mySeCret">Add
                                                Extra Variable</button>
                                        </div>
                                    </div>
                                    <div class="border-top my-4"></div>
                                    <!-- End Add custom variables -->
                                    <button type="submit" class="btn btn-primary" name="button">
                                        Create new Account
                                    </button>
                                    <button type="button" class="btn btn-danger" id="cancelButton">
                                        Exit         
                                    </button>

                                </form>
                                <!-- End Form -->

                                <div class="input-group">
                                </div>
                            </div>
                        </div>
                    </div>

                    {% include 'includes/footer.html' %}

</main>

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}
<script type="text/javascript">
    // add row
    $("#addRow").click(function () {
        var html = '';
        html += '<div class="row">';
        html += '<div id="inputFormRow">';
        html += '<div class="input-group col-sm-8 mb-3">';
        html += ' <div class="col-sm-8 mb-2">';
        html += '<input type="text" name="sld_key" class="form-control m-input" placeholder="Enter variable name" autocomplete="off">';
        html += '</div>';
        html += ' <div class="col-sm-8 mb-4">';
        html += '<input type="text" name="sld_value" class="form-control m-input" placeholder="Enter variable value" autocomplete="off">';
        html += '</div>';
        html += '<div class="input-group-append">';
        html += '<button id="removeRow" type="button" class="btn btn-danger btn-sm ml-2">Remove</button>';
        html += '</div>';
        html += '</div>';

        $('#newRow').append(html);
    });

    // remove row
    $(document).on('click', '#removeRow', function () {
        $(this).closest('#inputFormRow').remove();
    });
</script>
<script type="text/javascript">
    document.getElementById('cancelButton').addEventListener('click', function() {
        // Redirect to /aws-list when the cancel button is clicked
        window.location.href = '/aws-list';
    });
</script>
{% endblock javascripts %}