@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;">Edit Transaksi</h4>
            <form action="{{ route('admin.updatetransaksi', $transaksi->id_transaksi) }}" method="POST" enctype="multipart/form-data">
                @csrf

                <div class="mb-3">
                    <label for="id_booking" class="form-label">ID Booking</label>
                    <select name="id_booking" id="id_booking" class="form-control" required>
                        <option value="">Pilih Booking</option>
                        @foreach($bookings as $booking)
                            <option value="{{ $booking->id_booking }}" 
                                {{ $transaksi->id_booking == $booking->id_booking ? 'selected' : '' }}>
                                {{ $booking->id_booking }} - {{ $booking->user->name }} ({{ $booking->room->room_number }})
                            </option>
                        @endforeach
                    </select>
                </div>

                <div class="mb-3">
                    <label for="jumlah_pembayaran" class="form-label">Jumlah Pembayaran (Rp)</label>
                    <input type="number" name="jumlah_pembayaran" id="jumlah_pembayaran" class="form-control"
                           value="{{ $transaksi->jumlah_pembayaran }}" min="0" step="0.01" required>
                </div>

                <div class="mb-3">
                    <label for="metode_pembayaran" class="form-label">Metode Pembayaran</label>
                    <select name="metode_pembayaran" id="metode_pembayaran" class="form-control" required>
                        <option value="Transfer" {{ $transaksi->metode_pembayaran == 'Transfer' ? 'selected' : '' }}>Transfer</option>
                        <option value="E-Wallet" {{ $transaksi->metode_pembayaran == 'E-Wallet' ? 'selected' : '' }}>E-Wallet</option>
                        <option value="Tunai" {{ $transaksi->metode_pembayaran == 'Tunai' ? 'selected' : '' }}>Tunai</option>
                    </select>
                </div>

                <div class="mb-3">
                    <label for="status_transaksi" class="form-label">Status Transaksi</label>
                    <select name="status_transaksi" id="status_transaksi" class="form-control" required>
                        <option value="Belum Lunas" {{ $transaksi->status_transaksi == 'Belum Lunas' ? 'selected' : '' }}>Belum Lunas</option>
                        <option value="Lunas" {{ $transaksi->status_transaksi == 'Lunas' ? 'selected' : '' }}>Lunas</option>
                        <option value="Refund" {{ $transaksi->status_transaksi == 'Refund' ? 'selected' : '' }}>Refund</option>
                    </select>
                </div>

                <div class="mb-3">
                    <label for="bukti_pembayaran" class="form-label">Bukti Pembayaran</label>
                    <input type="file" class="form-control" id="bukti_pembayaran" name="bukti_pembayaran">
                    @if($transaksi->bukti_pembayaran)
                        <p class="mt-2">Bukti Pembayaran Sebelumnya: <a href="{{ asset( $transaksi->bukti_pembayaran) }}" target="_blank">Lihat</a></p>
                    @endif
                </div>

                <div class="mb-3">
                    <label for="tanggal_pembayaran" class="form-label">Tanggal Pembayaran</label>
                    <input type="datetime-local" name="tanggal_pembayaran" id="tanggal_pembayaran" class="form-control" 
                           value="{{ date('Y-m-d\TH:i', strtotime($transaksi->tanggal_pembayaran)) }}" required>
                </div>

                <div class="d-flex justify-content-between">
                    <a href="{{ route('admin.transaksi') }}" class="btn btn-secondary">Batal</a>
                    <button type="submit" class="btn text-white"
                            style="background: linear-gradient(135deg, #8AC0DF, #48499B);">
                        Update
                    </button>
                </div>
            </form>
        </div>
    </div>
@endsection
