<?php
/**
 * Шаблон постраничной навигации используемый в моделях
 *
 * @var $elements
 * @var \Illuminate\Pagination\Paginator $paginator
 */

?>
<?php if ($paginator->hasPages()): ?>
    <nav class="flex items-center justify-between border-t border-gray-200 bg-white px-4 py-4 sm:px-6 rounded-lg shadow-sm" aria-label="Pagination">
        <!-- Mobile View -->
        <div class="flex flex-1 justify-between sm:hidden">
            <?php if ($paginator->onFirstPage()): ?>
                <span class="relative inline-flex items-center rounded-lg border border-gray-300 bg-gray-100 px-4 py-2.5 text-sm font-medium text-gray-400 cursor-not-allowed">
                    <svg class="h-4 w-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                    </svg>
                    <?= __('Previous') ?>
                </span>
            <?php else: ?>
                <a href="<?= $paginator->previousPageUrl() ?>" class="relative inline-flex items-center rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200 shadow-sm hover:shadow">
                    <svg class="h-4 w-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                    </svg>
                    <?= __('Previous') ?>
                </a>
            <?php endif ?>

            <?php if ($paginator->hasMorePages()): ?>
                <a href="<?= $paginator->nextPageUrl() ?>" class="relative ml-3 inline-flex items-center rounded-lg border border-gray-300 bg-white px-4 py-2.5 text-sm font-medium text-gray-700 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200 shadow-sm hover:shadow">
                    <?= __('Next') ?>
                    <svg class="h-4 w-4 ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                    </svg>
                </a>
            <?php else: ?>
                <span class="relative ml-3 inline-flex items-center rounded-lg border border-gray-300 bg-gray-100 px-4 py-2.5 text-sm font-medium text-gray-400 cursor-not-allowed">
                    <?= __('Next') ?>
                    <svg class="h-4 w-4 ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                    </svg>
                </span>
            <?php endif ?>
        </div>

        <!-- Desktop View -->
        <div class="hidden sm:flex sm:flex-1 sm:items-center sm:justify-between">
            <!-- Page Info -->
            <div>
                <p class="text-sm text-gray-600">
                    <?= __('Showing') ?>
                    <span class="font-semibold text-gray-900"><?= $paginator->firstItem() ?? 0 ?></span>
                    <?= __('to') ?>
                    <span class="font-semibold text-gray-900"><?= $paginator->lastItem() ?? 0 ?></span>
                    <?= __('of') ?>
                    <span class="font-semibold text-gray-900"><?= $paginator->total() ?></span>
                    <?= __('results') ?>
                </p>
            </div>

            <!-- Page Numbers -->
            <div>
                <ul class="isolate inline-flex -space-x-px rounded-lg shadow-sm" role="navigation" aria-label="Pagination">
                    <!-- Previous Page Link -->
                    <?php if ($paginator->onFirstPage()): ?>
                        <li>
                            <span class="relative inline-flex items-center rounded-l-lg border border-gray-300 bg-gray-100 px-3 py-2 text-sm font-medium text-gray-400 cursor-not-allowed" aria-disabled="true" aria-label="Previous page">
                                <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                                </svg>
                            </span>
                        </li>
                    <?php else: ?>
                        <li>
                            <a href="<?= $paginator->previousPageUrl() ?>" class="relative inline-flex items-center rounded-l-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-500 hover:bg-gray-50 hover:text-gray-700 transition-all duration-200 hover:shadow" aria-label="Previous page">
                                <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
                                </svg>
                            </a>
                        </li>
                    <?php endif ?>

                    <!-- Pagination Elements -->
                    <?php foreach ($elements as $element): ?>
                        <!-- "Three Dots" Separator -->
                        <?php if (is_string($element)): ?>
                            <li>
                                <span class="relative inline-flex items-center border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-500">
                                    &hellip;
                                </span>
                            </li>
                        <?php endif ?>

                        <!-- Array Of Links -->
                        <?php if (is_array($element)): ?>
                            <?php foreach ($element as $page => $url): ?>
                                <?php if ($page === $paginator->currentPage()): ?>
                                    <li>
                                        <span class="relative z-10 inline-flex items-center border border-blue-500 bg-blue-600 px-4 py-2 text-sm font-semibold text-white shadow-lg" aria-current="page">
                                            <?= $page ?>
                                        </span>
                                    </li>
                                <?php else: ?>
                                    <li>
                                        <a href="<?= $url ?>" class="relative inline-flex items-center border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-600 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200 hover:shadow">
                                            <?= $page ?>
                                        </a>
                                    </li>
                                <?php endif ?>
                            <?php endforeach ?>
                        <?php endif ?>
                    <?php endforeach ?>

                    <!-- Next Page Link -->
                    <?php if ($paginator->hasMorePages()): ?>
                        <li>
                            <a href="<?= $paginator->nextPageUrl() ?>" class="relative inline-flex items-center rounded-r-lg border border-gray-300 bg-white px-3 py-2 text-sm font-medium text-gray-500 hover:bg-gray-50 hover:text-gray-700 transition-all duration-200 hover:shadow" aria-label="Next page">
                                <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                                </svg>
                            </a>
                        </li>
                    <?php else: ?>
                        <li>
                            <span class="relative inline-flex items-center rounded-r-lg border border-gray-300 bg-gray-100 px-3 py-2 text-sm font-medium text-gray-400 cursor-not-allowed" aria-disabled="true" aria-label="Next page">
                                <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
                                </svg>
                            </span>
                        </li>
                    <?php endif ?>
                </ul>
            </div>
        </div>
    </nav>
<?php endif; ?>