<x-dynamic-component :component="$layout">
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
            {{ __('Crud Tables') }}
        </h2>
    </x-slot>

    @if (session('feedback.success'))
        <x-admin-crud::alert.success>{{ session('feedback.success') }}</x-admin-crud::alert.success>
    @endif
    @if (session('feedback.error'))
        <x-admin-crud::alert.error>{{ session('feedback.error') }}</x-admin-crud::alert.error>
    @endif

    <div class="py-4">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <table class="divide-y divide-gray-400  dark:text-gray-300">
                <thead>
                    <tr>
                        <th class="px-2">cnt</th>
                        <th class="px-2">table name</th>
                        <th class="px-2">(row mode)</th>
                        <th class="px-2">truncate</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($tables as $table)
                        <tr>
                            <td class="px-2 text-right">
                                {{ $tableDataCounts[$table] }}
                            </td>
                            <td class="px-2 text-center">
                                <a href="{{ admin_crud_route('crud') }}?table={{ $table }}"
                                    class="hover:underline hover:text-blue-500"> {{ $table }} </a>
                            </td>
                            <td class="px-2 text-center">
                                <a href="{{ admin_crud_route('crud') }}?table={{ $table }}&row"
                                    class="hover:underline hover:text-blue-500"> {{ $table }} </a>
                            </td>
                            <td class="px-2 text-center">
                                @if ($tableDataCounts[$table] == 0)
                                    <span class="text-gray-400">truncate</span>
                                @else
                                    <x-admin-crud::linkbutton
                                        href="{{ admin_crud_route('crudtruncate', ['table' => $table]) }}"
                                        color="orange" size="sm"
                                        confirm="本当にこのテーブル（{{ $table }}）のデータをすべて削除しますか？">
                                        {{ $tableDataCounts[$table] }} truncate
                                    </x-admin-crud::linkbutton>
                                @endif
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>

</x-dynamic-component>
