@extends('layouts.app')

@section('content')
<!-- Background seluruh halaman -->
<div style="background-color: #e0e0e0; width: 100%; min-height: 100vh; border-radius: 15px; padding: 1rem;">

    <!-- Header -->
    <div style="background-color: #000; color: #fff; padding: 0.1rem; border-radius: 0.5rem;">
        <h1 class="m-0">Pengurus Masjid</h1>
    </div>

    <!-- Konten utama -->
    <div class="container mt-4">
        @if(session('success'))
            <div class="alert alert-success">{{ session('success') }}</div>
        @endif

        <div class="card p-4 border border-secondary" style="border-radius: 15px; background-color: #fff;">
            <div class="d-flex justify-content-between mb-3">
            <a href="{{ route('dashboard') }}" class="btn btn-secondary">Kembali</a>
            <!-- <a href="{{ route('pengurusmasjid.index') }}" class="btn btn-secondary">Kembali</a> -->

                @if(Auth::user()->tipe_pengguna !== 'anggota')
                    <a href="{{ route('pengurusmasjid.create') }}" class="btn btn-primary">Tambah Pengurus</a>
                @endif
            </div>

            <div class="table-responsive">
                <table class="table table-bordered table-hover mb-0">
                    <thead class="table-dark text-center">
                        <tr>
                            <th>Takmir</th>
                            <th>Bendahara</th>
                            <th>Sekretaris</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($pengurus as $data)
                            <tr>
                                <td>{{ $data->takmir }}</td>
                                <td>{{ $data->bendahara }}</td>
                                <td>{{ $data->sekretaris }}</td>
                                <td class="text-center">
                                    @if(Auth::user()->tipe_pengguna !== 'anggota')
                                        <a href="{{ route('pengurusmasjid.edit', $data->id) }}" class="btn btn-sm btn-warning">Edit</a>
                                        <form action="{{ route('pengurusmasjid.destroy', $data->id) }}" method="POST" class="d-inline" onsubmit="return confirm('Yakin ingin hapus?')">
                                            @csrf
                                            @method('DELETE')
                                            <button class="btn btn-sm btn-danger" type="submit">Hapus</button>
                                        </form>
                                    @else
                                        <span class="text-muted">-</span>
                                    @endif
                                </td>
                            </tr>
                        @endforeach

                        @if($pengurus->isEmpty())
                            <tr>
                                <td colspan="4" class="text-center text-muted">Belum ada data pengurus.</td>
                            </tr>
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
@endsection
