<?php
    $tags = App\Models\Tag::whereIn('id', $file->tags)->get();
    $pages = App\Models\Page::get();
    $query = App\Models\Category::where('status', 1)->latest();

    if (auth()->check()) {
        $isOrder = App\Models\Order::where('file_id', $file->id)
            ->where('user_id', auth()->user()->id)
            ->where('type', 1)
            ->where('status', 1)
            ->first();
        $subscribe = isSubscribe(auth()->user()->id);
    }

    // take related files
    $files = App\Models\File::where('category_id', $file->category_id)
        ->whereNotIn('id', [$file->id])
        ->get();

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

    foreach ($files 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);
    $relatedFiles = collect($latestSix);
?>

<?php $__env->startSection('content'); ?>
    <?php if($general->theme == 2): ?>
        <!-- ==================== Header End Here ==================== -->
        <div class="header" id="header">
            <div class="container ">
                <nav class="navbar navbar-expand-lg">
                    <div class="header-menu-wrapper align-items-center d-flex">
                        <div class="logo-wrapper">
                            <a href="<?php echo e(route('home')); ?>" class="navbar-brand logo" id="normal-logo">
                                <img src="<?php echo e(getImage('assets/images/general/logo1.png')); ?>" alt="...">
                            </a>
                        </div>
                    </div>
                    <form id="myForm" class="form-area d-flex" action="<?php echo e(route('search.by.type')); ?>" method="GET">
                        <div class="d-flex align-items-center">
                            <i class="fas fa-image ps-2"></i>
                            <p class="mx-2"><?php echo app('translator')->get('Image'); ?></p>
                        </div>
                        <div class="search">
                            <input id="searchInput" type="text" name="search" class="form--control"
                                value="<?php echo e(old('search')); ?>" placeholder="Search for photo">
                            <i class="fas fa-search"></i>
                        </div>
                    </form>
                    <button class="navbar-toggler header-button" type="button" data-bs-toggle="collapse"
                        data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                        <span id="hiddenNav"><i class="las la-bars"></i></span>
                    </button>

                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav nav-menu me-auto ps-lg-4 ps-0">
                            <?php $__currentLoopData = $pages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($page->slug == 'explore'): ?>
                                    <li class="nav-item">
                                        <a class="nav-link <?php echo e(Request::url() == url('/') . '/' . $page->slug ? 'active' : ''); ?>"
                                            href="<?php echo e(route('pages', $page->slug)); ?>"><?php echo e(__($page->name)); ?></a>
                                    </li>
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php if(auth()->guard()->guest()): ?>
                                <?php
                                    $categories = $query->take(3)->get();
                                ?>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <li class="nav-item">
                                        <a class="nav-link  <?php echo e(Request::url() == route('files.category', $item->id)); ?> ? 'active' : '' }}"
                                            href="<?php echo e(route('files.category', $item->id)); ?>"><?php echo e(__($item->name)); ?></a>
                                    </li>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                            <?php if(auth()->guard()->check()): ?>
                                <?php
                                    $categories = $query->take(2)->get();
                                ?>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <li class="nav-item">
                                        <a class="nav-link  <?php echo e(Request::url() == route('files.category', $item->id)); ?> ? 'active' : '' }}"
                                            href="<?php echo e(route('files.category', $item->id)); ?>"><?php echo e(__($item->name)); ?></a>
                                    </li>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>

                        </ul>
                        <div class="d-flex lan">
                            <i class="fas fa-globe"></i>
                            <select class="form-select langSel">
                                <?php $__currentLoopData = $language; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($item->code); ?>" <?php if(session('lang') == $item->code): ?> selected <?php endif; ?>>
                                        <?php echo e(__($item->name)); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="login">
                            <?php if(auth()->guard()->guest()): ?>
                                <a class="my-auto" href="<?php echo e(route('user.login')); ?>"><i
                                        class="fa-solid fa-user-large"></i><?php echo app('translator')->get('Sign In'); ?></a>
                            <?php endif; ?>

                            <?php if(auth()->guard()->check()): ?>
                                <li class="nav-item">
                                    <a class="nav-link" href="<?php echo e(route('user.home')); ?>"><?php echo app('translator')->get('Dashboard'); ?></a>
                                </li>
                            <?php endif; ?>
                        </div>
                    </div>
                </nav>
            </div>
        </div>
        <!-- ==================== Header End Here ==================== -->
    <?php endif; ?>
    <section class=" item-details py-100">
        <div class="container">
            <div class="row g-4">
                <div class="col-lg-8 col-md-7 col-12">
                    <div class="thumb-main">
                        <img src="<?php echo e(getImage(getFilePath('preview') . '/' . $file->file)); ?>" alt="image">
                        <div class="info">
                            <?php
                                if (Auth::check()) {
                                    $wish = App\Models\Wishlist::where('user_id', auth()->user()->id)
                                        ->where('file_id', $file->id)
                                        ->first();
                                }
                            ?>

                            <?php if(auth()->guard()->guest()): ?>
                                <button class="btn-img myGuestWishlistButton"><i class="fas fa-heart"></i></button>
                            <?php endif; ?>
                            <?php if(auth()->guard()->check()): ?>
                                <?php if(isset($wish)): ?>
                                    <button value="<?php echo e($file->id); ?>" class="btn-img markSingleWishlist"><i
                                            class="fas fa-heart text--base"></i></button>
                                <?php else: ?>
                                    <button value="<?php echo e($file->id); ?>" class="btn-img markSingleWishlist"><i
                                            class="fas fa-heart"></i></button>
                                <?php endif; ?>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="content">
                        <h5><?php echo e(__($file->title)); ?></h5>
                        <p><?php echo e(__($file->description)); ?></p>
                        <div class="tag">
                            <p><?php echo app('translator')->get('Related tags'); ?></p>
                            <?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)); ?>"><i
                                        class="fas fa-search"></i><?php echo e(__($item->name)); ?></a>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>

                </div>
                <div class="col-lg-4 col-md-5 col-12">
                    <?php if(isset($file->is_premium)): ?>
                        <div class="right-side">
                            <h6><?php echo app('translator')->get('Ways to shop'); ?></h6>
                            <form action="<?php echo e(route('user.payment')); ?>" method="POST" class="mt-4">
                                <?php echo csrf_field(); ?>
                                <input type="hidden" name="file_id" value="<?php echo e($file->id); ?>">
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="payment" value="1"
                                        id="flexRadioDefault1">
                                    <label class="form-check-label" for="flexRadioDefault1">
                                        <?php echo e($general->cur_sym); ?><?php echo e($general->image_price); ?> <?php echo app('translator')->get('for this image'); ?>
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" name="payment" value="2"
                                        id="flexRadioDefault2" checked>
                                    <label class="form-check-label" for="flexRadioDefault2">
                                        <?php echo e($general->image_quantity); ?>

                                        <?php echo app('translator')->get('images'); ?>/<?php echo e($general->package_type == 1 ? 'month' : 'year'); ?>

                                        <?php echo app('translator')->get('for'); ?>
                                        <?php echo e($general->cur_sym); ?><?php echo e($general->package_price); ?>

                                    </label>
                                </div>
                                <div class="mt-4">
                                    <?php if(auth()->guard()->guest()): ?>
                                        <button type="submit" class="btn button w-100 myGuestDownloadButton"><i
                                                class="fas fa-download"></i>
                                            <?php echo app('translator')->get('Download'); ?></button>
                                    <?php endif; ?>

                                    <?php if(auth()->guard()->check()): ?>
                                        <?php if(isset($isOrder)): ?>
                                            <a href="<?php echo e(route('user.file.download', $file->id)); ?>"
                                                class="btn button w-100"><i class="fas fa-download"></i>
                                                <?php echo app('translator')->get('Download'); ?></a>
                                        <?php elseif(isset($subscribe)): ?>
                                            <a href="<?php echo e(route('user.file.get', $file->id)); ?>" class="btn button w-100"><i
                                                    class="fas fa-download"></i>
                                                <?php echo app('translator')->get('Download'); ?></a>
                                        <?php elseif(auth()->user()->id == $file->user_id): ?>
                                            <button type="submit" class="btn button w-100 ownFile"><i
                                                    class="fas fa-download"></i>
                                                <?php echo app('translator')->get('Download'); ?></button>
                                        <?php else: ?>
                                            <button type="submit" class="btn button w-100"><i class="fas fa-download"></i>
                                                <?php echo app('translator')->get('Download'); ?></button>
                                        <?php endif; ?>

                                    <?php endif; ?>
                                </div>
                            </form>

                            <div class="type">
                                <div class="details">
                                    <i class="fas fa-certificate"></i>
                                    <h6><?php echo app('translator')->get('Vast Collection'); ?></h6>
                                </div>
                                <div class="details">
                                    <i class="fas fa-sign-in-alt"></i>
                                    <h6><?php echo app('translator')->get('Sign In first to buy image'); ?></h6>
                                </div>
                                <div class="details">
                                    <i class="fas fa-file"></i>
                                    <h6><?php echo app('translator')->get('File type'); ?>: <?php echo app('translator')->get('PNG'); ?>, <?php echo app('translator')->get('JPG'); ?>, <?php echo app('translator')->get('JPEG'); ?>
                                    </h6>
                                </div>
                            </div>
                        </div>
                    <?php else: ?>
                        <div class="right-side">
                            <h6><?php echo app('translator')->get('Download this image for free!'); ?></h6>

                            <div class="mt-4">
                                <?php if(auth()->guard()->guest()): ?>
                                    <button type="submit" class="btn button w-100 myGuestDownloadButton"><i
                                            class="fas fa-download"></i>
                                        <?php echo app('translator')->get('Free Download'); ?></button>
                                <?php endif; ?>

                                <?php if(auth()->guard()->check()): ?>
                                    <a href="<?php echo e(route('user.file.download', $file->id)); ?>" class="btn button w-100"><i
                                            class="fas fa-download"></i>
                                        <?php echo app('translator')->get('Free Download'); ?></a>

                                <?php endif; ?>
                            </div>

                            <div class="type">
                                <div class="details">
                                    <i class="fas fa-certificate"></i>
                                    <h6><?php echo app('translator')->get('Vast Collection'); ?></h6>
                                </div>
                                <div class="details">
                                    <i class="fas fa-sign-in-alt"></i>
                                    <h6><?php echo app('translator')->get('Sign In first to buy image'); ?></h6>
                                </div>
                                <div class="details">
                                    <i class="fas fa-file"></i>
                                    <h6><?php echo app('translator')->get('File type'); ?>: <?php echo app('translator')->get('PNG'); ?>, <?php echo app('translator')->get('JPG'); ?>, <?php echo app('translator')->get('JPEG'); ?>
                                    </h6>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            <div class="more categories-item">
                <div>
                    <h4><?php echo app('translator')->get('More Related Photos'); ?></h4>
                </div>
                <?php if($relatedFiles->isEmpty()): ?>
                    <div class="d-flex justify-content-start mt-5 mb-3">
                        <h4 class="no-file"><?php echo app('translator')->get('Looks like there are no related file here.'); ?></h4>
                    </div>
                <?php endif; ?>
                <div class="row g-4 justify-content-center ">
                    <?php $__currentLoopData = $relatedFiles; $__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>
        </div>
    </section>
<?php $__env->stopSection(); ?>

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

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

    <script>
        $(document).on('click', '.ownFile', function() {
            Toast.fire({
                icon: 'error',
                title: 'You can\'t buy your own file.'
            })
            return false;
        });
    </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>
    <script>
        $(document).on('click', '.markSingleWishlist', 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>`;
                        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>`;
                        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>

    <script>
        $(document).ready(function() {
            'use strict';
            $('#searchInput').keypress(function(e) {
                if (e.which === 13) {
                    e.preventDefault();
                    $('#myForm').submit();
                }
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make($activeTemplate . 'layouts.frontend', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\photostack\application\resources\views/presets/default/file_details.blade.php ENDPATH**/ ?>