<?php
/*
 * This file is part of the CLIENTXCMS project.
 * It is the property of the CLIENTXCMS association.
 *
 * Personal and non-commercial use of this source code is permitted.
 * However, any use in a project that generates profit (directly or indirectly),
 * or any reuse for commercial purposes, requires prior authorization from CLIENTXCMS.
 *
 * To request permission or for more information, please contact our support:
 * https://clientxcms.com/client/support
 *
 * Learn more about CLIENTXCMS License at:
 * https://clientxcms.com/eula
 *
 * Year: 2025
 */
?>


<div class="card">
    <div class="card-heading">
        <div>
            <h2 class="text-xl font-semibold text-gray-800 dark:text-gray-200">
                {{ __('client.payment-methods.index') }}
            </h2>
            <p class="text-sm text-gray-600 dark:text-gray-400">
                {{ __('client.payment-methods.index_description') }}
            </p>
        </div>

        <div>

            @if(isset($count) && $count > 3)
                <a class="py-1 px-4 inline-flex gap-x-1 text-sm font-semibold rounded-lg border border-transparent text-blue-600 hover:text-blue-800 disabled:opacity-50 disabled:pointer-events-none dark:text-blue-500 dark:hover:text-blue-400 dark:focus:outline-none dark:focus:ring-1 dark:focus:ring-gray-600" href="{{ route('front.invoices.index') }}">
                    {{ __('global.seemore') }}
                    <svg class="flex-shrink-0 w-4 h-4 mt-0.5" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
                </a>
            @endif
            </div>
        </div>
    <div class="border rounded-lg overflow-hidden dark:border-gray-700">
        <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
            <thead>
            <tr>
                <th scope="col" class="px-6 py-3 text-start">
                    <div class="flex items-center gap-x-2">
                    <span class="text-xs font-semibold uppercase tracking-wide text-gray-800 dark:text-gray-200">
                      {{ __('client.payment-methods.paymentmethod') }}
                    </span>
                    </div>
                </th>

                <th scope="col" class="px-6 py-3 text-start">
                    <div class="flex items-center gap-x-2">
                    <span class="text-xs font-semibold uppercase tracking-wide text-gray-800 dark:text-gray-200">
                      {{ __('client.payment-methods.expiration') }}
                    </span>
                    </div>
                </th>

                <th scope="col" class="px-6 py-3 text-start">
                    <div class="flex items-center gap-x-2">
                    <span class="text-xs font-semibold uppercase tracking-wide text-gray-800 dark:text-gray-200">
                      {{ __('client.payment-methods.default') }}
                    </span>
                    </div>
                </th>
                <th scope="col" class="px-6 py-3 text-start">
                    <div class="flex items-center gap-x-2">
                    <span class="text-xs font-semibold uppercase tracking-wide text-gray-800 dark:text-gray-200">
                      {{ __('global.actions') }}
                    </span>
                    </div>
                </th>

            </tr>
            </thead>

            <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
            @if (count($sources) == 0)
                <tr class="bg-white hover:bg-gray-50 dark:bg-slate-900 dark:hover:bg-slate-800">
                    <td colspan="56" class="px-6 py-4 whitespace-nowrap text-center">
                        <div class="flex flex-auto flex-col justify-center items-center p-2 md:p-3">
                            <p class="text-sm text-gray-800 dark:text-gray-400">
                                {{ __('global.no_results') }}
                            </p>
                        </div>
                    </td>
                </tr>
            @endif
            @foreach($sources as $i => $source)
                <tr class="bg-white hover:bg-gray-50 dark:bg-slate-900 dark:hover:bg-slate-800">
                    @if ($source->gateway_uuid == 'paypal_express_checkout')
                        <td class="h-px w-px whitespace-nowrap">
            <span class="block px-6 py-2">
                <span class="block text-sm font-medium text-gray-800 dark:text-neutral-200">
                    <i class="bi bi-paypal"></i> {{ $source->email }}
                </span>
            </span>
                        </td>
                    @else
                        <td class="h-px w-px whitespace-nowrap">
            <span class="block px-6 py-2">
                <span class="block text-sm font-medium text-gray-800 dark:text-neutral-200">
                    •••• {{ $source->last4 ?? $source->email }}
                </span>
            </span>
                        </td>
                    @endif

                        <td class="h-px w-px whitespace-nowrap">
            <span class="block px-6 py-2">
                <span class="text-sm text-gray-600 dark:text-gray-400">
                    {{ $source->exp_month . '/' . $source->exp_year }}
                </span>
            </span>
                        </td>

                    <td class="h-px w-px whitespace-nowrap">
                        @if ($source->isDefault())
                            <span class="py-1 px-2 inline-flex items-center gap-x-1 text-xs font-medium bg-teal-100 text-teal-800 rounded-full dark:bg-teal-500/10 dark:text-teal-500">
                <svg class="flex-shrink-0 w-3 h-3" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z"/>
                    <path d="m9 12 2 2 4-4"/>
                </svg>
                {{ __('global.yes') }}
            </span>
                        @else
                            <span class="py-1 px-2 inline-flex items-center gap-x-1 text-xs font-medium bg-red-100 text-red-800 rounded-full dark:bg-red-500/10 dark:text-red-500">
                <svg class="flex-shrink-0 w-3 h-3" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <circle cx="12" cy="12" r="10"/>
                    <path d="m15 9-6 6"/>
                    <path d="m9 9 6 6"/>
                </svg>
                {{ __('global.no') }}
            </span>
                        @endif
                    </td>

                    <td class="h-px w-px whitespace-nowrap">
                        <div class="flex">
                        @if (!$source->isDefault())
                                        <form action="{{ route('front.payment-methods.default', ['paymentMethod' => $source->id]) }}" method="POST">
                                            @csrf
                                            <button>
                                          <span class="py-1 px-2 inline-flex mr-2 justify-center items-center gap-2 rounded-lg border font-medium bg-slate text-slate-700 shadow-sm align-middle hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white focus:ring-blue-600 transition-all text-sm dark:bg-slate-900 dark:hover:bg-slate-800 dark:border-slate-700 dark:text-white dark:hover:text-white dark:focus:ring-offset-gray-800">
                                                <i class="bi bi-sliders2-vertical"></i>

                                                {{ __('client.payment-methods.set_default') }}
                                          </span>
                                            </button>
                                        </form>
                                    @endif
                                    <form action="{{ route('front.payment-methods.delete', ['paymentMethod' => $source->id]) }}" method="POST">
                                        @csrf
                                        @method('DELETE')
                                        <button>
                                          <span class="py-1 px-2 inline-flex justify-center items-center gap-2 rounded-lg border font-medium bg-red text-red-700 shadow-sm align-middle hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white focus:ring-blue-600 transition-all text-sm dark:bg-red-900 dark:hover:bg-red-800 dark:border-red-700 dark:text-white dark:hover:text-white dark:focus:ring-offset-gray-800">
                                                <i class="bi bi-trash"></i>
                                            {{ __('global.delete') }}
                                          </span>
                                        </button>
                                    </form>
                        </div>

                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>
