@extends('admin.layouts.app')

@section('title', 'Detail Akun Bank | TailorHub Admin')

@section('content')
<div class="container px-6 mx-auto grid">
    <div class="flex justify-between items-center my-6">
        <h2 class="text-2xl font-semibold text-gray-700">
            Detail Akun Bank
        </h2>
        <a href="{{ url()->previous() }}" class="px-4 py-2 bg-gray-600 text-white rounded-md hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2">
            Kembali
        </a>
    </div>

    <!-- Alert Status -->
    @if (session('success'))
    <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-6 rounded" role="alert">
        <p>{{ session('success') }}</p>
    </div>
    @endif

    @if (session('error'))
    <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 mb-6 rounded" role="alert">
        <p>{{ session('error') }}</p>
    </div>
    @endif

    <!-- Informasi Akun Bank -->
    <div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
        <div class="p-6 border-b border-gray-200">
            <h3 class="text-lg font-medium text-gray-900">Informasi Akun Bank</h3>
        </div>
        <div class="p-6">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h4 class="font-medium text-gray-700 mb-2">Data Penjahit</h4>
                    <div class="bg-gray-100 p-4 rounded-lg">
                        <p class="mb-2"><span class="font-semibold">Nama:</span> {{ $bankAccount['user']['name'] }}</p>
                        <p class="mb-2"><span class="font-semibold">Email:</span> {{ $bankAccount['user']['email'] }}</p>
                        <p><span class="font-semibold">No. Telepon:</span> {{ $bankAccount['user']['phone_number'] ?? '-' }}</p>
                    </div>
                </div>
                <div>
                    <h4 class="font-medium text-gray-700 mb-2">Data Rekening</h4>
                    <div class="bg-gray-100 p-4 rounded-lg">
                        <p class="mb-2"><span class="font-semibold">Nama Bank:</span> {{ $bankAccount['bank_name'] }}</p>
                        <p class="mb-2"><span class="font-semibold">Nomor Rekening:</span> {{ $bankAccount['account_number'] }}</p>
                        <p class="mb-2"><span class="font-semibold">Nama Pemilik:</span> {{ $bankAccount['account_holder_name'] }}</p>
                        <p class="mb-2">
                            <span class="font-semibold">Status:</span> 
                            @if ($bankAccount['status'] == 'active')
                            <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full">Diterima</span>
                            @elseif ($bankAccount['status'] == 'rejected')
                            <span class="px-2 py-1 font-semibold leading-tight text-red-700 bg-red-100 rounded-full">Ditolak</span>
                            @else
                            <span class="px-2 py-1 font-semibold leading-tight text-gray-700 bg-gray-100 rounded-full">{{ $bankAccount['status'] }}</span>
                            @endif
                        </p>
                        @if ($bankAccount['status'] == 'rejected' && $bankAccount['rejection_reason'])
                        <p class="mt-2"><span class="font-semibold">Alasan Penolakan:</span> {{ $bankAccount['rejection_reason'] }}</p>
                        @endif
                        <p class="mt-2"><span class="font-semibold">Tanggal Verifikasi:</span> {{ \Carbon\Carbon::parse($bankAccount['verified_at'])->format('d M Y H:i') }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Riwayat Penarikan -->
    <div class="bg-white rounded-lg shadow-md overflow-hidden">
        <div class="p-6 border-b border-gray-200">
            <h3 class="text-lg font-medium text-gray-900">Riwayat Penarikan</h3>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full whitespace-no-wrap">
                <thead>
                    <tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b bg-gray-50">
                        <th class="px-4 py-3">ID</th>
                        <th class="px-4 py-3">Jumlah</th>
                        <th class="px-4 py-3">Status</th>
                        <th class="px-4 py-3">Bukti Pembayaran</th>
                        <th class="px-4 py-3">Tanggal Diproses</th>
                        <th class="px-4 py-3">Tanggal Dibuat</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y">
                    @forelse ($bankAccount['withdrawals'] ?? [] as $withdrawal)
                    <tr class="text-gray-700">
                        <td class="px-4 py-3 text-sm">
                            {{ $withdrawal['id'] }}
                        </td>
                        <td class="px-4 py-3 text-sm">
                            Rp {{ number_format($withdrawal['amount'], 0, ',', '.') }}
                        </td>
                        <td class="px-4 py-3 text-sm">
                            @if ($withdrawal['status'] == 'pending')
                            <span class="px-2 py-1 font-semibold leading-tight text-yellow-700 bg-yellow-100 rounded-full">
                                Menunggu
                            </span>
                            @elseif ($withdrawal['status'] == 'processing')
                            <span class="px-2 py-1 font-semibold leading-tight text-blue-700 bg-blue-100 rounded-full">
                                Diproses
                            </span>
                            @elseif ($withdrawal['status'] == 'completed')
                            <span class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full">
                                Selesai
                            </span>
                            @elseif ($withdrawal['status'] == 'rejected')
                            <span class="px-2 py-1 font-semibold leading-tight text-red-700 bg-red-100 rounded-full" title="{{ $withdrawal['rejection_reason'] }}">
                                Ditolak
                            </span>
                            @else
                            <span class="px-2 py-1 font-semibold leading-tight text-gray-700 bg-gray-100 rounded-full">
                                {{ $withdrawal['status'] }}
                            </span>
                            @endif
                        </td>
                        <td class="px-4 py-3 text-sm">
                            @if ($withdrawal['proof_of_payment'])
                            <a href="{{ config('api.url') }}/storage/{{ $withdrawal['proof_of_payment'] }}" target="_blank" class="text-blue-600 hover:underline">
                                Lihat Bukti
                            </a>
                            @else
                            -
                            @endif
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{ $withdrawal['processed_at'] ? \Carbon\Carbon::parse($withdrawal['processed_at'])->format('d M Y H:i') : '-' }}
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{ \Carbon\Carbon::parse($withdrawal['created_at'])->format('d M Y H:i') }}
                        </td>
                    </tr>
                    @empty
                    <tr class="text-gray-700">
                        <td colspan="6" class="px-4 py-3 text-sm text-center">
                            Tidak ada riwayat penarikan untuk akun bank ini.
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection 