@extends('layouts/contentNavbarLayout')

@section('title', 'Tables - Nilai')

@section('content')
<h4 class="fw-bold py-3 mb-4">
    <span class="text-muted fw-light">Tables Nilai</span>
</h4>

<!-- Responsive Table -->
<div class="card">
    <h5 class="card-header">Nilai</h5>
    @if ($user->role == "Admin")
        <div class="mx-3 text-start">
            <a href="{{ route('nilai.create') }}">
                <button type="submit" class="btn btn-sm btn-primary">
                    <i class='bx bx-plus'></i>
                    Add
                </button>
            </a>
            <div class="btn-group">
                <button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-bs-toggle="dropdown"
                    aria-expanded="false">Export</button>
                <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="{{route('nilai.export')}}?output=excel">Excel</a></li>
                    <li><a class="dropdown-item" href="{{route('nilai.export')}}?output=pdf">PDF</a></li>
                </ul>
            </div>
        </div>
        <div class="table-responsive text-nowrap p-3">
            <table class="table" id="table">
                <thead>
                    <tr class="text-nowrap">
                        <th>No</th>
                        <th>Nama</th>
                        <th>Writing</th>
                        <th>Reading</th>
                        <th>Listening</th>
                        <th>Speaking</th>
                        <th>Rata-Rata</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($nilai as $record)
                        <tr>
                            <th scope="row">{{$loop->index + 1}}</th>
                            <td>{{$record->nama}}</td>
                            <td>{{$record->writing}}</td>
                            <td>{{$record->reading}}</td>
                            <td>{{$record->listening}}</td>
                            <td>{{$record->speaking}}</td>
                            <td>{{($record->writing + $record->reading + $record->listening + $record->speaking) / 4}}
                            </td>
                            <td>
                                <div class="btn-group" role="group" aria-label="Actions">
                                    <a href="{{route('nilai.edit', $record->nilai_id)}}" class="btn btn-blue"><i
                                            class="bx bx-edit-alt"></i> Edit</a>
                                    <form action="{{route('nilai.delete', $record->nilai_id)}}" method="POST">
                                        @csrf
                                        @method("DELETE")
                                        <button type="submit" class="btn btn-white"
                                            onclick="return confirm('Apakah Kamu Yakin?')">
                                            <i class="bx bx-trash"></i> Delete
                                        </button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    @else
        <div class="row mb-3 px-3">
            <div class="col-md-6 col-lg-4 mb-3">
                <div class="card text-center">
                    <div class="card-header">
                        Reading
                    </div>
                    <div class="card-body">
                        <h3 class="card-title">{{$nilai[0]->reading}}</h3>
                        <p class="card-text">Kemampuan peserta didik dalam membaca teks berbahasa inggris</p>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-4 mb-3">
                <div class="card text-center">
                    <div class="card-header">
                        Writing
                    </div>
                    <div class="card-body">
                        <h3 class="card-title">{{$nilai[0]->writing}}</h3>
                        <p class="card-text">Kemampuan peserta didik dalam menulis teks berbahasa inggris</p>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-4 mb-3">
                <div class="card text-center">
                    <div class="card-header">
                        Listening
                    </div>
                    <div class="card-body">
                        <h3 class="card-title">{{$nilai[0]->listening}}</h3>
                        <p class="card-text">Kemampuan peserta didik dalam mendengarkan teks berbahasa inggris</p>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-4 mb-3">
                <div class="card text-center">
                    <div class="card-header">
                        Speaking
                    </div>
                    <div class="card-body">
                        <h3 class="card-title">{{$nilai[0]->speaking}}</h3>
                        <p class="card-text">Kemampuan peserta didik dalam berbicara bahasa inggris</p>
                    </div>
                </div>
            </div>
            <div class="col-md-6 col-lg-12 mb-3">
                <div class="card text-center">
                    <div class="card-header">
                        Average
                    </div>
                    <div class="card-body">
                        <h3 class="card-title">
                            {{($nilai[0]->reading + $nilai[0]->writing + $nilai[0]->listening + $nilai[0]->speaking) / 4}}
                        </h3>
                        <p class="card-text">Nilai rata-rata kemampuan peserta didik</p>
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
<!--/ Responsive Table -->
@endsection