@extends('layouts.app')

@section('title','Master Mata Pelajaran')

@section('content')

<div class="container-fluid">

    {{-- Header --}}
    <div class="d-flex justify-content-between align-items-center mb-4">

        <div>

            <h3 class="font-weight-bold mb-1">
                Master Mata Pelajaran
            </h3>

            <p class="text-muted mb-0">
                Kelola seluruh mata pelajaran yang diajarkan di sekolah.
            </p>

        </div>

    </div>

    {{-- Alert --}}
    @if(session('success'))

    <div class="alert alert-success alert-dismissible fade show">

        <i class="fas fa-check-circle mr-2"></i>

        {{ session('success') }}

        <button
            type="button"
            class="close"
            data-dismiss="alert">

            <span>&times;</span>

        </button>

    </div>

    @endif

    {{-- Statistik --}}
    <div class="row mb-4">

        <div class="col-md-4">

            <div class="small-card">

                <div>

                    <small>Total Mata Pelajaran</small>

                    <h2>

                        {{ $mapel->count() }}

                    </h2>

                </div>

                <div class="small-icon bg-success">

                    <i class="fas fa-book-open"></i>

                </div>

            </div>

        </div>

    </div>

    {{-- Form --}}
    <div class="card card-modern mb-4">

        <div class="card-header bg-white border-0">

            <h5 class="mb-0">

                <i class="fas fa-plus-circle text-success mr-2"></i>

                Tambah Mata Pelajaran

            </h5>

        </div>

        <div class="card-body">

            <form action="{{ route('mata-pelajaran.store') }}" method="POST">

                @csrf

                <div class="row">

                    <div class="col-md-5">

                        <label>Kode Mata Pelajaran</label>

                        <input
                            type="text"
                            name="kode_mapel"
                            class="form-control"
                            placeholder="Contoh : MTK001">

                    </div>

                    <div class="col-md-5">

                        <label>Nama Mata Pelajaran</label>

                        <input
                            type="text"
                            name="nama_mapel"
                            class="form-control"
                            placeholder="Contoh : Matematika">

                    </div>

                    <div class="col-md-2 d-flex align-items-end">

                        <button
                            class="btn btn-success btn-modern btn-block">

                            <i class="fas fa-save mr-1"></i>

                            Simpan

                        </button>

                    </div>

                </div>

            </form>

        </div>

    </div>

    {{-- Table --}}
    <div class="card card-modern">

        <div class="card-header bg-white border-0">

            <h5 class="mb-0">

                <i class="fas fa-list text-primary mr-2"></i>

                Daftar Mata Pelajaran

            </h5>

        </div>

        <div class="card-body">

            <div class="table-responsive">

                <table class="table table-modern table-hover datatable">

                    <thead>

                        <tr>

                            <th width="180">
                                Kode
                            </th>

                            <th>
                                Mata Pelajaran
                            </th>

                            <th width="150" class="text-center">
                                Aksi
                            </th>

                        </tr>

                    </thead>

                    <tbody>

                    @foreach($mapel as $m)

                    <tr>

                        <td>

                            <span class="badge badge-primary px-3 py-2">

                                {{ $m->kode_mapel }}

                            </span>

                        </td>

                        <td>

                            <strong>

                                {{ $m->nama_mapel }}

                            </strong>

                        </td>

                        <td class="text-center">

                            <a
                                href="{{ route('mata-pelajaran.edit',$m->id) }}"
                                class="btn btn-warning btn-sm rounded-circle"
                                title="Edit">

                                <i class="fas fa-pencil-alt"></i>

                            </a>

                            <form
                                action="{{ route('mata-pelajaran.destroy',$m->id) }}"
                                method="POST"
                                class="d-inline">

                                @csrf
                                @method('DELETE')

                                <button
                                    class="btn btn-danger btn-sm rounded-circle"
                                    onclick="return confirm('Hapus mata pelajaran ini?')">

                                    <i class="fas fa-trash"></i>

                                </button>

                            </form>

                        </td>

                    </tr>

                    @endforeach

                    </tbody>

                </table>

            </div>

        </div>

    </div>

</div>

@endsection