{% extends "corptools/base.html" %}
{% load i18n %}
<!-- TODO Make this nicer in some way... -->
{% block ct_block %}
    <br>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button"
                        class="navbar-toggle collapsed"
                        data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1"
                        aria-expanded="false">
                    <span class="sr-only">{% translate "Toggle navigation" %}</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="{% url 'corptools:view' %}">{% translate "Account Audit" %}</a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    {% if perms.corptools.admin %}
                        <li>
                            <a class="" href="{% url 'corptools:admin' %}">{% translate "DB Admin" %}</a>
                        </li>

                    {% endif %}
                    {% if perms.corptools.alliance_corp_manager or perms.corptools.global_corp_manager or perms.corptools.state_corp_manager %}
                        <li class=>
                            <a href="{% url 'corptools:corp_menu' %}">{% translate "Corporations" %}</a>
                            <li>
                            {% endif %}

                        </ul>
                        <ul class="nav navbar-nav pull-right">
                            <li class=>
                                <a href="{% url 'corptools:add_char' %}">{% translate "Add Character Token" %}</a>
                            </li>
                            {% if perms.corptools.alliance_corp_manager or perms.corptools.global_corp_manager or perms.corptools.state_corp_manager %}
                                <li class=>
                                    <a href="{% url 'corptools:add_corp' %}">{% translate "Add Corporate Token" %}</a>
                                    <li>
                                    {% endif %}

                                </ul>
                            </div>

                        </div>
                    </nav>
                    <div class="col-md-12">
                        <table class="table table-hover dateTable" id="characters">
                            <thead>
                                <th></th>
                                <th>{% translate "Main Character" %}</th>
                                <th>{% translate "Corporation" %}</th>
                                <th>{% translate "Alliance" %}</th>
                                <th>{% translate "Alts" %}</th>
                            </thead>
                            <tbody>
                                {% for char,alts in characters.items %}
                                    <tr>
                                        <td>
                                            <a href="{% url 'corptools:overview' char %}">
                                                <img class="ra-avatar img-circle" src="{{ alts.main.portrait_url_64 }}">
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{% url 'corptools:overview' char %}">{{ alts.main.character_name }}</a>
                                    </td>
                                    <td>{{ alts.main.corporation_name }}</td>
                                    <td>{{ alts.main.alliance_name }}</td>
                                    <td>
                                        {% for alt in alts.audit.character.character_ownership.user.character_ownerships.all %}
                                            <span style="background-color:
                                                         {% if alt.character.characteraudit.active %}
                                                             #008844
                                                         {% else %}
                                                             #AA0000
                                                         {% endif %}"
                                                  class="label label-default">{{ alt.character.character_name }}</span>
                                        {% endfor %}
                                    </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>

            {% endblock ct_block %}
            {% block extra_javascript %}
                {% include "bundles/datatables-js.html" %}
                <script>
                    ! function(t) {
                        function e(t) {
                            var e = {
                                columns: [],
                                columnsIdxList: [],
                                bootstrap: !1,
                                autoSize: !0,
                                label: "Filter "
                            };
                            if ("bootstrap" in t && "boolean" == typeof t.bootstrap && (e.bootstrap = t.bootstrap), "autoSize" in t && "boolean" == typeof t.autoSize && (e.autoSize = t.autoSize), "label" in t && "string" == typeof t.label && (e.label = t.label), "columns" in t)
                                for (var i = 0; i < t.columns.length; i++) {
                                    var n = t.columns[i];
                                    if ("idx" in n && "number" == typeof n.idx) {
                                        var o = n.idx;
                                        e.columns[o] = {
                                            title: null,
                                            maxWidth: null,
                                            autoSize: !0
                                        }, e.columnsIdxList.push(o), "title" in n && "string" == typeof n.title && (e.columns[o].title = n.title), "maxWidth" in n && "string" == typeof n.maxWidth && (e.columns[o].maxWidth = n.maxWidth), "autoSize" in n && "boolean" == typeof n.autoSize && (e.columns[o].autoSize = n.autoSize)
                                    }
                                }
                            return e
                        }
                        t(document).on("preInit.dt", function(i, n) {
                            if ("dt" === i.namespace) {
                                var o = new t.fn.dataTable.Api(n),
                                    a = o.table().node().id,
                                    l = o.init();
                                if ("filterDropDown" in l) {
                                    var r = e(l.filterDropDown);
                                    if (0 != r.columns.length) {
                                        var u = o.table().container(),
                                            s = a + "_filterWrapper",
                                            c = s + " " + (r.bootstrap ? "form-inline" : "");
                                        t(u).prepend('<div id="' + s + '" class="' + c + '">' + r.label + "</div>"), o.columns(r.columnsIdxList).every(function() {
                                            var e = this.index(),
                                                i = null !== r.columns[e].title ? r.columns[e].title : t(this.header()).html();
                                            "" == i && (i = "column " + (e + 1));
                                            var n = "form-control " + a + "_filterSelect",
                                                o = a + "_filterSelect" + e;
                                            t("#" + s).append('<select id="' + o + '" class="' + n + '"></select>');
                                            var l = t("#" + o).empty().append('<option value="">(' + i + ")</option>");
                                        })
                                    }
                                }
                            }
                        }), t(document).on("init.dt", function(i, n) {
                            if ("dt" === i.namespace) {
                                var o = new t.fn.dataTable.Api(n),
                                    a = o.table().node().id,
                                    l = o.init();
                                if ("filterDropDown" in l) {
                                    var r = e(l.filterDropDown);
                                    o.table().container();
                                    o.columns(r.columnsIdxList).every(function() {
                                        var e = this,
                                            i = e.index(),
                                            n = t("#" + (a + "_filterSelect" + i));
                                        n.on("change", function() {
                                            var i = t.fn.dataTable.util.escapeRegex(t(this).val());
                                            e.search(i ? "^" + i + "$" : "", !0, !1).draw()
                                        }), e.data().unique().sort().each(function(t, e) {
                                            "" != t && n.append('<option value="' + t + '">' + t + "</option>")
                                        })
                                    })
                                }
                            }
                        })
                    }(jQuery);
                </script>
            {% endblock extra_javascript %}
            {% block extra_script %}
                $(document).ready(function() {
                $('#characters').DataTable({
                "filterDropDown": {
                columns: [{
                idx: 2
                },
                {
                idx: 3
                }],
                bootstrap: true
                },
                "columnDefs": [
                { "sortable": false, "targets": [0] }
                ],
                "order": [
                [1, "asc"]
                ],
                "pageLength": 25
                });
                });
            {% endblock extra_script %}
