{% load static %}
<!DOCTYPE html>
<html lang="en"> <!--begin::Head-->

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Upload</title><!--begin::Primary Meta Tags-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="title" content="AdminLTE | Dashboard v2">
    <meta name="author" content="ColorlibHQ">
    <meta name="description"
        content="AdminLTE is a Free Bootstrap 5 Admin Dashboard, 30 example pages using Vanilla JS.">
    <meta name="keywords"
        content="bootstrap 5, bootstrap, bootstrap 5 admin dashboard, bootstrap 5 dashboard, bootstrap 5 charts, bootstrap 5 calendar, bootstrap 5 datepicker, bootstrap 5 tables, bootstrap 5 datatable, vanilla js datatable, colorlibhq, colorlibhq dashboard, colorlibhq admin dashboard">
    <!--end::Primary Meta Tags--><!--begin::Fonts-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/source-sans-3@5.0.12/index.css"
        integrity="sha256-tXJfXfp6Ewt1ilPzLDtQnJV4hclT9XuaZUKyUvmyr+Q=" crossorigin="anonymous">
    <!--end::Fonts--><!--begin::Third Party Plugin(OverlayScrollbars)-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/styles/overlayscrollbars.min.css"
        integrity="sha256-dSokZseQNT08wYEWiz5iLI8QPlKxG+TswNRD8k35cpg=" crossorigin="anonymous">
    <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Third Party Plugin(Bootstrap Icons)-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.min.css"
        integrity="sha256-Qsx5lrStHZyR9REqhUF8iQt73X06c8LGIUPzpOhwRrI=" crossorigin="anonymous">
    <!--end::Third Party Plugin(Bootstrap Icons)--><!--begin::Required Plugin(AdminLTE)-->
    <link rel="stylesheet" href="{% static './css/adminlte.css' %}"><!--end::Required Plugin(AdminLTE)--><!-- apexcharts -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.css"
        integrity="sha256-4MX+61mt9NVvvuPjUWdUdyfZfxSB1/Rf9WtqRHgG5S0=" crossorigin="anonymous">
    <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="{% static './css/select2-bootstrap4.min.css' %}">
    <link rel="stylesheet" href="{% static './css/custom.css' %}">
    <style>
        .select2-container .select2-search--inline .select2-search__field {
            position: absolute;
            top: 3px;
            font-size: 14px;
        }
    </style>
    <style>
        #full-page-loader {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.6); /* semi-transparent black */
            z-index: 9999;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .loader-overlay .spinner-border {
            width: 3rem;
            height: 3rem;
        }

    </style>
</head>

<body class="layout-fixed sidebar-expand-lg sidebar-mini app-loaded sidebar-collapse">
    <!--begin::App Wrapper-->
    <div class="app-wrapper"> <!--begin::Header-->
        <nav class="app-header navbar navbar-expand bg-body"> <!--begin::Container-->
            <div class="container-fluid"> <!--begin::Start Navbar Links-->
                <ul class="navbar-nav">
                    <li class="nav-item"> <a class="nav-link" data-lte-toggle="sidebar" href="#" role="button"> <i
                                class="bi bi-list"></i> </a> </li>
                    <li class="nav-item d-none d-md-block"> <a  href="{% url 'file-upload' %}" class="nav-link">Home</a> </li>
                    <!-- <li class="nav-item d-none d-md-block"> <a href="#" class="nav-link">Contact</a> </li> -->
                </ul> <!--end::Start Navbar Links--> <!--begin::End Navbar Links-->
                <ul class="navbar-nav ms-auto"> <!--begin::Navbar Search-->
                    <!-- <li class="nav-item"> <a class="nav-link" data-widget="navbar-search" href="search.html"
                            role="button"> <i class="bi bi-search"></i> </a> </li> 

                    <li class="nav-item dropdown"> <a class="nav-link" data-bs-toggle="dropdown" href="#"> <i
                                class="bi bi-bell-fill"></i> <span class="navbar-badge badge text-bg-warning">15</span>
                        </a>
                        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-end"> <span
                                class="dropdown-item dropdown-header">3 Notifications</span>
                            <div class="dropdown-divider"></div> <a href="#" class="dropdown-item"> <i
                                    class="bi bi-people-fill me-2"></i> filename_22_09_2024.xml is ready for review.
                                <span class="float-end text-secondary fs-7">1 hours</span> </a>
                            <div class="dropdown-divider"></div> <a href="#" class="dropdown-item"> <i
                                    class="bi bi-people-fill me-2"></i> filename_22_09_2024.xml is uploaded
                                successfully.
                                <span class="float-end text-secondary fs-7">12 hours</span> </a>
                            <div class="dropdown-divider"></div> <a href="#" class="dropdown-item"> <i
                                    class="bi bi-file-earmark-fill me-2"></i> filename_12_09_2024.xml is uploaded
                                successfully.
                                <span class="float-end text-secondary fs-7">2 days</span> </a>
                            <div class="dropdown-divider"></div> <a href="#" class="dropdown-item dropdown-footer">
                                See All Notifications
                            </a>
                        </div>
                    </li>  -->
                    <li class="nav-item"> <a class="nav-link" href="#" data-lte-toggle="fullscreen"> <i
                                data-lte-icon="maximize" class="bi bi-arrows-fullscreen"></i> <i
                                data-lte-icon="minimize" class="bi bi-fullscreen-exit" style="display: none;"></i> </a>
                    </li> <!--end::Fullscreen Toggle--> <!--begin::User Menu Dropdown-->
                    <li class="nav-item dropdown user-menu"> <a href="#" class="nav-link dropdown-toggle"
                            data-bs-toggle="dropdown"> <img src="{% static './images/user2-160x160.jpg' %}"
                                class="user-image rounded-circle shadow" alt="User Image"> <span
                                class="d-none d-md-inline">Arun Devar</span> </a>
                        <ul class="dropdown-menu dropdown-menu-lg dropdown-menu-end"> <!--begin::User Image-->
                            <li class="user-header text-bg-secondary"> <img src="{% static './images/user2-160x160.jpg' %}"
                                    class="rounded-circle shadow" alt="User Image">
                                <p>
                                    Arun Devar - Senior Manager
                                    <small>Since Nov. 2023</small>
                                </p>
                            </li> <!--end::User Image--> <!--begin::Menu Body-->

                            <li class="user-footer"> <a href="#" class="btn btn-default btn-flat">Profile</a> <a
                                    href="{% url 'logout' %}" class="btn btn-default btn-flat float-end">Sign out</a> </li>
                            <!--end::Menu Footer-->
                        </ul>
                    </li> <!--end::User Menu Dropdown-->
                </ul> <!--end::End Navbar Links-->
            </div> <!--end::Container-->
        </nav> <!--end::Header--> <!--begin::Sidebar-->
        <aside class="app-sidebar shadow"> <!--begin::Sidebar Brand-->
            <div class="sidebar-brand"> <!--begin::Brand Link--> <a href="{% url 'file-upload' %}" class="brand-link">
                    <!--begin::Brand Image--> <img src="{% static './images/logo-mini.png' %}" alt="Lumina Datamatics"
                        class="brand-image logo-mini"> <!--end::Brand Image--> <!--begin::Brand Text--> <span
                        class="brand-text fw-light" style="position:relative; left: -40px;"><img
                            src="{% static './images/logo.png' %}" alt="Lumina Datamatics" class="brand-image"></span>
                    <!--end::Brand Text--> </a>
                <!--end::Brand Link-->
            </div> <!--end::Sidebar Brand--> <!--begin::Sidebar Wrapper-->
            <div class="sidebar-wrapper">
                <nav class="mt-2"> <!--begin::Sidebar Menu-->
                    <ul class="nav sidebar-menu flex-column" data-lte-toggle="treeview" role="menu"
                        data-accordion="false">
                        <li class="nav-item"> <a href="{% url 'file-upload' %}" class="nav-link active"> <i
                                    class="nav-icon bi bi-upload"></i>
                                <p>Upload</p>
                            </a> </li>
                        <li class="nav-item"> <a href="{% url 'tool-check' %}" class="nav-link"> <i
                                    class="nav-icon bi bi-house"></i>
                                <p>Home</p>
                            </a> </li>    
                        
                    </ul> <!--end::Sidebar Menu-->
                </nav>
            </div> <!--end::Sidebar Wrapper-->
        </aside> <!--end::Sidebar--> <!--begin::App Main-->
        <main class="app-main"> <!--begin::App Content Header-->
            <div class="app-content-header"> <!--begin::Container-->
                <div class="container-fluid"> <!--begin::Row-->
                    <div class="row">
                        <div class="col-sm-6">
                            <h3 class="mb-0">Upload</h3>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-end">
                                <li class="breadcrumb-item"><a href="{% url 'file-upload' %}">Home</a></li>
                                <li class="breadcrumb-item active" aria-current="page"><a href="{% url 'tool-check' %}"></a>
                                    Upload</a>
                                </li>
                            </ol>
                        </div>
                    </div> <!--end::Row-->
                </div> <!--end::Container-->
            </div>
            <div class="app-content"> <!--begin::Container-->
                <div class="container-fluid"> <!-- Info boxes -->
                    <div id="full-page-loader" style="display: none;">
                    <div class="loader-overlay">
                        <div class="spinner-border text-light" role="status">
                            <!-- <span class="sr-only">Loading...</span> -->
                        </div>
                    </div>
                </div>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card mb-4">
                                <div class="card-header">
                                    <h5 class="card-title">Upload</h5>
                                    <!-- <a href="#" class="btn btn-sm btn-primary float-sm-end me-2">Download Template</a> -->
                                </div> <!-- /.card-header -->
                                <div class="card-body p-0">
                                    <!-- {% if success %}
                                        <div class="alert alert-success mt-3">
                                            File uploaded successfully! {{ file_url }}View File</a>
                                        </div>
                                    {% endif %} -->

                                    <form id="uploadForm" method="POST"  enctype="multipart/form-data"> <!--begin::Body-->
                                        {% csrf_token %}
                                        <div class="card-body">
                                            
                                            <div class="form-group row mb-3">
                                                <label for="file" class="col-sm-2 col-form-label">Select Input
                                                    File <span class="text-danger">*</span></label>
                                                <div class="col-sm-6">
                                                    <div class="input-group mb-3"> 
                                                        <input type="file" class="form-control"
                                                            id="fileInput" name="file" required
                                                            >
