<?php
    $category = getContent('category.content', true);
    $categories = App\Models\Category::where('status', 1)
        ->inRandomOrder()
        ->take(6)
        ->get();

    $allRandomFiles = App\Models\File::where('status', 1)
        ->latest()
        ->get();

    $biggerWidth = [];
    $biggerHeight = [];

    foreach ($allRandomFiles as $item) {
        if ($item->width > $item->height) {
            $biggerWidth[] = $item;
        } else {
            $biggerHeight[] = $item;
        }
    }

    $orderedExplores = [];
    $biggerWidthCount = count($biggerWidth);
    $biggerHeightCount = count($biggerHeight);

    $rowCount = max(ceil($biggerWidthCount / 2), ceil($biggerHeightCount / 2));

    for ($i = 0; $i < $rowCount; $i++) {
        if ($i % 2 === 0) {
            if (isset($biggerWidth[$i])) {
                $orderedExplores[] = $biggerWidth[$i];
            }

            if (isset($biggerHeight[$i * 2])) {
                $orderedExplores[] = $biggerHeight[$i * 2];
            }

            if (isset($biggerHeight[$i * 2 + 1])) {
                $orderedExplores[] = $biggerHeight[$i * 2 + 1];
            }
        } else {
            if (isset($biggerHeight[$i * 2])) {
                $orderedExplores[] = $biggerHeight[$i * 2];
            }

            if (isset($biggerHeight[$i * 2 + 1])) {
                $orderedExplores[] = $biggerHeight[$i * 2 + 1];
            }

            if (isset($biggerWidth[$i])) {
                $orderedExplores[] = $biggerWidth[$i];
            }
        }
    }

    $latestSix = array_slice($orderedExplores, 0, 6);
    $allFiles = collect($latestSix);
