@extends('layouts.app')

@section('title', '계좌 상세 - ' . $account->bank_name)

@section('content')
<div class="container mx-auto px-4 py-6">
    {{-- 페이지 헤더 --}}
    <div class="flex flex-col lg:flex-row lg:justify-between lg:items-start gap-4 mb-6">
        <div>
            <a href="{{ route('finance.accounts.index') }}" class="text-sm text-gray-500 hover:text-gray-700 inline-flex items-center gap-1 mb-2">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                </svg>
                계좌 목록으로
            </a>
            <h1 class="text-2xl font-bold text-gray-800">{{ $account->bank_name }}</h1>
            <p class="text-sm text-gray-500 mt-1">{{ $account->account_number }} · {{ $account->account_type }}</p>
        </div>
        <div class="flex flex-wrap items-center gap-2">
            <a href="{{ route('finance.accounts.edit', $account->id) }}"
               class="inline-flex items-center gap-2 px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
                </svg>
                수정
            </a>
        </div>
    </div>

    {{-- 계좌 정보 카드 --}}
    <div class="bg-white rounded-lg shadow-sm p-6 mb-6">
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <div>
                <div class="text-sm text-gray-500">현재 잔액</div>
                <div class="text-3xl font-bold text-emerald-600">{{ $account->formatted_balance }}</div>
            </div>
            <div>
                <div class="text-sm text-gray-500">예금주</div>
                <div class="text-lg font-medium text-gray-900">{{ $account->account_holder ?? '-' }}</div>
            </div>
            <div>
                <div class="text-sm text-gray-500">개설일자</div>
                <div class="text-lg font-medium text-gray-900">{{ $account->opened_at?->format('Y-m-d') ?? '-' }}</div>
            </div>
        </div>
        @if($account->memo)
        <div class="mt-4 pt-4 border-t">
            <div class="text-sm text-gray-500">메모</div>
            <div class="text-gray-700">{{ $account->memo }}</div>
        </div>
        @endif
    </div>

    {{-- 거래내역 --}}
    <div class="bg-white rounded-lg shadow-sm overflow-hidden">
        <div class="px-6 py-4 border-b border-gray-200 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
            <h2 class="text-lg font-semibold text-gray-800">거래내역</h2>

            {{-- 필터 --}}
            <form id="transactionFilterForm" class="flex flex-col sm:flex-row gap-2 sm:gap-3">
                <input type="date" name="start_date" placeholder="시작일"
                       class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
                <input type="date" name="end_date" placeholder="종료일"
                       class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
                <select name="transaction_type" class="px-3 py-2 border border-gray-300 rounded-lg text-sm">
                    <option value="">전체</option>
                    <option value="deposit">입금</option>
                    <option value="withdrawal">출금</option>
                    <option value="transfer">이체</option>
                </select>
                <button type="submit"
                        hx-get="{{ route('api.admin.bank-accounts.transactions', $account->id) }}"
                        hx-target="#transactions-table"
                        hx-include="#transactionFilterForm"
                        class="px-4 py-2 bg-gray-600 hover:bg-gray-700 text-white text-sm rounded-lg">
                    조회
                </button>
            </form>
        </div>

        {{-- 거래내역 테이블 --}}
        <div id="transactions-table"
             hx-get="{{ route('api.admin.bank-accounts.transactions', $account->id) }}"
             hx-trigger="load"
             hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
             class="min-h-[200px]">
            <div class="flex justify-center items-center p-12">
                <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-emerald-600"></div>
            </div>
        </div>
    </div>
</div>
@endsection