<!-- onchange="enableSubmitButton()" -->
                                                        <!-- <input type="file"
                                                            onchange="$(this).parents('.form-group').next().removeClass('d-none')"
                                                            class="form-control" id="file" required> 
                                                        </div> -->
                                                </div>
                                            </div>

                                            <div class="form-group row mb-3 ">
                                                <label for="file" class="col-sm-2 col-form-label"></label>
                                                <div class="col-sm-6">
                                                    <button type="submit" class="btn btn-primary" id="submitBtn" disabled>Upload</button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                    
                                    <div id="responseMessage" class="mt-3"></div>

                                </div>
                            </div> <!-- /.card -->
                        </div> <!-- /.col -->
                    </div> <!--end::Row--> <!--begin::Row-->
                    
                </div> <!--end::Container-->
            </div> <!--end::App Content-->
        </main> <!--end::App Main--> <!--begin::Footer-->
        <footer class="app-footer"> <!--begin::To the end-->
            <!-- <div class="float-end d-none d-sm-inline">Anything you want</div>--> <!--end::To the end-->
            <!--begin::Copyright--> <strong>
                Copyright &copy; 2014-2024&nbsp;
                <a href="https://www.luminadatamatics.com/" target="_blank" class="text-decoration-none">Lumina
                    Datamatics LTD</a>.
            </strong>
            All rights reserved.
            <!--end::Copyright-->
        </footer> <!--end::Footer-->
    </div> <!--end::App Wrapper--> <!--begin::Script--> <!--begin::Third Party Plugin(OverlayScrollbars)-->
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"
        integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/browser/overlayscrollbars.browser.es6.min.js"
        integrity="sha256-H2VM7BKda+v2Z4+DRy69uknwxjyDRhszjXFhsL4gD3w=" crossorigin="anonymous"></script>
    <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Required Plugin(popperjs for Bootstrap 5)-->
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
        integrity="sha256-whL0tQWoY1Ku1iskqPFvmZ+CHsvmRWx/PIoEvIeWh4I=" crossorigin="anonymous"></script>
    <!--end::Required Plugin(popperjs for Bootstrap 5)--><!--begin::Required Plugin(Bootstrap 5)-->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"
        integrity="sha256-YMa+wAM6QkVyz999odX7lPRxkoYAan8suedu4k2Zur8=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
    <!--end::Required Plugin(Bootstrap 5)--><!--begin::Required Plugin(AdminLTE)-->
    <script src="{% static './js/adminlte.js' %}"></script>
    <!--end::Required Plugin(AdminLTE)--><!--begin::OverlayScrollbars Configure-->
    <script>
        const SELECTOR_SIDEBAR_WRAPPER = ".sidebar-wrapper";
        const Default = {
            scrollbarTheme: "os-theme-light",
            scrollbarAutoHide: "leave",
            scrollbarClickScroll: true,
        };
        document.addEventListener("DOMContentLoaded", function () {
            const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER);
            if (
                sidebarWrapper &&
                typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== "undefined"
            ) {
                OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
                    scrollbars: {
                        theme: Default.scrollbarTheme,
                        autoHide: Default.scrollbarAutoHide,
                        clickScroll: Default.scrollbarClickScroll,
                    },
                });
            }
        });
        $(document).ready(function () {
            $('.select2').select2({
                theme: 'bootstrap4',
                placeholder: 'Select Competitors'
            });
        });

        //$('#myForm').on('submit', function (e) {
        //    e.preventDefault(); //stop submit

        //    if ($('#file').val() != "") {
        //        //Check if checkbox is checked then show modal
        //        $('#myModal').modal('show');
        //    }
        //});
    </script> <!--end::OverlayScrollbars Configure--> <!-- OPTIONAL SCRIPTS --> <!-- apexcharts -->
    <script src="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.min.js"
        integrity="sha256-+vh8GkaU7C9/wbSLIcwq82tQ2wTf44aOHA8HlBMwRI8=" crossorigin="anonymous"></script>
    
    <!-- <script>
    function enableSubmitButton() {
        const fileInput = document.getElementById('fileInput');
        const submitBtn = document.getElementById('submitBtn');

        if (fileInput.files.length > 0) {
            submitBtn.disabled = false;
        } else {
            submitBtn.disabled = true;
        }
    }
    </script> -->

    <script>
