@extends('layouts.admin', ['heading' => 'Payment Gateways', 'subheading' => 'Configure and enable gateways'])

@section('content')
    <div class="admin-card p-5">
        <div class="overflow-x-auto">
            <table class="min-w-full text-sm">
                <thead class="bg-slate-100 text-left">
                    <tr>
                        <th class="p-3">Gateway</th>
                        <th class="p-3">Status</th>
                        <th class="p-3">Config (JSON)</th>
                        <th class="p-3">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($gateways as $gateway)
                        <tr class="border-t">
                            <td class="p-3">
                                <div class="font-semibold">{{ $gateway->name }}</div>
                                <div class="text-xs text-slate-500">{{ $gateway->code }}</div>
                            </td>
                            <td class="p-3">
                                <span class="admin-badge {{ $gateway->is_enabled ? 'success' : 'danger' }}">
                                    {{ $gateway->is_enabled ? 'Enabled' : 'Disabled' }}
                                </span>
                            </td>
                            <td class="p-3">
                                <form method="POST" action="{{ route('admin.payments.gateways.update', $gateway) }}" class="space-y-2">
                                    @csrf
                                    <input name="name" value="{{ $gateway->name }}" class="w-full rounded border p-2 text-xs">
                                    <textarea name="config_json" rows="5" class="w-full rounded border p-2 text-xs" placeholder='{"key":"...","secret":"..."}'>{{ $gateway->config_json ? json_encode($gateway->config_json, JSON_PRETTY_PRINT) : '' }}</textarea>
                                    <button class="rounded bg-slate-900 px-2 py-1 text-xs text-white">Save</button>
                                </form>
                            </td>
                            <td class="p-3">
                                <form method="POST" action="{{ route('admin.payments.gateways.toggle', $gateway) }}">
                                    @csrf
                                    <button class="rounded bg-amber-600 px-3 py-1 text-xs text-white">
                                        {{ $gateway->is_enabled ? 'Disable' : 'Enable' }}
                                    </button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
@endsection
