<?php if(get_post_type(get_queried_object_id()) != 'profile_article'): ?>
    <div class="partners">
        <div class="partners__header">
            Самое читаемое<!--1-->
        </div>
        <div class="row">
            <?php
            $i = 0;
            $current = get_the_ID();
            $topitems = (array)json_decode(get_option('ppp_options'));
            $top = (array)json_decode(get_option('ppp_options'));
            $has_with_tag = false;
            foreach ($top as $item):
                if(has_tag(7840, $item->id)){
                    if($has_with_tag === true){
                        continue;
                    }
                    $has_with_tag = true;
                }
                $post = get_post($item->id);
                if ($item->id == $current || get_post_meta($item->id, 'popular_hide', true) == 1){ continue; }
                ?>
                <div class="col-12 col-md-4 d-none is_agregator" data-id="<?php echo $item->id; ?>">
                    <a class="partners__item d-flex d-lg-block" href="<?php echo get_permalink($post); ?>?utm_from=must-main">
                        <span class="partners__frame">
                            <?php if(has_post_thumbnail($post)): ?>
                                <?php if(wp_is_mobile()): ?>
                                    <img loading="lazy" class="lazyload" src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload_m.webp" data-src="<?php echo wp_get_attachment_image_src( get_post_thumbnail_id($post), 'thumbnail' )[0]; ?>" alt="<?php echo $post->post_title; ?>">
                                <?php else: ?>
                                    <img loading="lazy" class="lazyload" src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload.jpg" data-src="<?php echo wp_get_attachment_image_src( get_post_thumbnail_id($post), 'medium' )[0]; ?>" alt="<?php echo $post->post_title; ?>">
                                <?php endif; ?>
                            <?php else: ?>
                                <img loading="lazy" <?php if(wp_is_mobile()): ?>src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload_m.webp"<?php else: ?>src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload.jpg"<?php endif; ?> alt="<?php echo $post->post_title; ?>">
                            <?php endif; ?>
                        </span>
                        <strong class="partners__item__title">
                            <?php echo $post->post_title; ?>
                        </strong>
                    </a>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
    <script>
        (function(){
            let visited = (getCookie('visited')+',<?php echo $current; ?>').split(',').filter( onlyUnique ).join(',');
            setCookie('visited', visited, {secure: true, 'max-age': 3600});
            let list = document.querySelectorAll('.partners .row > div');
            let i = 0, j = 0, k = 0;
            while(i < <?php echo count($top)-1; ?>){
                let id = list[i].getAttribute('data-id');
                if (visited.split(',').indexOf(id) == -1 && j < 3){
                    list[i].classList.remove("d-none");
                    j++;
                }
                i++;
            }

            while(j < 3){
                list[k].classList.remove("d-none");
                j++;k++;
            }
        })();
        function getCookie(name) {
            let matches = document.cookie.match(new RegExp(
                "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
            ));
            return matches ? decodeURIComponent(matches[1]) : undefined;
        }
        function onlyUnique(value, index, self) {
            return (self.indexOf(value) === index && value == parseInt(value, 10));
        }
        function setCookie(name, value, options = {}) {
            options = {
                path: '/',
                expires: 0
            };
            if (options.expires.toUTCString) {
                options.expires = options.expires.toUTCString();
            }
            let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
            for (let optionKey in options) {
                updatedCookie += "; " + optionKey;
                let optionValue = options[optionKey];
                if (optionValue !== true) {
                    updatedCookie += "=" + optionValue;
                }
            }
            document.cookie = updatedCookie;
        }
    </script>
<?php endif; ?>