@extends('adminlte::page')

@section('title', 'Maklumat Bantuan')

@section('content_header')
    <h1><i class="fas fa-question-circle mr-2"></i>Maklumat Bantuan</h1>
@stop

@section('content')
    @if (session('success'))
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <i class="fas fa-check-circle mr-1"></i> {{ session('success') }}
        </div>
    @endif

    <div class="row justify-content-center">
        <div class="col-md-10">

            {{-- Tambah Entri --}}
            <div class="card card-outline card-primary">
                <div class="card-header">
                    <h3 class="card-title"><i class="fas fa-plus-circle mr-1"></i> Tambah Entri Bantuan</h3>
                    <div class="card-tools">
                        <button type="button" class="btn btn-tool" data-card-widget="collapse">
                            <i class="fas fa-minus"></i>
                        </button>
                    </div>
                </div>
                <div class="card-body">
                    <form action="{{ route('admin.bantuan.store') }}" method="POST">
                        @csrf
                        <div class="form-row">
                            <div class="form-group col-md-4">
                                <label><i class="fas fa-user mr-1 text-primary"></i> Nama</label>
                                <input type="text" name="nama"
                                    class="form-control @error('nama') is-invalid @enderror"
                                    placeholder="Encik Ahmad bin Ali" value="{{ old('nama') }}" maxlength="100">
                                @error('nama')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="form-group col-md-3">
                                <label><i class="fas fa-phone mr-1 text-success"></i> No. Telefon</label>
                                <input type="text" name="telefon"
                                    class="form-control @error('telefon') is-invalid @enderror" placeholder="03-5510 0000"
                                    value="{{ old('telefon') }}" maxlength="20">
                                @error('telefon')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="form-group col-md-5">
                                <label><i class="fas fa-map-marker-alt mr-1 text-danger"></i> Alamat / Jawatan</label>
                                <input type="text" name="alamat"
                                    class="form-control @error('alamat') is-invalid @enderror"
                                    placeholder="Bahagian Pendidikan Islam..." value="{{ old('alamat') }}" maxlength="300">
                                @error('alamat')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary btn-sm">
                            <i class="fas fa-plus mr-1"></i> Tambah
                        </button>
                    </form>
                </div>
            </div>

            {{-- Senarai --}}
            <div class="card card-outline card-info">
                <div class="card-header">
                    <h3 class="card-title"><i class="fas fa-list mr-1"></i> Senarai Entri Bantuan</h3>
                    <div class="card-tools">
                        <small class="text-muted">Maklumat ini dipaparkan pada halaman log masuk</small>
                    </div>
                </div>
                <div class="card-body p-0">
                    @if ($bantuans->isEmpty())
                        <p class="text-center text-muted py-3">Tiada entri bantuan. Tambah entri di atas.</p>
                    @else
                        <table class="table table-hover table-sm mb-0">
                            <thead class="thead-light">
                                <tr>
                                    <th width="40">#</th>
                                    <th>Nama</th>
                                    <th>No. Telefon</th>
                                    <th>Alamat / Jawatan</th>
                                    <th width="90">Tindakan</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($bantuans as $i => $b)
                                    <tr>
                                        <td>{{ $i + 1 }}</td>
                                        <td>{{ $b->nama }}</td>
                                        <td>{{ $b->telefon }}</td>
                                        <td>{{ $b->alamat }}</td>
                                        <td>
                                            <button class="btn btn-xs btn-warning" data-toggle="modal"
                                                data-target="#editModal{{ $b->id }}">
                                                <i class="fas fa-edit"></i>
                                            </button>
                                            <form action="{{ route('admin.bantuan.destroy', $b) }}" method="POST"
                                                class="d-inline" onsubmit="return confirm('Padam entri ini?')">
                                                @csrf
                                                @method('DELETE')
                                                <button class="btn btn-xs btn-danger">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </form>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    @endif
                </div>
            </div>

            {{-- Meja Bantuan Preview --}}
            @if ($bantuans->isNotEmpty())
                <div class="card card-outline card-secondary">
                    <div class="card-header">
                        <h3 class="card-title"><i class="fas fa-eye mr-1"></i> Meja Bantuan</h3>
                    </div>
                    <div class="card-body">
                        @foreach ($bantuans as $b)
                            <div class="d-flex align-items-start mb-2">
                                <div class="mr-3 text-primary" style="font-size:1.4rem">
                                    <i class="fas fa-user-circle"></i>
                                </div>
                                <div>
                                    <div class="font-weight-bold">{{ $b->nama }}</div>
                                    <div><i class="fas fa-phone mr-1 text-success"></i>{{ $b->telefon }}</div>
                                    @if ($b->alamat)
                                        <div class="text-muted small">
                                            <i class="fas fa-map-marker-alt mr-1"></i>{{ $b->alamat }}
                                        </div>
                                    @endif
                                </div>
                            </div>
                            @if (!$loop->last)
                                <hr class="my-2">
                            @endif
                        @endforeach
                    </div>
                </div>
            @endif

        </div>
    </div>

    {{-- Edit Modals --}}
    @foreach ($bantuans as $b)
        <div class="modal fade" id="editModal{{ $b->id }}" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form action="{{ route('admin.bantuan.update', $b) }}" method="POST">
                        @csrf
                        @method('PUT')
                        <div class="modal-header bg-warning">
                            <h5 class="modal-title"><i class="fas fa-edit mr-1"></i> Edit Entri Bantuan</h5>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                        </div>
                        <div class="modal-body">
                            <div class="form-group">
                                <label>Nama</label>
                                <input type="text" name="nama" class="form-control" value="{{ $b->nama }}"
                                    maxlength="100" required>
                            </div>
                            <div class="form-group">
                                <label>No. Telefon</label>
                                <input type="text" name="telefon" class="form-control" value="{{ $b->telefon }}"
                                    maxlength="20" required>
                            </div>
                            <div class="form-group">
                                <label>Alamat / Jawatan</label>
                                <input type="text" name="alamat" class="form-control" value="{{ $b->alamat }}"
                                    maxlength="300">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-warning btn-sm">
                                <i class="fas fa-save mr-1"></i> Simpan
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    @endforeach
@stop
