$def with (entry)

$def format_time(time):
    $if time is not None:
        $return '{:d}:{:02d}'.format(time//60, time%60)
    $else:
        $return ''

$def format_date(time):
    $if time is not None:
        $return time.strftime('%H:%M:%S')
    $else:
        $return ''

$def format_diff_time(t):
    $if entry.result.start_time is not None:
        $ diff = t.replace(microsecond=0) - entry.result.start_time.replace(microsecond=0)
        $return format_time(int(diff.total_seconds()))
    $else:
        $return ''


<!-- Modal content -->
<div class="modal-content">
    <span class="close" onclick="document.getElementById('entr.resultDialog').style.display='none'">&times;</span>
    <form id="entr.formAdd" class="form-container" autocomplete="off" onsubmit="entr_submitAdd(); return false;">
        <input id="entr.resultId" name="id" type="text" value="$entry.id" hidden/>
        <table>
            <tr>
                <th class="input-header">First name</th>
                <td>$entry.first_name</td>
            </tr>
            <tr>
                <th class="input-header"><label>Last name</label></th>
                <td><label>$entry.last_name</label></td>
            </tr>
            <tr>
                <th class="input-header"><label>Year</label></th>
                <td><label>$entry.year</label></td>
            </tr>
            <tr>
                <th class="input-header"><label>Class</label></th>
                <td><label>$entry.class_</label></td>
            </tr>
            <tr>
                <th class="input-header"><label>Chip</label></th>
                <td><label>$entry.chip</label></td>
            </tr>
            <tr>
                <th class="input-header"><label for="start_time">Start time</label></th>
                <td><label>$(format_date(entry.result.get('start_time', None)))</label></td>
            </tr>
            <tr>
                <th class="input-header"><label for="finish_time">Finish time</label></th>
                <td><label>$(format_date(entry.result.get('finish_time', None)))</label></td>
            </tr>
            <tr>
                <th class="input-header"><label>Status</label></th>
                <td><label>$MAP_STATUS[entry.result.status]</label></td>
            </tr>
            <tr>
                <th class="input-header"><label>Time</label></th>
                <td><label>$(format_time(entry.result.extensions.get('running_time', entry.result.time)))</label></td>
            </tr>
        </table>
            
        <table style="border-collapse: collapse">
            $if entry.result.punched_clear_time is not None or entry.result.punched_check_time is not None or entry.result.punched_start_time is not None or entry.result.punched_finish_time is not None:
                <thead>
                    <tr><th colspan="2" style="padding-top:2em"></th></tr>
                    <tr class="dt">
                        <th class="dt">Number</th>
                        <th class="dt">Control code</th>
                        <th class="dt">Punch time</th>
                        <th class="dt">Time</th>
                        <th class="dt">Status</th>
                    </tr>
                </thead>
                <tbody>
                    $if entry.result.punched_clear_time is not None:
                        <tr class="dt">
                            <td class="dt" style="text-align:right">Clear</td>
                            <td class="dt" style="text-align:right">Clear</td>
                            <td class="dt" style="text-align:right">$format_date(entry.result.punched_clear_time)</td>
                            <td class="dt" style="text-align:right">$format_diff_time(entry.result.punched_clear_time)</td>
                            <td class="dt"></td>
                        </tr>
                    $if entry.result.punched_check_time is not None:
                        <tr class="dt">
                            <td class="dt" style="text-align:right">Check</td>
                            <td class="dt" style="text-align:right">Check</td>
                            <td class="dt" style="text-align:right">$format_date(entry.result.punched_check_time)</td>
                            <td class="dt" style="text-align:right">$format_diff_time(entry.result.punched_check_time)</td>
                            <td class="dt"></td>
                        </tr>
                    $if entry.result.punched_start_time is not None:
                        <tr class="dt">
                            <td class="dt" style="text-align:right">Start</td>
                            <td class="dt" style="text-align:right">Start</td>
                            <td class="dt" style="text-align:right">$format_date(entry.result.punched_start_time)</td>
                            <td class="dt" style="text-align:right">$format_diff_time(entry.result.punched_start_time)</td>
                            <td class="dt"></td>
                        </tr>
                    $if entry.result.punched_finish_time is not None:
                        <tr class="dt">
                            <td class="dt" style="text-align:right">Finish</td>
                            <td class="dt" style="text-align:right">Finish</td>
                            <td class="dt" style="text-align:right">$format_date(entry.result.punched_finish_time)</td>
                            <td class="dt" style="text-align:right">$format_diff_time(entry.result.punched_finish_time)</td>
                            <td class="dt"></td>
                        </tr>
                </tbody>

            $if entry.result.split_times != []:
                <thead>
                    <tr class="dt">
                    <tr><th colspan="2" style="padding-top:2em"></th></tr>
                        <th class="dt">Number</th>
                        <th class="dt">Control code</th>
                        <th class="dt">Punch time</th>
                        <th class="dt">Time</th>
                        <th class="dt">Status</th>
                    </tr>
                </thead>
                <tbody>
                    $ i = 0
                    $for punch in entry.result.split_times:
                        <tr class="dt">
                            $if punch.get('status', '') in ('OK', 'Missing'):
                                $ i += 1
                                <td class="dt" style="text-align:right">$str(i)</td>
                            $else:
                                <td class="dt" style="text-align:right"></td>
                            <td class="dt" style="text-align:right">$punch.get('control_code', '')</td>
                            <td class="dt" style="text-align:right">$(format_date(punch.get('punch_time', None)))</td>
                            <td class="dt" style="text-align:right">$(format_time(punch.get('time', None)))</td>
                            <td class="dt">$punch.get('status', '')</td>
                        </tr>
                </tbody>
        </table>
        <p></p>
        <!--button type="submit" class="btn">Save</button-->
        <button type="button" class="btn cancel" onclick="document.getElementById('entr.resultDialog').style.display='none'">Cancel</button>
    </form>
</div>
 