?>
<!-- ==================== categories item Start ==================== -->
<section class="categories-item pb-100">
    <div class="container">
        <div class="title mb-4">
            <h3><?php echo e(__($category->data_values->heading)); ?></h3>
            <p><?php echo e(__($category->data_values->subheading)); ?></p>
        </div>
        <div class="tabs tab-custom">
            <div class="d-flex justify-content-center">
                <ul class="nav nav-pills my-auto" id="pills-tab" role="tablist">
                    <li class="nav-item" role="presentation">
                        <button class="nav-link active" id="pills-all-tab" data-bs-toggle="pill"
                            data-bs-target="#pills-all" type="button" role="tab" aria-controls="pills-all"
                            aria-selected="true"><?php echo app('translator')->get('All'); ?></button>
                    </li>
                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li class="nav-item" role="presentation">
                            <button class="nav-link" id="pills-example-tab<?php echo e($loop->iteration); ?>" data-bs-toggle="pill"
                                data-bs-target="#pills-example<?php echo e($loop->iteration); ?>" type="button" role="tab"
                                aria-controls="pills-example<?php echo e($loop->iteration); ?>"
                                aria-selected="true"><?php echo e(__($item->name)); ?></button>
                        </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            </div>
            <div class="tab-content wow animate__animated animate__fadeInUp mt-4" data-wow-delay="0.6s"
                id="pills-tabContent">
                <div class="tab-pane fade show active " id="pills-all" role="tabpanel" aria-labelledby="pills-all-tab"
                    tabindex="0">
                    <div class="row g-4 justify-content-center">
                        <?php if($allFiles->isEmpty()): ?>
                            <div class="d-flex justify-content-center mt-5">
                                <h4 class="no-file"><?php echo app('translator')->get('Looks like there are no file here.'); ?></h4>
                            </div>
                        <?php endif; ?>
                        <?php $__currentLoopData = $allFiles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $tags = App\Models\Tag::whereIn('id', $item->tags)
                                    ->take(3)
                                    ->get();

                                if (Auth::check()) {
                                    $Wishlist = App\Models\Wishlist::where('user_id', auth()->user()->id)
                                        ->where('file_id', $item->id)
                                        ->first();
                                }
                            ?>
                            <?php if($item->width > $item->height): ?>
                                <div class="col-lg-6 col-12">
                                    <div class="thumb">
                                        <a href="<?php echo e(route('file.details', $item->id)); ?>">
                                            <img src="<?php echo e(getImage(getFilePath('preview') . '/' . $item->file)); ?>"
                                                alt="image">

                                        </a>
                                        <div class="info">
                                            <?php if(auth()->guard()->guest()): ?>
                                                <button class="btn-img myGuestWishlistButton"><i
                                                        class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                            <?php endif; ?>
                                            <?php if(auth()->guard()->check()): ?>
                                                <?php if(isset($Wishlist)): ?>
                                                    <button value="<?php echo e($item->id); ?>" class="btn-img markWishlist"><i
                                                            class="fas fa-heart text--base"></i><?php echo app('translator')->get('Added'); ?></button>
                                                <?php else: ?>
                                                    <button value="<?php echo e($item->id); ?>" class="btn-img markWishlist"><i
                                                            class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </div>
                                        <div class="tag">
                                            <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <a href="<?php echo e(route('search.by.tag', $item->id)); ?>"
                                                    class="text-nowrap"><?php echo e($item->name); ?></a>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    </div>
                                </div>
                            <?php else: ?>
                                <div class="col-lg-3 col-md-6 col-12">
                                    <div class="thumb">
                                        <a href="<?php echo e(route('file.details', $item->id)); ?>">
                                            <img src="<?php echo e(getImage(getFilePath('preview') . '/' . $item->file)); ?>"
                                                alt="image">
                                        </a>
                                        <div class="info">
                                            <?php if(auth()->guard()->guest()): ?>
                                                <button class="btn-img myGuestWishlistButton"><i
                                                        class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                            <?php endif; ?>
                                            <?php if(auth()->guard()->check()): ?>
                                                <?php if(isset($Wishlist)): ?>
                                                    <button value="<?php echo e($item->id); ?>" class="btn-img markWishlist"><i
                                                            class="fas fa-heart text--base"></i><?php echo app('translator')->get('Added'); ?></button>
                                                <?php else: ?>
                                                    <button value="<?php echo e($item->id); ?>" class="btn-img markWishlist"><i
                                                            class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </div>
                                        <div class="tag">
                                            <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <a href="<?php echo e(route('search.by.tag', $item->id)); ?>"
                                                    class="text-nowrap"><?php echo e($item->name); ?></a>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    </div>
                                </div>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                    </div>
                </div>
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        // take related files
                        $allCatFiles = App\Models\File::where('category_id', $item->id)
                            ->where('status', 1)
                            ->get();

                        $biggerWidth = [];
                        $biggerHeight = [];

                        foreach ($allCatFiles as $item) {
                            if ($item->width > $item->height) {
                                $biggerWidth[] = $item;
                            } else {
                                $biggerHeight[] = $item;
                            }
                        }

                        $orderedExplores = [];
                        $biggerWidthCount = count($biggerWidth);
                        $biggerHeightCount = count($biggerHeight);

                        $rowCount = max(ceil($biggerWidthCount / 2), ceil($biggerHeightCount / 2));

                        for ($i = 0; $i < $rowCount; $i++) {
                            if ($i % 2 === 0) {
                                if (isset($biggerWidth[$i])) {
                                    $orderedExplores[] = $biggerWidth[$i];
                                }

                                if (isset($biggerHeight[$i * 2])) {
                                    $orderedExplores[] = $biggerHeight[$i * 2];
                                }

                                if (isset($biggerHeight[$i * 2 + 1])) {
                                    $orderedExplores[] = $biggerHeight[$i * 2 + 1];
                                }
                            } else {
                                if (isset($biggerHeight[$i * 2])) {
                                    $orderedExplores[] = $biggerHeight[$i * 2];
                                }

                                if (isset($biggerHeight[$i * 2 + 1])) {
                                    $orderedExplores[] = $biggerHeight[$i * 2 + 1];
                                }

                                if (isset($biggerWidth[$i])) {
                                    $orderedExplores[] = $biggerWidth[$i];
                                }
                            }
                        }

                        $latestSix = array_slice($orderedExplores, 0, 6);
                        $files = collect($latestSix);
                    ?>
                    <div class="tab-pane fade show" id="pills-example<?php echo e($loop->iteration); ?>" role="tabpanel"
                        aria-labelledby="pills-example-tab<?php echo e($loop->iteration); ?>" tabindex="0">
                        <div class="row g-4 justify-content-center">
                            <?php if($files->isEmpty()): ?>
                                <div class="d-flex justify-content-center mt-5">
                                    <h4 class="no-file"><?php echo app('translator')->get('Looks like there are no file here.'); ?></h4>
                                </div>
                            <?php endif; ?>
                            <?php $__currentLoopData = $files; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $file): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php
                                    $tags = App\Models\Tag::whereIn('id', $file->tags)
                                        ->take(3)
                                        ->get();
                                    if (Auth::check()) {
                                        $Wishlist = App\Models\Wishlist::where('user_id', auth()->user()->id)
                                            ->where('file_id', $file->id)
                                            ->first();
                                    }
                                ?>
                                <?php if($file->width > $file->height): ?>
                                    <div class="col-lg-6 col-12">
                                        <div class="thumb">
                                            <a href="<?php echo e(route('file.details', $file->id)); ?>">
                                                <img src="<?php echo e(getImage(getFilePath('preview') . '/' . $file->file)); ?>"
                                                    alt="image">
                                            </a>
                                            <div class="info">
                                                <?php if(auth()->guard()->guest()): ?>
                                                    <button class="btn-img myGuestWishlistButton"><i
                                                            class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                <?php endif; ?>
                                                <?php if(auth()->guard()->check()): ?>
                                                    <?php if(isset($Wishlist)): ?>
                                                        <button value="<?php echo e($file->id); ?>" class="btn-img markWishlist"><i
                                                                class="fas fa-heart text--base"></i><?php echo app('translator')->get('Added'); ?></button>
                                                    <?php else: ?>
                                                        <button value="<?php echo e($file->id); ?>" class="btn-img markWishlist"><i
                                                                class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </div>
                                            <div class="tag">
                                                <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <a href="<?php echo e(route('search.by.tag', $item->id)); ?>"
                                                        class="text-nowrap"><?php echo e($item->name); ?></a>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php else: ?>
                                    <div class="col-lg-3 col-md-6 col-12">
                                        <div class="thumb">
                                            <a href="<?php echo e(route('file.details', $file->id)); ?>">
                                                <img src="<?php echo e(getImage(getFilePath('preview') . '/' . $file->file)); ?>"
                                                    alt="image">
                                            </a>
                                            <div class="info">
                                                <?php if(auth()->guard()->guest()): ?>
                                                    <button class="btn-img myGuestWishlistButton"><i
                                                            class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                <?php endif; ?>
                                                <?php if(auth()->guard()->check()): ?>
                                                    <?php if(isset($Wishlist)): ?>
                                                        <button value="<?php echo e($file->id); ?>"
                                                            class="btn-img markWishlist"><i
                                                                class="fas fa-heart text--base"></i><?php echo app('translator')->get('Added'); ?></button>
                                                    <?php else: ?>
                                                        <button value="<?php echo e($file->id); ?>"
                                                            class="btn-img markWishlist"><i
                                                                class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?></button>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </div>
                                            <div class="tag">
                                                <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <a href="<?php echo e(route('search.by.tag', $item->id)); ?>"
                                                        class="text-nowrap"><?php echo e($item->name); ?></a>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>
                                        </div>
                                    </div>
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>
    </div>
