<x-admin-layout>
    <x-slot name="header">
        {{ __('Daftar Testimoni') }}
    </x-slot>

    <div class="flex justify-end mb-4">
        <a href="{{ route('admin.testimonials.create') }}" class="inline-flex items-center px-4 py-2 border border-transparent rounded-lg shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors">
            <x-heroicon-o-plus class="-ml-1 mr-2 h-5 w-5" />
            Tambah Testimoni
        </a>
    </div>

    <!-- Table Section -->
    <div class="bg-white dark:bg-slate-800 rounded-2xl shadow-sm border border-gray-100 dark:border-slate-700 overflow-hidden">
        <div class="px-6 py-5 border-b border-gray-100 dark:border-slate-700 flex flex-col sm:flex-row justify-between items-center gap-4">
            <h3 class="font-semibold text-gray-800 dark:text-gray-100">Daftar Testimoni</h3>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full text-sm text-left whitespace-nowrap">
                <thead class="text-xs text-gray-500 dark:text-gray-400 uppercase bg-gray-50 dark:bg-slate-700/50 border-b border-gray-100 dark:border-slate-700">
                    <tr>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider">User</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider">Rating</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider">Produk</th>
                        <th scope="col" class="px-6 py-4 font-medium tracking-wider text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100 dark:divide-slate-700 bg-white dark:bg-slate-800">
                    @forelse ($testimonials as $testimonial)
                    <tr class="hover:bg-gray-50 dark:hover:bg-slate-700/50 transition-colors">
                        <td class="px-6 py-4">
                            <div class="flex items-center">
                                <div class="flex-shrink-0 h-10 w-10 flex items-center justify-center rounded-full bg-indigo-100 dark:bg-slate-700 mr-4 overflow-hidden border border-gray-200 dark:border-slate-700">
                                    @if($testimonial->avatar)
                                        <img src="{{ Storage::url($testimonial->avatar) }}" alt="{{ $testimonial->name }}" class="h-full w-full object-cover">
                                    @else
                                        <span class="text-indigo-600 dark:text-indigo-400 font-bold text-sm">{{ substr($testimonial->name, 0, 2) }}</span>
                                    @endif
                                </div>
                                <div>
                                    <div class="font-medium text-gray-900 dark:text-white">{{ $testimonial->name }}</div>
                                    <div class="text-xs text-gray-500 truncate max-w-[200px]">{{ str($testimonial->content)->limit(40) }}</div>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            <div class="flex text-yellow-400">
                                @for($i=1; $i<=5; $i++)
                                    @if($i <= $testimonial->rating)
                                    <x-heroicon-s-star class="w-4 h-4" />
                                    @else
                                    <x-heroicon-o-star class="w-4 h-4 text-gray-300 dark:text-slate-600" />
                                    @endif
                                @endfor
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            @if($testimonial->product)
                                <span class="inline-flex items-center px-2.5 py-0.5 rounded-md text-xs font-medium bg-gray-100 dark:bg-slate-700 text-gray-800 dark:text-gray-100">
                                    {{ $testimonial->product->name }}
                                </span>
                            @else
                                <span class="text-red-500 text-xs">Produk Dihapus</span>
                            @endif
                        </td>
                        <td class="px-6 py-4 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{{ route('admin.testimonials.edit', $testimonial) }}" class="p-2 text-gray-400 hover:text-indigo-600 dark:hover:text-indigo-400 rounded-lg transition-colors" title="Edit">
                                    <x-heroicon-o-pencil-square class="w-5 h-5" />
                                </a>
                                <form action="{{ route('admin.testimonials.destroy', $testimonial) }}" method="POST" data-confirm="Hapus testimoni ini secara permanen?" class="inline-block">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="p-2 text-gray-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30 rounded-lg transition-colors" title="Delete">
                                        <x-heroicon-o-trash class="w-5 h-5" />
                                    </button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="4" class="px-6 py-12 text-center text-gray-500 dark:text-gray-400">
                            <div class="flex flex-col items-center justify-center">
                                <div class="w-16 h-16 rounded-full bg-gray-100 dark:bg-slate-700 flex items-center justify-center mb-4 text-gray-400">
                                    <x-heroicon-o-chat-bubble-bottom-center-text class="w-8 h-8" />
                                </div>
                                <h4 class="text-base font-medium text-gray-900 dark:text-white mb-1">Belum ada testimoni</h4>
                                <p class="text-sm">Silakan tambah testimoni baru.</p>
                            </div>
                        </td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        
        @if($testimonials->hasPages())
        <div class="px-6 py-4 border-t border-gray-100 dark:border-slate-700 bg-gray-50 dark:bg-slate-700/50">
            {{ $testimonials->links() }}
        </div>
        @endif
    </div>
</x-admin-layout>
