<script>
 import {
     Alert,
     Card,
     CardBody,
     CardTitle,
     Col,
     Container,
     Icon,
     Row,
 } from '@sveltestrap/sveltestrap';

 import { my } from '$lib/stores/my.js';
 import { rank } from '$lib/stores/teams.js';
 import { challengeInfo } from '$lib/stores/challengeinfo.js';

 import CardTheme from '$lib/components/CardTheme.svelte';

 let search = "";

 // Override theme color
 document.body.style.backgroundColor = "";
</script>

<Container fluid class="my-3">
<h1 class="text-dark">
    {$challengeInfo.title}
    <small class="text-muted">Classement</small>
</h1>
<div class="card niceborder text-light">
    <div class="card-body">
        <input type="text" class="form-control" placeholder="Rechercher" bind:value={search}>
    </div>
    <table class="table table-hover table-striped">
        <thead>
            <tr>
	        <th>Rang</th>
	        <th>Équipe</th>
	        <th>Points</th>
            </tr>
        </thead>
        <tbody>
            {#each $rank as team (team.id)}
                {#if team.rank != 0 || ($my && $my.team_id == team.id)}
                    <tr class:bg-info={$my && $my.team_id == team.id} class:bg-warning={search.length && team.name.toLowerCase().indexOf(search.toLowerCase()) >= 0}>
	                <td>{team.rank}</td>
	                <td>{team.name}</td>
	                <td>{Math.round(team.score*100)/100}</td>
                    </tr>
                {/if}
            {/each}
        </tbody>
    </table>
</div>
</Container>
