<!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' ) }}">
        
        <script type="text/javascript">
            baseurl = "{{ baseurl }}";
            
            {% if not admin %}
                var password_local = decrypt( sessionStorage.getItem( "session_key" ), "{{ session_security_key }}" );
                var nickname = decrypt( "{{ nickname }}", password_local );
            {% endif %}
            
            var marks_list = {};
            {% if not admin %}
                {% for file in files %}
                    marks_list[ "{{ file[ 'uuid' ] }}" ] = {
                        "id": "{{ file[ 'id' ] }}",
                        "uuid": "{{ file[ 'uuid' ] }}",
                        "filename": decrypt( "{{ file[ 'filename' ] }}", password_local )
                    };
                {% endfor %}
            {% else %}
                {% for file in files %}
                    marks_list[ "{{ file[ 'uuid' ] }}" ] = {
                        "id": "{{ file[ 'id' ] }}",
                        "uuid": "{{ file[ 'uuid' ] }}",
                        "filename": "Mark {{ file[ 'id' ] }}"
                    };
                {% endfor %}
            {% endif %}
            
            update_search_result = function()
            {
                var searched = $( "#search_bar" ).val();
                searched = searched.toLowerCase();
                
                _.forEach( marks_list, function( mark )
                {
                    var tmp = [];
                    _.forEach( mark, function( d )
                    {
                        tmp.push( d.toLowerCase().indexOf( searched ) );
                    } );
                    
                    if( Math.max( ...tmp ) > -1 )
                    {
                        $( "#mark_" + mark[ 'uuid' ] ).show();
                    } else {
                        $( "#mark_" + mark[ 'uuid' ] ).hide();
                    }
                } );
            }
        </script>
        
        <style type="text/css">
            .icnml_list_of_boxes {
                grid-template-columns: repeat( auto-fill, calc( var( --imgsize ) + 2 * var( --imgmargin ) ) );
            }
            .icnml_search_bar {
                margin-left: 10px;
                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 file..."/>
            </div>
            
            <div class="icnml_list_of_boxes">
                {% for file in files %}
                    <div id="mark_{{ file[ 'uuid' ] }}">
                        <div class="ui-widget-header ui-corner-top icnml_box_top" id="mark_{{ file[ 'uuid' ] }}_filename">-</div>
                        <div class="ui-widget-content ui-corner-bottom icnml_box_content">
                            <div
                                id="mark_{{ file[ 'uuid' ] }}"
                                class="icnml_pointer"
                                style="background-image: url( {{ url_for( 'image.image_file_serve', file_id = file[ 'uuid' ] ) }} )">
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
            <div id="zoom_slider"></div>
        </div>
        <script type="text/javascript">
            $( "#search_bar" ).on( "keyup", update_search_result );
            $( "#search_bar" ).focus();
            
            {% if not admin %}
                {% for file in files %}
                    $( "#mark_{{ file[ 'uuid' ] }}" ).on( "click", function()
                    {
                        window.location.href = "{{ url_for( 'submission.submission_mark', submission_id = submission_id, mark_id = file[ 'uuid' ] ) }}";
                    } );
                {% endfor %}
            {% else %}
                {% for file in files %}
                    $( "#mark_{{ file[ 'uuid' ] }}" ).on( "click", function()
                    {
                        window.location.href = "{{ url_for( 'submission.admin_submission_mark', submission_id = submission_id, mark_id = file[ 'uuid' ] ) }}";
                    } );
                {% endfor %}
            {% endif %}
            
            _.forEach( marks_list, function( mark )
            {
                $( "#mark_" + mark[ "uuid" ] + "_filename" ).text( mark[ "filename" ] );
            } )
            
            $( "#icnml_navigation_submissions" )
                .addClass( "activated" );
            
            {% if not admin %}
                $( "#navloc" ).append(
                    $( "<a />" )
                        .attr( "href", "{{ url_for( 'submission.submission_list' ) }}" )
                        .text( "Submissions" )
                )
                .append(
                    $( "<span />" ).text( ">" )
                )
                .append(
                    $( "<a />" )
                        .attr( "href", "{{ url_for( 'submission.submission_upload_tenprintmark', submission_id = submission_id ) }}" )
                        .text( nickname )
                )
                .append(
                    $( "<span />" ).text( ">" )
                )
                .append(
                    $( "<a />" )
                        .attr( "href", "{{ url_for( 'submission.submission_mark_list', submission_id = submission_id, mark_type = 'all' ) }}" )
                        .text( "Marks" )
                )
                .append(
                    $( "<span />" ).text( ">" )
                )
                .append(
                    $( "<span />" ).text( "{{ mark_type }}" )
                );
            {% else %}
                $( "#navloc" ).append(
                    $( "<a />" )
                        .attr( "href", "{{ url_for( 'submission.admin_submission_list' ) }}" )
                        .text( "Submissions" )
                )
                .append(
                    $( "<span />" ).text( ">" )
                )
                .append(
                    $( "<a />" )
                        .attr( "href", "{{ url_for( 'submission.admin_submission_home', submission_id = submission_id ) }}" )
                        .text( "{{ username }}" )
                )
                .append(
                    $( "<span />" ).text( ">" )
                )
                .append(
                    $( "<span />" ).text( "Marks" )
                );
            {% endif %}
        </script>
    </body>
</html>
        
