@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Customers.Management', __('Customer Management')))

@section('content')
<div class="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 py-8 px-4 md:px-8">
    <div class="max-w-7xl mx-auto">
        <div class="mb-8">
            <div class="flex items-center justify-between mb-6 flex-wrap gap-3">
                <div>
                    <h1 class="text-3xl font-bold text-gray-900 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Management', __('Customer Management')) }}</h1>
                    <p class="text-gray-600">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Subtitle', __('Manage and update customer information, contracts and invoices')) }}</p>
                </div>
                <div class="flex gap-2 flex-wrap">
                    @can('viewAny', App\Models\Customer::class)
                    <a href="{{ route('customers.export.excel') }}" class="inline-flex items-center px-4 py-3 bg-gradient-to-r from-green-500 to-green-600 text-white font-semibold rounded-lg hover:from-green-600 hover:to-green-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('General.ExportExcel', __('Export to Excel')) }}">
                        <i class="fas fa-file-excel ml-2"></i>
                        <span>Excel</span>
                    </a>
                    <a href="{{ route('customers.export.pdf') }}" class="inline-flex items-center px-4 py-3 bg-gradient-to-r from-red-500 to-red-600 text-white font-semibold rounded-lg hover:from-red-600 hover:to-red-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.ExportPDF', __('Export to PDF')) }}">
                        <i class="fas fa-file-pdf ml-2"></i>
                        <span>PDF</span>
                    </a>
                    @endcan
                    @can('create', App\Models\Customer::class)
                    <a href="{{ route('customers.import.show') }}" class="inline-flex items-center px-4 py-3 bg-gradient-to-r from-purple-500 to-purple-600 text-white font-semibold rounded-lg hover:from-purple-600 hover:to-purple-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.ImportExcel', __('Import from Excel')) }}">
                        <i class="fas fa-download ml-2"></i>
                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Import', __('Import')) }}</span>
                    </a>
                    <a href="{{ route('customers.create') }}" class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-semibold rounded-lg hover:from-blue-700 hover:to-blue-800 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105">
                        <i class="fas fa-plus ml-2"></i>
                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.AddNew', __('Add New Customer')) }}</span>
                    </a>
                    @endcan
                </div>
            </div>

            @if(session('success'))
            <div class="bg-green-50 border-l-4 border-green-500 p-4 mb-6 rounded-r-lg">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-check-circle text-green-500 text-xl"></i>
                    </div>
                    <div class="mr-3">
                        <p class="text-green-700 font-medium">{{ session('success') }}</p>
                    </div>
                </div>
            </div>
            @endif
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead class="bg-gradient-to-r from-gray-800 to-gray-900 text-white">
                        <tr>
                            <th class="px-6 py-4 text-right font-semibold text-sm">#</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Name', __('Customer Name')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.ContactPerson', __('Contact Person')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Email', __('Email')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Phone', __('Phone')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Type', __('Customer Type')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Category', __('Category')) }}</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Status', __('Status')) }}</th>
                            <th class="px-6 py-4 text-center font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Actions', __('Actions')) }}</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        @forelse($customers as $customer)
                        <tr class="hover:bg-blue-50 transition-colors duration-150 border-b border-gray-100">
                            <td class="px-6 py-4 text-gray-600 font-medium">{{ $loop->iteration }}</td>
                            <td class="px-6 py-4">
                                <div class="font-semibold text-gray-900">{{ $customer->name }}</div>
                            </td>
                            <td class="px-6 py-4 text-gray-700">{{ $customer->contact_person }}</td>
                            <td class="px-6 py-4 text-gray-700">
                                <a href="mailto:{{ $customer->email }}" class="text-blue-600 hover:text-blue-800 underline">
                                    {{ $customer->email }}
                                </a>
                            </td>
                            <td class="px-6 py-4 text-gray-700">
                                <a href="tel:{{ $customer->phone }}" class="text-blue-600 hover:text-blue-800 underline">
                                    {{ $customer->phone }}
                                </a>
                            </td>
                            <td class="px-6 py-4">
                                @if($customer->customer_type == 'individual')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-indigo-100 text-indigo-700">
                                    <i class="fas fa-user ml-1"></i>
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Individual', __('Individual')) }}
                                </span>
                                @else
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-700">
                                    <i class="fas fa-building ml-1"></i>
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Company', __('Company')) }}
                                </span>
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                @if($customer->category)
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-50 text-blue-700 border border-blue-200">
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.Category.' . Str::studly($customer->category), __($customer->category)) }}
                                </span>
                                @else
                                <span class="text-gray-400 text-sm">-</span>
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                @if($customer->status == 'active')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-700">
                                    <span class="w-2 h-2 bg-green-500 rounded-full ml-2"></span>
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Status.Active', __('Active')) }}
                                </span>
                                @else
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-700">
                                    <span class="w-2 h-2 bg-red-500 rounded-full ml-2"></span>
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Status.Inactive', __('Inactive')) }}
                                </span>
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                <div class="flex items-center justify-center gap-1">
                                    @can('view', $customer)
                                    <a href="{{ route('customers.show', $customer) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-blue-100 text-blue-600 hover:bg-blue-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.ViewDetails', __('View Details')) }}">
                                        <i class="fas fa-eye mr-1"></i>
                                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('General.View', __('View')) }}</span>
                                    </a>
                                    @endcan

                                    @can('update', $customer)
                                    <a href="{{ route('customers.edit', $customer) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-amber-100 text-amber-600 hover:bg-amber-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Edit', __('Edit')) }}">
                                        <i class="fas fa-edit mr-1"></i>
                                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Edit', __('Edit')) }}</span>
                                    </a>
                                    @endcan

                                    @can('delete', $customer)
                                    <form action="{{ route('customers.destroy', $customer) }}" method="POST" class="inline">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="inline-flex items-center px-3 py-2 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Delete', __('Delete')) }}" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.DeleteConfirm', __('Are you sure you want to delete this customer?')) }}')">
                                            <i class="fas fa-trash mr-1"></i>
                                            <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('General.Delete', __('Delete')) }}</span>
                                        </button>
                                    </form>
                                    @endcan
                                </div>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="8" class="px-6 py-12 text-center">
                                <div class="flex flex-col items-center justify-center">
                                    <i class="fas fa-inbox text-gray-400 text-4xl mb-3"></i>
                                    <p class="text-gray-600 font-medium">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.NoCustomersFound', __('No customers found')) }}</p>
                                    <p class="text-gray-500 text-sm mt-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Customers.StartAdding', __('Start by adding a new customer')) }}</p>
                                </div>
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="px-6 py-4 bg-gray-50 border-t border-gray-200">
                <div class="flex justify-center">
                    {{ $customers->links() }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
