@extends('layouts.app')

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

                <form method="GET" action="{{ route('admin.transaksi') }}" class="d-flex">
                    <input type="text" name="search" class="form-control form-control-sm me-2"
                        placeholder="Cari transaksi..." value="{{ request()->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>Nama Booking</th>
                            <th>Jumlah Pembayaran</th>
                            <th>Metode Pembayaran</th>
                            <th>Status Transaksi</th>
                            <th>Bukti Pembayaran</th>
                            <th>Tanggal Pembayaran</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($transaksi as $index => $item)
                            <tr>
                                <td>{{ $index + 1 }}</td>
                                <td>{{ $item->booking->user->name }} - Kamar {{ $item->booking->room->room_number }}</td>
                                <td>Rp {{ number_format((int) $item->jumlah_pembayaran, 0, ',', '.') }}</td>
                                <td>{{ $item->metode_pembayaran ?? 'Belum dipilih' }}</td>
                                <td>{{ ucfirst($item->status_transaksi) }}</td>
                                <td>
                                    @if($item->bukti_pembayaran)
                                        <a href="{{ asset($item->bukti_pembayaran) }}" target="_blank">Lihat</a>
                                    @else
                                        Belum diunggah
                                    @endif
                                </td>
                                <td>{{ \Carbon\Carbon::parse($item->tanggal_pembayaran)->format('d-m-Y H:i') }}</td>
                                <td>
                                    <a href="{{ route('admin.edittransaksi', ['id_transaksi' => $item->id_transaksi]) }}" method="POST" enctype="multipart/form-data" class="text-warning">
                                        <i class="bi bi-pencil-square"></i>
                                    </a>
                                    <a href="{{ route('admin.deletetransaksi', ['id_transaksi' => $item->id_transaksi]) }}" class="text-danger" onclick="return confirm('Apakah Anda yakin ingin menghapus transaksi ini?');">
                                        <i class="bi bi-trash-fill"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
