@extends('layouts.app')

@section('content')
<div class="container-fluid p-4">
    <div class="card shadow-sm p-4">
        <h3 class="fw-bold" style="text-align: center;">Data Pengeluaran</h3>
        <div class="d-flex justify-content-between mb-3">
            <a href="{{ route('admin.createexpense') }}" class="btn text-white" style="background: linear-gradient(135deg, #8AC0DF, #48499B); border: none;">
                <i class="bi bi-plus-circle"></i> Tambah Data
            </a>

            <!-- Form Pencarian -->
            <form action="{{ route('admin.expense') }}" method="GET" class="d-flex">
                <input type="text" name="search" class="form-control form-control-sm me-2" placeholder="Cari Data..." value="{{ request()->get('search') }}" style="max-width: 200px;">
                <button type="submit" class="btn btn-outline-secondary btn-sm">Cari</button>
            </form>
        </div>

        <div class="table-responsive">
            <table class="table table-bordered text-center">
                <thead class="table-primary">
                    <tr>
                        <th>No</th>
                        <th>Keterangan</th>
                        <th>Tanggal</th>
                        <th>Jumlah</th>
                        <th>Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @if(isset($pengeluaran) && count($pengeluaran) > 0)
                        @foreach($pengeluaran as $index => $item)
                        <tr>
                            <td>{{ $loop->iteration }}</td>
                            <td>{{ $item->keterangan }}</td>
                            <td>{{ \Carbon\Carbon::parse($item->tanggal_pengeluaran)->format('d M Y') }}</td>
                            <td>Rp {{ number_format($item->jumlah_pengeluaran, 0, ',', '.') }}</td>
                            <td>
                                <a href="{{ route('admin.editexpense', ['id_pengeluaran' => $item->id_pengeluaran]) }}" class="text-warning">
                                    <i class="bi bi-pencil-square"></i>
                                </a>
                                <a href="{{ route('admin.deleteexpense', ['id_pengeluaran' => $item->id_pengeluaran]) }}" class="text-danger" onclick="return confirm('Apakah Anda yakin ingin menghapus?');">
                                    <i class="bi bi-trash"></i>
                                </a>
                            </td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="5" class="text-center">Tidak ada data pengeluaran.</td>
                        </tr>
                    @endif
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
