@extends('admin.layouts.app')

@section('title', 'Proses Penarikan Dana')

@section('content')
<div class="bg-white shadow-md rounded-lg overflow-hidden">
    <div class="p-6">
        <div class="flex justify-between items-center mb-6">
            <h2 class="text-xl font-semibold text-gray-800">Proses Penarikan Dana #{{ $withdrawal['id'] }}</h2>
            <a href="{{ route('admin.withdrawals.pending') }}" class="bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-4 rounded">
                Kembali
            </a>
        </div>
        
        @if (session('error'))
            <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4" role="alert">
                <p>{{ session('error') }}</p>
            </div>
        @endif
        
        @if ($errors->any())
            <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-4">
                <ul class="list-disc pl-5">
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
        
        <div class="bg-gray-50 p-4 rounded-lg mb-6">
            <h3 class="font-semibold text-gray-700 mb-2">Detail Penarikan</h3>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <p class="text-sm text-gray-600">Nama Penjahit:</p>
                    <p class="font-medium">{{ $withdrawal['wallet']['user']['name'] }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600">Jumlah Penarikan:</p>
                    <p class="font-medium">Rp {{ number_format($withdrawal['amount'], 0, ',', '.') }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600">Bank:</p>
                    <p class="font-medium">{{ $withdrawal['bank_account']['bank_name'] }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600">Nomor Rekening:</p>
                    <p class="font-medium">{{ $withdrawal['bank_account']['account_number'] }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600">Atas Nama:</p>
                    <p class="font-medium">{{ $withdrawal['bank_account']['account_holder_name'] }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600">Tanggal Permintaan:</p>
                    <p class="font-medium">{{ \Carbon\Carbon::parse($withdrawal['created_at'])->format('d M Y H:i') }}</p>
                </div>
            </div>
        </div>
        
        <form action="{{ route('admin.withdrawals.process', $withdrawal['id']) }}" method="POST" enctype="multipart/form-data">
            @csrf
            
            <div class="mb-4">
                <label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status Penarikan</label>
                <select id="status" name="status" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500" required>
                    <option value="">Pilih Status</option>
                    <option value="completed">Selesaikan Pembayaran</option>
                    <option value="rejected">Tolak Penarikan</option>
                </select>
            </div>
            
            <div id="rejection_reason_container" class="mb-4 hidden">
                <label for="rejection_reason" class="block text-sm font-medium text-gray-700 mb-1">Alasan Penolakan</label>
                <textarea id="rejection_reason" name="rejection_reason" rows="3" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500"></textarea>
                <p class="text-sm text-gray-500 mt-1">Jelaskan alasan penolakan penarikan dana ini.</p>
            </div>
            
            <div id="proof_of_payment_container" class="mb-4 hidden">
                <label for="proof_of_payment" class="block text-sm font-medium text-gray-700 mb-1">Bukti Pembayaran</label>
                <input type="file" id="proof_of_payment" name="proof_of_payment" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500" accept="image/jpeg,image/png,image/jpg,application/pdf">
                <p class="text-sm text-gray-500 mt-1">Unggah bukti pembayaran (JPEG, PNG, PDF, maks. 2MB).</p>
            </div>
            
            <div class="mt-6">
                <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
                    Simpan
                </button>
            </div>
        </form>
    </div>
</div>

@push('scripts')
<script>
    $(document).ready(function() {
        $('#status').change(function() {
            const status = $(this).val();
            
            if (status === 'rejected') {
                $('#rejection_reason_container').removeClass('hidden');
                $('#proof_of_payment_container').addClass('hidden');
                $('#proof_of_payment').removeAttr('required');
                $('#rejection_reason').attr('required', 'required');
            } else if (status === 'completed') {
                $('#rejection_reason_container').addClass('hidden');
                $('#proof_of_payment_container').removeClass('hidden');
                $('#rejection_reason').removeAttr('required');
                $('#proof_of_payment').attr('required', 'required');
            } else {
                $('#rejection_reason_container').addClass('hidden');
                $('#proof_of_payment_container').addClass('hidden');
                $('#rejection_reason').removeAttr('required');
                $('#proof_of_payment').removeAttr('required');
            }
        });
    });
</script>
@endpush
@endsection 