@extends('backend.master')

@section('title', 'Deposit Methods')

@section('content')
<div class="max-w-5xl mx-auto py-6">
    @if(session('success'))
        <div class="mb-4 rounded bg-emerald-50 border border-emerald-200 px-3 py-2 text-sm text-emerald-800">
            {{ session('success') }}
        </div>
    @endif

    <div class="grid md:grid-cols-2 gap-6">
        {{-- Mobile Banking --}}
        <div class="bg-white rounded-xl shadow p-4">
            <h2 class="font-bold mb-3">Mobile Banking Methods</h2>

            <form action="{{ route('admin.deposit-methods.mobile.store') }}" method="POST" class="space-y-2 mb-4">
                @csrf
                <div class="grid grid-cols-2 gap-2">
                    <input name="name" class="border rounded px-2 py-1 text-sm" placeholder="Name (bKash)">
                    <input name="slug" class="border rounded px-2 py-1 text-sm" placeholder="Slug (bkash)">
                    <input name="account_number" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Account / Agent Number">
                    <input name="logo" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Logo path or URL (optional)">
                    <input name="sort_order" class="border rounded px-2 py-1 text-sm" placeholder="Sort" type="number" min="0">
                </div>
                <button class="mt-2 px-3 py-1.5 text-xs rounded bg-sky-600 text-white">Add Mobile Method</button>
            </form>

            <table class="w-full text-xs border">
                <thead class="bg-slate-100">
                    <tr>
                        <th class="border px-2 py-1 text-left">Name</th>
                        <th class="border px-2 py-1">Number</th>
                        <th class="border px-2 py-1">Active</th>
                        <th class="border px-2 py-1">Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($mobileMethods as $m)
                        <tr>
                            <form action="{{ route('admin.deposit-methods.mobile.update', $m) }}" method="POST">
                                @csrf
                                @method('PATCH')
                                <td class="border px-1 py-1">
                                    <input name="name" value="{{ $m->name }}" class="w-full border rounded px-1 py-0.5">
                                    <input name="slug" value="{{ $m->slug }}" class="w-full border rounded px-1 py-0.5 mt-0.5 text-[11px] text-slate-500">
                                </td>
                                <td class="border px-1 py-1">
                                    <input name="account_number" value="{{ $m->account_number }}" class="w-full border rounded px-1 py-0.5 text-[11px]">
                                </td>
                                <td class="border px-1 py-1 text-center">
                                    <input type="checkbox" name="status" value="1" {{ $m->status ? 'checked' : '' }}>
                                </td>
                                <td class="border px-1 py-1">
                                    <div class="flex gap-1">
                                        <button class="px-2 py-0.5 text-[11px] rounded bg-emerald-600 text-white">Save</button>
                            </form>
                                        <form action="{{ route('admin.deposit-methods.mobile.destroy', $m) }}" method="POST" onsubmit="return confirm('Delete?')">
                                            @csrf
                                            @method('DELETE')
                                            <button class="px-2 py-0.5 text-[11px] rounded bg-rose-600 text-white">Del</button>
                                        </form>
                                    </div>
                                </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        {{-- Bank Methods --}}
        <div class="bg-white rounded-xl shadow p-4">
            <h2 class="font-bold mb-3">Bank Methods</h2>

            <form action="{{ route('admin.deposit-methods.bank.store') }}" method="POST" class="space-y-2 mb-4">
                @csrf
                <div class="grid grid-cols-2 gap-2">
                    <input name="bank_name" class="border rounded px-2 py-1 text-sm" placeholder="Bank Name">
                    <input name="slug" class="border rounded px-2 py-1 text-sm" placeholder="Slug (islami-bank)">
                    <input name="account_holder" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Account Holder">
                    <input name="account_number" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Account Number">
                    <input name="branch_name" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Branch Name">
                    <input name="logo" class="border rounded px-2 py-1 text-sm col-span-2" placeholder="Logo path or URL (optional)">
                    <input name="sort_order" class="border rounded px-2 py-1 text-sm" placeholder="Sort" type="number" min="0">
                </div>
                <button class="mt-2 px-3 py-1.5 text-xs rounded bg-sky-600 text-white">Add Bank Method</button>
            </form>

            <table class="w-full text-xs border">
                <thead class="bg-slate-100">
                    <tr>
                        <th class="border px-2 py-1 text-left">Bank</th>
                        <th class="border px-2 py-1">Account</th>
                        <th class="border px-2 py-1">Active</th>
                        <th class="border px-2 py-1">Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($bankMethods as $b)
                        <tr>
                            <form action="{{ route('admin.deposit-methods.bank.update', $b) }}" method="POST">
                                @csrf
                                @method('PATCH')
                                <td class="border px-1 py-1">
                                    <input name="bank_name" value="{{ $b->bank_name }}" class="w-full border rounded px-1 py-0.5">
                                    <input name="slug" value="{{ $b->slug }}" class="w-full border rounded px-1 py-0.5 mt-0.5 text-[11px] text-slate-500">
                                </td>
                                <td class="border px-1 py-1 text-[11px]">
                                    <input name="account_number" value="{{ $b->account_number }}" class="w-full border rounded px-1 py-0.5 mb-0.5">
                                    <input name="account_holder" value="{{ $b->account_holder }}" class="w-full border rounded px-1 py-0.5 mb-0.5">
                                    <input name="branch_name" value="{{ $b->branch_name }}" class="w-full border rounded px-1 py-0.5">
                                </td>
                                <td class="border px-1 py-1 text-center">
                                    <input type="checkbox" name="status" value="1" {{ $b->status ? 'checked' : '' }}>
                                </td>
                                <td class="border px-1 py-1">
                                    <div class="flex gap-1">
                                        <button class="px-2 py-0.5 text-[11px] rounded bg-emerald-600 text-white">Save</button>
                            </form>
                                        <form action="{{ route('admin.deposit-methods.bank.destroy', $b) }}" method="POST" onsubmit="return confirm('Delete?')">
                                            @csrf
                                            @method('DELETE')
                                            <button class="px-2 py-0.5 text-[11px] rounded bg-rose-600 text-white">Del</button>
                                        </form>
                                    </div>
                                </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
