<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Control Service</title>
    {{> control/partials/head-includes }}
</head>
<body>
{{> control/partials/nav}}
<div class="container">
    <h1 class="my-3">Domain Complaints</h1>
    {{#unless complaintsNew}}
    <p>No new complaints!</p>
    {{/unless}}
    {{#if complaintsNew}}
    <table class="table-rh-3 table" id="complaintsNew">
        <tr>
            <th>Date</th>
            <th>Category</th>
            <th></th>
        </tr>
        <tr>
            <th>Domain</th>
            <th colspan="2">Sample</th>
        </tr>
        <tr>
            <th colspan="3">Description</th>
        </tr>

        {{#each complaintsNew}}

        <tr>
            <td>{{fileDate}}</td>
            <td>{{category}}</td>
            <td>
                <div class="dropdown">
                    <a class="btn btn-secondary dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        Action
                    </a>

                    <ul class="dropdown-menu">
                        {{#if appeal}}
                            <li><a class="dropdown-item" href="#"  onClick="handleComplaint('{{domain}}', 'appeal')">Revert Sanction</a></li>
                        {{/if}}
                        {{#unless appeal}}
                            <li><a class="dropdown-item" href="#"  onClick="handleComplaint('{{domain}}', 'blacklist')">Add Sanction</a></li>
                            <li><a class="dropdown-item" href="#"  onClick="handleComplaint('{{domain}}', 'no-random')">Remove From Random Domains</a></li>
                        {{/unless}}
                        <li><a class="dropdown-item" href="#" onClick="handleComplaint('{{domain}}', 'noop')">Ignore</a></li>
                    </ul>
                </div>

<!--                <form method="post" action="/complaints/{{domain}}" onsubmit="return confirm('Confirm review of {{domain}}')">-->
<!--                    <div class="mb-3 row">-->
<!--                        <div class="col-sm-10">-->
<!--                            <label class="form-label" for="action-{{domain}}" style="display: none;">Action: </label>-->
<!--                            <select class="form-control" type="select" name="action" id="action-{{domain}}">-->
<!--                                {{#if appeal}}-->
<!--                                <option value="appeal">Revert Ban</option>-->
<!--                                {{/if}}-->
<!--                                {{#unless appeal}}-->
<!--                                <option value="blacklist">Ban Domain</option>-->
<!--                                {{/unless}}-->
<!--                                <option selected value="noop">No Action</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                        <div class="col-sm-10">-->
<!--                            <input type="submit" value="Review" />-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </form>-->
            </td>
        </tr>
        <tr>
            <td><a href="https://search.marginalia.nu/site/{{domain}}">{{domain}}</a></td>
            <td colspan="2">{{sample}}</td>
        </tr>
        <tr>
            <td colspan="3">{{description}}</td>
        </tr>
        {{/each}}
    </table>
    {{/if}}

    {{#if complaintsReviewed}}
    <h1>Review Log</h1>
    <table class="table-rh-3 table" id="complaintsReviewed">
        <tr>
            <th>Review Date</th>
            <th>Category</th>
            <th>Action</th>
        </tr>
        <tr>
            <th>Domain</th>
            <th colspan="2">Sample</th>
        </tr>
        <tr>
            <th colspan="3">Description</th>
        </tr>

        {{#each complaintsReviewed}}
        <tr>
            <td>{{fileDate}}</td>
            <td>{{category}}</td>
            <td>
                {{decision}}
            </td>
        </tr>
        <tr>
            <td><a href="https://search.marginalia.nu/site/{{domain}}">{{domain}}</a></td>
            <td colspan="2">{{sample}}</td>
        </tr>
        <tr>
            <td colspan="3">{{description}}</td>
        </tr>
        {{/each}}
    </table>
    {{/if}}
</div>
</body>
<script>
    function handleComplaint(domain, action) {
        const request = new XMLHttpRequest();
        request.open("POST", "/complaints/"+domain+"?action="+action);
        request.onload = () => {
            window.location.reload();
        }
        request.send();
    }
</script>
{{> control/partials/foot-includes }}
</html>