<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-l text-gray-800 leading-tight">
                {{ \App\Helpers\TranslationHelper::transFromDatabase('Cost Center Types', __('Cost Center Types')) }}
            </h2>
            <div>
                @if (auth()->user()->can('accounting.cost-center-types.create'))
                    <a href="{{ route('accounting.cost-center-types.create') }}" class="inline-flex items-center p-4 py-2 bg-blue-600 border border-transparent rounded-md font-semibold text-s text-white uppercase tracking-widest hover:bg-blue-700 focus:bg-blue-700 active:bg-blue-800 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150">
                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Add New Type', __('Add New Type')) }}
                    </a>
                @endif
            </div>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7l m-auto sm:p-6 lg:p-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    @if (session('success'))
                        <div class="bg-green-100 border border-green-400 text-green-700 p-4 py-3 rounded relative mb-4" role="alert">
                            <span class="block sm:inline">{{ session('success') }}</span>
                        </div>
                    @endif

                    @if (session('error'))
                        <div class="bg-red-100 border border-red-400 text-red-700 p-4 py-3 rounded relative mb-4" role="alert">
                            <span class="block sm:inline">{{ session('error') }}</span>
                        </div>
                    @endif

                    <div class="overflow-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Code', __('Code')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Name', __('Name')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Arabic Name', __('Arabic Name')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Status', __('Status')) }}
                                    </th>
                                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Actions', __('Actions')) }}
                                    </th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                @forelse ($types as $type)
                                    <tr>
                                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
                                            {{ $type->code }}
                                        </td>
                                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                            {{ $type->name }}
                                        </td>
                                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                            {{ $type->name_ar }}
                                        </td>
                                        <td class="p-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                            @if ($type->status === 'active')
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-green-100 text-green-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Active', __('Active')) }}
                                                </span>
                                            @else
                                                <span class="inline-flex items-center p-2.5 py-0.5 rounded-full text-s font-medium bg-red-100 text-red-800">
                                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Inactive', __('Inactive')) }}
                                                </span>
                                            @endif
                                        </td>
                                        <td class="p-6 py-4 whitespace-nowrap text-sm font-medium">
                                            <div class="flex space-y-2 space-y-reverse">
                                                @if (auth()->user()->can('accounting.cost-center-types.view'))
                                                    <a href="{{ route('accounting.cost-center-types.show', $type) }}" class="text-indigo-600 hover:text-indigo-900 ml-3">
                                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                                                            <path d="M10 12a2 2 0 100-4 2 2 0 000 4z" />
                                                            <path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd" />
                                                        </svg>
                                                    </a>
                                                @endif
                                                @if (auth()->user()->can('accounting.cost-center-types.edit'))
                                                    <a href="{{ route('accounting.cost-center-types.edit', $type) }}" class="text-yellow-600 hover:text-yellow-900 ml-3">
                                                        <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                                                            <path d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z" />
                                                        </svg>
                                                    </a>
                                                @endif
                                                @if (auth()->user()->can('accounting.cost-center-types.delete'))
                                                    <form action="{{ route('accounting.cost-center-types.destroy', $type) }}" method="POST" class="inline-block">
                                                        @csrf
                                                        @method('DELETE')
                                                        <button type="submit" class="text-red-600 hover:text-red-900 ml-3" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure you want to delete this type?', __('Are you sure you want to delete this type?')) }}')">
                                                            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                                                                <path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
                                                            </svg>
                                                        </button>
                                                    </form>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="5" class="p-6 py-4 whitespace-nowrap text-sm text-gray-500 text-center">
                                            {{ \App\Helpers\TranslationHelper::transFromDatabase('No cost center types added', __('No cost center types added')) }}
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