document.addEventListener('DOMContentLoaded', function () {
    const form = document.getElementById('uploadForm');
    const fileInput = document.getElementById('fileInput');
    const submitBtn = document.getElementById('submitBtn');
    const responseDiv = document.getElementById('responseMessage');

    // Enable submit button when file is selected
    fileInput.addEventListener('change', function () {
        submitBtn.disabled = fileInput.files.length === 0;
    });

    // Handle form submission
    form.addEventListener('submit', function (e) {
        e.preventDefault();
        $('#full-page-loader').show();
        // Disable button during upload
        submitBtn.disabled = true;
        submitBtn.textContent = 'Uploading...';

        const formData = new FormData(form);

        fetch('/core/api/upload-rules/', {
            method: 'POST',
            body: formData,
            headers: {
                'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
            }
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                responseDiv.innerHTML = `<div class="alert alert-success">✅ ${data.message}</div>`;
                fileInput.value = ''; // Clear file input
                submitBtn.disabled = true; // Keep disabled until new file selected
                $('#full-page-loader').hide();
            } else {
                responseDiv.innerHTML = `<div class="alert alert-danger">❌ ${data.error}</div>`;
                submitBtn.disabled = false;
                $('#full-page-loader').hide();
            }
        })
        .catch(error => {
            responseDiv.innerHTML = `<div class="alert alert-danger">❌ Upload failed: ${error}</div>`;
            submitBtn.disabled = false;
            $('#full-page-loader').hide();
        })
        .finally(() => {
            submitBtn.textContent = 'Upload';
            $('#full-page-loader').hide();

            // Remove message after 5 seconds
            setTimeout(() => {
                responseDiv.innerHTML = '';
                window.location.href = "/tool-check";
            }, 3000);
        });
    });
});
</script>

    <!-- <script>
        function enableSubmitButton() {
            const fileInput = document.getElementById('fileInput');
            const submitBtn = document.getElementById('submitBtn');
            submitBtn.disabled = fileInput.files.length === 0;
        }
        
        document.addEventListener('DOMContentLoaded', function () {
            
            const form = document.getElementById('uploadForm');

            form.addEventListener('submit', function(e) {
            e.preventDefault(); // prevent default form submission

            const form = e.target;
            const formData = new FormData(form);
            const responseDiv = document.getElementById('responseMessage');

            fetch('/core/api/upload-rules/', {
                method: 'POST',
                body: formData,
                headers: {
                    'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
                }
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    responseDiv.innerHTML = `<div class="alert alert-success">✅ ${data.message}</div>`;
                } else {
                    responseDiv.innerHTML = `<div class="alert alert-danger">❌ ${data.error}</div>`;
                }
            })
            .catch(error => {
                responseDiv.innerHTML = `<div class="alert alert-danger">❌ Upload failed: ${error}</div>`;
            });
        });
                
        });

        </script> -->

</body><!--end::Body-->

</html>