</section>
<!-- ==================== categories End ==================== -->

<?php $__env->startPush('script'); ?>
    <script>
        $(document).on('click', '.myGuestWishlistButton', function() {
            window.location.href = "<?php echo e(route('user.login')); ?>";
        });
    </script>

    <script>
        $(document).on('click', '.markWishlist', function(e) {
            e.preventDefault();
            var file_id = $(this).val();
            var button = $(this);
            $.ajax({
                url: "<?php echo e(route('user.mark.wishlist')); ?>",
                data: {
                    file_id: file_id,
                },
                method: "GET",
                success: function(data) {
                    if (data.status == true) {
                        var innerData = `<i class="fas fa-heart text--base"></i><?php echo app('translator')->get('Added'); ?>`;
                        button.html(innerData);
                        Toast.fire({
                            icon: 'success',
                            title: 'Successfully set this image to your wishlist.'
                        })
                        return false;
                    }

                    if (data.status == false) {
                        var innerData = `<i class="fas fa-heart"></i><?php echo app('translator')->get('Add'); ?>`;
                        button.html(innerData);
                        Toast.fire({
                            icon: 'success',
                            title: 'Successfully removed this image from your wishlist.'
                        })
                        return false;
                    }

                    if (data.auth == false) {
                        window.location.href = "<?php echo e(route('user.login')); ?>";
                    }
                },
                error: function(xhr, status, error) {},
            });

        });
    </script>
<?php $__env->stopPush(); ?>
<?php /**PATH C:\xampp\htdocs\photostack\application\resources\views/presets/default/sections/category.blade.php ENDPATH**/ ?>