<!DOCTYPE html>
<html>
    <head>
        {% for src in js %}
            <script type="text/javascript" src="{{ src }}"></script>
        {% endfor %}
        {% for src in css %}
            <link type="text/css" rel="stylesheet" href="{{ src }}">
        {% endfor %}
        
        <script type="text/javascript" src="{{ url_for( 'files.send_app_files', subpath = 'functions.js' ) }}"></script>
        <link type="text/css" rel="stylesheet" href="{{ url_for( 'files.send_app_files', subpath = 'app.css' ) }}">
        <link type="text/css" rel="stylesheet" href="{{ url_for( 'files.send_app_files', subpath = 'dropzone.css' ) }}">
        
        <script type="text/javascript">
            baseurl = "{{ baseurl }}";

            var donors = {};
            {% for donor in donors %}
                donors[ "{{ donor[ 'uuid' ] }}" ] = {
                    "uuid": "{{ donor[ 'uuid' ] }}",
                    "username": "{{ donor[ 'username' ] }}"
                };
            {% endfor %}
            
            update_search_result = function()
            {
                var searched = $( "#search_bar" ).val();
                searched = searched.toLowerCase();
                
                _.forEach( donors, function( donor )
                {
                    var tmp = [];
                    _.forEach( donor, function( d )
                    {
                        tmp.push( d.toLowerCase().indexOf( searched ) );
                    } );
                    
                    if( Math.max( ...tmp ) > -1 )
                    {
                        $( "#donor_" + donor[ "uuid" ] + "_outer_div" ).show();
                    } else {
                        $( "#donor_" + donor[ "uuid" ] + "_outer_div" ).hide();
                    }
                } );
            }
        </script>
        
        <style type="text/css">
            :root {
                --imgsize: 170px;
            }
            .icnml_donor_button {
                width: 120px;
                height: 120px;
            }
            .icnml_donor_button > span {
                height: 120px;
                line-height: 120px;
                vertical-align: center;
                text-align: center;
            }
            .icnml_search_bar {
                margin-bottom: 20px;
                width: 500px;
            }
        </style>
    </head>
    <body class="icnml_main_layout">
        {% include "header.html" %}
        {% include navigation %}
        
        <div class="icnml_content">
            <div class="icnml_search_bar">
                <input id="search_bar" placeholder="Search for a donor..."/>
            </div>
            <div class="icnml_list_of_boxes">
                {% for donor in donors %}
                    <div style="margin-bottom: 20px" id="donor_{{ donor[ 'uuid' ] }}_outer_div">
                        <div class="ui-widget-header ui-corner-top icnml_box_top" id="donor_{{ donor[ 'id' ] }}_nickname">{{ donor[ 'username' ] }}</div>
                        <div class="ui-widget-content ui-corner-bottom icnml_box_content">
                            <div class="icnml_button">
                                <a class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only icnml_donor_button" id="edit_{{ donor[ 'id' ] }}_button" role="button" aria-disabled="false">
                                    <span>View</span>
                                </a>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        
        <script type="text/javascript">
            $( "#search_bar" ).on( "keyup", update_search_result );
            $( "#search_bar" ).focus();
            
            {% for donor in donors %}
                $( "#edit_{{ donor[ 'id' ] }}_button" ).on( "click", function()
                {
                    window.location = "{{ url_for( 'submission.admin_submission_home', submission_id = donor[ 'uuid' ] ) }}";
                } );
            {% endfor %}
            
            $( "#icnml_navigation_submissions" )
                .addClass( "activated" );
            
            $( "#navloc" ).append(
                $( "<span />" ).text( "Submissions" )
            );
        </script>
    </body>
</html>
