@extends('web.layouts.layout')

@section('container_content')

<section class="box">
    <div class="container-fluid">
        <div class="loops">
            <h3 class="title wow fadeInUp">Loops</h3>
            <div class="row">
                <div class="{{ ($currentLoop && $currentLoop['month']) ? 'col-lg-7' : 'col-lg-12' }} ">
                    <div class="items">
                        <div class="content">
                            <div class="row">
                                <div class="col-6">
                                    <div class="cur-loops">
                                        <h6>Current loops</h6>
                                        @foreach($currentLoops as $userLoop)
                                            <a href="{{ route('loops.details', [ 'loop_id'=> $userLoop['id'] ]) }}">
                                                <span>{{ $userLoop['month'] }}</span>
                                            </a>
                                        @endforeach
                                    </div>
                                </div>

                                <div class="col-6">
                                    <div class="prev-loops">
                                        <h6>previous loops</h6>
                                        @foreach($prevLoops as $userLoop)
                                            <a href="{{ route('loops.details', [ 'loop_id'=> $userLoop['id'] ]) }}">
                                                <span>{{ $userLoop['month'] }}</span>
                                            </a>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                @if($currentLoop && $currentLoop['month'])
                <div class="col-lg-4 offset-lg-1">
                    <div class="items">
                        <h6>{{ date('F Y') }}</h6>
                        <div class="join-loops mb-2">
                            <!-- <span>feb</span> -->
                            <a href="{{ route('loops.available') }}">
                                <span>{{ $currentLoop['month'] }}</span>
                            </a>
                        </div>
                        <p>remaining to close</p>
                        <ul class="countdown-date">
                            <li><span id="days"></span>D : </li>
                            <li><span id="hours"></span>H : </li>
                            <li><span id="minutes"></span>M : </li>
                            <li><span id="seconds"></span>S</li>
                        </ul>
                    </div>
                </div>
                @endif
            </div>
        </div>
    </div>
</section>
@endsection

@section('container_js')
@if($currentLoop && $currentLoop['end_date'])
<script>
    // date countdown -----------------
    const second = 1000,
        minute = second * 60,
        hour = minute * 60,
        day = hour * 24,
        week = hour * 24 * 7;

    // let countDown = new Date('Nov 29, 2020 12:30:00').getTime(),
    let countDown = new Date('{{ $currentLoop["end_date"] }}').getTime(),
        x = setInterval(function() {

            let now = new Date().getTime(),
                distance = countDown - now;

            document.getElementById('days').innerText = Math.floor(distance / (day)),
                document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)),
                document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)),
                document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
        }, second)
</script>
@endif
@endsection
