<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>
        Admin || <%= config.name %>
    </title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.css">
    <%- include("./../components/head.ejs")%>
</head>

<body class="w-100 bg-light-light h-auto">
    <%- include("./../components/nav.ejs")%>
        <div class="w-100 content bg-light-light px-3 px-md-5 py-3" id="content">
            <h2 class="d-inline-block">Multipliers</h2>
            <button type="button" class="btn btn-<%= config.other.navColor[2] %> float-end" data-bs-toggle="modal"
                data-bs-target="#exampleModal">
                Add Multiplier
            </button>
            <div class="table-responsive">
                <table data-toggle="table" data-search="true" data-show-columns="true" id="mainTable">
                    <thead>
                        <tr class="tr-class-2">
                            <th data-field="label">Label</th>
                            <th data-field="multi">Amount</th>
                            <th data-field="data">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <% Multipliers.forEach(multi=>{%>
                            <tr id="tr-id-<%=multi.id%>" class="tr-class-<%=multi.id%>" data-title="<%=multi.id%>"
                                title="<%=multi.id%>" data-object='{"key": "value"}'>
                                <td id="td-id-<%=multi.id%>" class="td-class-<%=multi.id%>" data-title="<%=multi.label%>">
                                    <strong>
                                        <%=multi.label%>
                                    </strong>
                                </td>
                                <td data-text="<%= multi.amount%>">
                                    <%= multi.amount %>x
                                </td>
                                <td data-text="Delete">
                                    <button class="btn btn-danger" onclick="removeMultiplier('<%=multi.id%>')"><i
                                            class="bi bi-x-circle"></i></button>
                                </td>
                            </tr>
                            <%})%>
                    </tbody>
                </table>
            </div>
            <br>
            <div class="modal fade hideScroll" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel"
                aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">Add Multiplier</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <form method="POST" class="needs-validation" novalidate action="/admin/multi/new">
                                <h2>Create New Multiplier</h2>
                                <br>
                                <div class="mb-3">
                                    <label for="title">Multiplier Label:</label>
                                    <input type="text" class="form-control" placeholder="Multiplier Label" required
                                        aria-label="Label" id="Label" name="label">
                                    <div class="valid-feedback">Looks Good!</div>
                                    <div class="invalid-feedback">Need valid text.</div>
                                </div>
                                <div class="mb-3">
                                    <label for="url">Multiplier Amount:</label>
                                    <input type="number" step="any" max="100" min="0" class="form-control" placeholder="Multiplier Amount" required id="amount"
                                        aria-label="Multiplier" name="amount">
                                    <div class="valid-feedback">Looks Good!</div>
                                    <div class="invalid-feedback">Need a valid number that is between 0-100.</div>
                                </div>
                                <button class="btn btn-<%= config.other.navColor[2] %>">Create</button>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <%- include('./../components/footer.ejs') %>
            <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
                integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
                crossorigin="anonymous"></script>

            <script>
                function removeMultiplier(id) {
                    const data = `id=${id}`;
                    const xhr = new XMLHttpRequest();
                    xhr.withCredentials = true;
                    xhr.addEventListener("readystatechange", function () {
                        console.log(this)
                        if (this.readyState === this.DONE) {
                            console.log(this.responseText);
                        }
                    });
                    xhr.open("POST", `/admin/multi/rem`);
                    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    xhr.send(data);
                    setTimeout(() => {
                        window.location.reload();
                    }, 1500);
                }
            </script>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
            <script src="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.js"></script>

</body>

</html>