{% extends "/base.html" %}

{% block title %} UI Tables {% endblock %} 

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

{% block content %}
{% with messages = get_flashed_messages() %}
        {% if messages %}
            <div class="flash">
                {{ messages }}
            </div>
        {% endif %}
{% endwith %}
<div class="modal fade" id="uploadModal" tabindex="-1" role="dialog" aria-labelledby="uploadModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="uploadModalLabel">Upload File</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- Your existing form goes here -->
                <form role="form" method="post" action="/save_file" enctype="multipart/form-data">
                    <!-- <div class="form-group">
                        <label for="exampleFormControlSelect1">Choose Data Source</label>
                        <select class="form-control" name="connection_name" id="exampleFormControlSelect1">
                            {% for name in connection_name %}
                                <option>{{ name[0] }}</option>
                            {% endfor %}
                        </select>
                    </div> -->
                    <div class="form-group">
                        <label>File:</label>
                        <input type="file" name="excelFile" accept=".xlsx, .xls" required>
                    </div>
                    <!-- Rest of your form fields go here -->

                    <!-- Submit button moved outside the form -->
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </form>
            </div>
            
        </div>
    </div>
</div>


    <!-- [ Main Content ] start -->
    <section class="pcoded-main-container">
        <div class="pcoded-wrapper">

            <div class="pcoded-content">
                <div class="pcoded-inner-content">
                    <!-- [ breadcrumb ] start -->
                    <div class="page-header">
                        <div class="page-block">
                            <div class="row align-items-center">
                                <div class="col-md-12">
                                    <div class="page-header-title">
                                        <h5 class="m-b-10"></h5>
                                    </div>
                                    <ul class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="/dashboard"><i class="feather icon-home"></i></a></li>
                                        <li class="breadcrumb-item"><a href="">File List</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- [ breadcrumb ] end -->
                    <div class="main-body">
                        <div class="page-wrapper">
                            <div class="row">
                                <!-- [ basic-table ] start -->
                                <div class="col-xl-12">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5>File List</h5>
                                        </div>
                                        <div style="text-align: end">
                                            {% if session.get('role') == 'Checker' %}
                                            <button type="submit" class="btn btn-secondary" title="Create User" onclick="window.location.href='/download_excel'">Download</button>
                                            {% endif %}
                                            {% if session.get('role') == 'superadmin' or session.get('role') == 'user' %}
                                                <button type="button" class="btn btn-secondary" title="Create User" data-toggle="modal" data-target="#uploadModal">
                                                    Upload File
                                                </button>
                                            {% else %}
                                                <button type="button" class="btn btn-secondary" title="Create User" data-toggle="modal" data-target="#uploadModal" disabled>
                                                    Upload File
                                                </button>
                                            {% endif %}
                                        </div>
                                        
                                        <!-- <div style="text-align: end"><button type="submit" class="btn btn-secondary" title="Create User" onclick="window.location.href='/add_db'">Add Data Source</button></div>-->
                                        <div class="card-block table-border-style"> 
                                            <div class="table-responsive">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>File Name</th>
                                                            <th>Date</th>
                                                            <th>view</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <!-- Your rows inside the table HERE: -->
                                                        {% for item in data_dicts %}
                                                        <tr>
                                                            <th scope="row">{{ item.id }}</th>
                                                            <td contenteditable="false" class="editable" data-field="file_path">{{ item.file_path.split("\\")[-1] }}</td>
                                                            <td contenteditable="false" class="editable" data-field="username">{{ item.created_at.strftime('%d %B %Y') }}</td>
                                                            <td>
                                                                <a href="/show_data/{{ item.id }}" class="fa fa-eye"></a>
                                                            </td>
                                                        </tr>
                                                        {% endfor %}
                                                    </tbody>
                                                </table>

                                                </div>
                                
                                                </div>
                            
                                            </div>
                                </div>
                            </div>
                        </div>
                        </div>
                        </div>
                    </div>
    </section>
    <!-- [ Main Content ] end -->

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const flashMessage = document.querySelector(".flash");
        if (flashMessage) {
            toastMixin.fire({
                animation: true,
                title: flashMessage
            });
        }
    });
</script>
{% endblock javascripts %}

