@extends('layouts.admin')

@section('title', $department->name)

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-2">
                @include('admin.department.navigation', ['departments' => $departments, 'activeDepartment' => $department->id, 'routeLink' => 'admin.departments.show'])
            </div>

            <div class="col-md-10">
                <div class="d-flex justify-content-end mb-3">
                    <a class="btn btn-success mr-1" href="{{ route('admin.departments.subjects.create', $department->id) }}">Dodaj predmet</a>
                    <button class="btn btn-primary" id="upload-excel-button" type="button">Učitaj Excel</button>
                    <form method="POST" action="{{ route('admin.departments.import', $department->id) }}" id="upload-excel-form" enctype="multipart/form-data">
                        @csrf
                        <input type="file" id="upload-excel-input" name="excel" hidden>
                    </form>
                    <a class="btn btn-warning ml-1" href="{{ route('admin.departments.edit', $department->id) }}">Izmeni</a>
                </div>
                <ul class="nav nav-tabs" id="semesters" role="tablist">
                    @foreach ($semesters as $semester => $subjects)
                        <li class="nav-item">
                            <a
                                    class="nav-link @if($loop->first) active @endif "
                                    id="{{ $semester }}-tab"
                                    data-toggle="tab"
                                    href="#semester-{{ $semester }}"
                                    role="tab"
                                    aria-controls="semester-{{ $semester }}"
                                    @if ($loop->first)
                                        aria-selected="true"
                                    @endif
                            >{{ $semester }}. semestar</a>
                        </li>
                    @endforeach
                </ul>

                <div class="tab-content mt-4">
                    @foreach ($semesters as $semester => $subjects)
                        <div class="tab-pane @if($loop->first) active @endif" id="semester-{{ $semester }}" role="tabpanel" aria-labelledby="{{ $semester }}-tab">
                            <table class="table">
                                <thead class="thead-dark">
                                    <th scope="col">
                                        Predmet
                                    </th>
                                    <th scope="col">
                                        Profesor
                                    </th>
                                    <th scope="col">
                                        Asistent
                                    </th>
                                    <th scope="col">
                                        Semestar
                                    </th>
                                    <th scope="col">
                                        Opcije
                                    </th>
                                </thead>
                                <tbody>
                                    @foreach ($subjects->sortBy('name') as $subject)
                                        <tr>
                                            <th class="align-middle" scope="row">{{ $subject->name }}</th>
                                            <td class="align-middle">{{ $subject->teacher->name }}</td>
                                            <td class="align-middle">{{ optional($subject->assistant)->name }}</td>
                                            <td class="align-middle">{{ $subject->semester }}</td>
                                            <td>
                                                <div class="row">
                                                    <div class="mr-1">
                                                        @include('admin.partials.buttons.delete', ['url' => route('admin.subjects.destroy', $subject->id)])
                                                    </div>
                                                    @include('admin.partials.buttons.edit', ['url' => route('admin.subjects.edit', $subject->id)])
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    @endforeach
                </div>
        </div>
    </div>
@endsection

@section('scripts')
    @parent
    <script>
        $(document).ready(function () {
            $('#upload-excel-button').on('click', function () {
                $('#upload-excel-input').trigger('click');
            });
            $('#upload-excel-input').on('change', function () {
                $('#upload-excel-form').submit();
            });
        });
    </script>
@endsection