<x-app-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between gap-4 rounded-2xl border border-sky-200/70 bg-gradient-to-r from-sky-50 to-green-50 px-5 py-4">
            <h2 class="text-xl font-semibold leading-tight text-sky-900">
                {{ __('Payment Methods') }}
            </h2>
            <a href="{{ route('admin.payment-methods.create') }}"
                class="inline-flex items-center rounded-lg bg-sky-600 px-4 py-2 font-semibold text-white transition hover:bg-sky-700">
                + {{ __('Add Payment Method') }}
            </a>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            @if ($message = Session::get('success'))
                <div class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 text-green-700">
                    {{ $message }}
                </div>
            @endif

            @if ($message = Session::get('error'))
                <div class="mb-4 rounded-lg border border-red-200 bg-red-50 p-4 text-red-700">
                    {{ $message }}
                </div>
            @endif

            <div class="overflow-hidden rounded-2xl border border-sky-200/70 bg-white shadow-sm">
                <div class="overflow-x-auto">
                    <table class="w-full">
                        <thead class="border-b border-sky-100 bg-sky-50/80">
                            <tr>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Name') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Provider') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Description') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Status') }}</th>
                                <th class="px-6 py-3 text-left text-sm font-semibold text-sky-800">{{ __('Actions') }}</th>
                            </tr>
                        </thead>
                        <tbody>
                            @forelse ($paymentMethods as $method)
                                <tr class="border-b border-sky-100 hover:bg-sky-50/40">
                                    <td class="px-6 py-4 whitespace-nowrap font-semibold">
                                        {{ $method->name }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        <span class="rounded-full bg-sky-100 px-3 py-1 text-xs font-semibold capitalize text-sky-800">
                                            {{ $method->provider }}
                                        </span>
                                    </td>
                                    <td class="px-6 py-4 text-sm text-gray-700">
                                        {{ $method->description ?? 'N/A' }}
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm">
                                        @if ($method->is_active)
                                            <span class="px-3 py-1 bg-green-100 text-green-800 rounded-full text-xs font-semibold">
                                                {{ __('Active') }}
                                            </span>
                                        @else
                                            <span class="px-3 py-1 bg-gray-100 text-gray-800 rounded-full text-xs font-semibold">
                                                {{ __('Inactive') }}
                                            </span>
                                        @endif
                                    </td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm space-x-2">
                                        <form action="{{ route('admin.payment-methods.test', $method) }}" method="POST" class="inline">
                                            @csrf
                                            <button type="submit"
                                                class="inline-block px-3 py-1 bg-green-600 text-white text-xs rounded hover:bg-green-700">
                                                {{ __('Test') }}
                                            </button>
                                        </form>
                                        <a href="{{ route('admin.payment-methods.edit', $method) }}"
                                            class="inline-block px-3 py-1 bg-yellow-600 text-white text-xs rounded hover:bg-yellow-700">
                                            {{ __('Edit') }}
                                        </a>
                                        <form action="{{ route('admin.payment-methods.destroy', $method) }}" method="POST" class="inline"
                                            onsubmit="return confirm('{{ __('Are you sure?') }}');">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit"
                                                class="px-3 py-1 bg-red-600 text-white text-xs rounded hover:bg-red-700">
                                                {{ __('Delete') }}
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @empty
                                <tr>
                                    <td colspan="5" class="px-6 py-4 text-center text-sky-700/80">
                                        {{ __('No payment methods configured') }}
                                    </td>
                                </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>

                @if ($paymentMethods->hasPages())
                    <div class="border-t border-sky-100 bg-sky-50/50 px-6 py-4">
                        {{ $paymentMethods->links() }}
                    </div>
                @endif
            </div>
        </div>
    </div>
</x-app-layout>
