<?php 

if(!function_exists('breeza_get_post_grid')){
    function breeza_get_post_grid($posts = [], $settings = []){ 
        if (empty($posts) || !is_array($posts) || empty($settings) || !is_array($settings)) {
            return false;
        }
        switch ($settings['layout']) {

            case 'post-1':
            breeza_get_post_grid_layout1($posts, $settings);
            break;

            case 'service-1':
            breeza_get_service_grid_layout1($posts, $settings);
            break;

            case 'service-2':
            breeza_get_service_grid_layout2($posts, $settings);
            break;

            case 'service-3':
            breeza_get_service_grid_layout3($posts, $settings);
            break;

            case 'service-4':
            breeza_get_service_grid_layout4($posts, $settings);
            break;

            case 'case-1':
            breeza_get_case_grid_layout2($posts, $settings);
            break;

            default:
            return false;
            break;
        }
    }
}

// Start Post Grid
//--------------------------------------------------
function breeza_get_post_grid_layout1($posts = [], $settings = []){ 
    extract($settings);
    
    $images_size = !empty($img_size) ? $img_size : '648x496';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";
                
                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $img_id = get_post_thumbnail_id($post->ID);
            if($img_id) {
                $img = pxl_get_image_by_size( array(
                    'attach_id'  => $img_id,
                    'thumb_size' => $images_size,
                    'class' => 'no-lazyload',
                ));
                $thumbnail = $img['thumbnail'];
            } else {
                $thumbnail = get_the_post_thumbnail($post->ID, $images_size);
            }
            $author = get_user_by('id', $post->post_author);  ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <?php if (has_post_thumbnail($post->ID) && wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false)):
                    $img_id = get_post_thumbnail_id($post->ID);
                    $img          = pxl_get_image_by_size( array(
                        'attach_id'  => $img_id,
                        'thumb_size' => $images_size
                    ) );
                    $thumbnail    = $img['thumbnail'];
                    ?>
                    <div class="pxl-item--image">
                        <a href="<?php echo esc_url(get_permalink( $post->ID )); ?>"><?php echo wp_kses_post($thumbnail); ?></a>
                        <?php if($show_category) : ?>            
                            <span class="pxl-item--category"><?php the_terms( $post->ID, 'category', '', ', ', '' ); ?></span>             
                        <?php endif; ?>
                        <?php if($show_date) : ?>            
                            <span class="pxl-item--date"><i class="fas fa-calendar-alt"></i><?php $date_formart = get_option('date_format'); echo get_the_date($date_formart, $post->ID); ?></span>             
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
                <div class="pxl-item--holder">
                    <?php if($show_author) : ?>                   
                        <div class="pxl-item--author">
                            <?php                             
                            $avatar_url = get_avatar_url($author->ID);
                            $author_name = $author->display_name; 
                            if ($author || !empty($user_position)) {                                
                                echo '<img src="' . esc_url($avatar_url) . '" alt="' . esc_attr($author_name) . '" />';                                
                            } ?> 
                            <?php echo esc_html__('By', 'breeza'); ?>&nbsp;
                            <span>
                                <?php echo esc_attr($author_name); ?>                                
                            </span>
                        </div>
                    <?php endif; ?>
                    <h5 class="pxl-item--title"><a href="<?php echo esc_url(get_permalink( $post->ID )); ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a></h5>  
                    <?php if($show_excerpt) : ?>                                
                        <div class="pxl-item--excerpt">
                            <?php echo wp_trim_words( $post->post_excerpt, $num_words, $more = null ); ?>
                        </div>      
                    <?php endif; ?>
                </div>
                <?php if ($show_button) : ?>
                    <div class="pxl-item--readmore">
                        <a class="btn--readmore" href="<?php echo esc_url( get_permalink($post->ID)); ?>">                    
                            <span class="btn--icon pxl-mr-11 rtl-reverse">
                                <svg xmlns="http://www.w3.org/2000/svg" width="32" height="19" viewBox="0 0 32 19" fill="none">
                                  <path d="M23.0107 18.0412L32 9.02058L23.0107 -3.92935e-07L21.4998 1.5162L27.9099 7.94855L1.55991e-06 7.94855L1.46618e-06 10.0927L27.9097 10.0927L21.4998 16.5249L23.0107 18.0412Z" fill="#194341"/>
                              </svg>
                          </span>                    
                          <span class="btn--text"><?php if(!empty($button_text)) {
                            echo esc_attr($button_text);
                        } else {
                            echo esc_html__('Continue Reading', 'breeza');
                        } ?></span>
                    </a>
                </div>                      
            <?php endif; ?>
        </div>
    </div>
    <?php
endforeach;
endif;
}
// End Post Grid
//--------------------------------------------------


// Start Service Grid
//--------------------------------------------------
function breeza_get_service_grid_layout1($posts = [], $settings = []){ 
    extract($settings);

    $images_size = !empty($img_size) ? $img_size : '301x401';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";

                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $service_external_link = get_post_meta($post->ID, 'service_external_link', true);
            $service_excerpt = get_post_meta($post->ID, 'service_excerpt', true);
            $service_icon_type = get_post_meta($post->ID, 'service_icon_type', true);
            $service_icon_font = get_post_meta($post->ID, 'service_icon_font', true);
            $service_icon_img = get_post_meta($post->ID, 'service_icon_img', true);
            $gradient_color = breeza()->get_opt( 'gradient_color' );
            ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <div class="pxl-item--holder">
                        <?php if($service_icon_type == 'icon' && !empty($service_icon_font)) : ?>
                            <div class="pxl-icon">
                                <i class="<?php echo esc_attr($service_icon_font); ?>"></i>
                            </div>
                        <?php endif; ?>
                        <?php if($service_icon_type == 'image' && !empty($service_icon_img)) : 
                            $icon_img = pxl_get_image_by_size( array(
                                'attach_id'  => $service_icon_img['id'],
                                'thumb_size' => '52x52',
                            ));
                            $icon_thumbnail = $icon_img['thumbnail'];
                            ?>
                            <div class="pxl-icon">
                                <?php echo wp_kses_post($icon_thumbnail); ?>
                            </div>
                        <?php endif; ?>                        
                        <h6 class="pxl-item--title">
                            <a href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a>
                        </h6>      
                        <?php if($show_excerpt) : ?>                                
                            <div class="pxl-item--excerpt">
                                <?php echo wp_trim_words( $post->post_excerpt, $num_words, $more = null ); ?>
                            </div>      
                        <?php endif; ?>                            
                        <?php if($show_button == 'true') : ?>
                            <a class="arrow" href="<?php echo esc_url(get_permalink( $post->ID )); ?>">
                                <svg xmlns="http://www.w3.org/2000/svg" width="32" height="19" viewBox="0 0 32 19" fill="none">
                                    <path d="M23.0107 18.0412L32 9.02058L23.0107 -3.92935e-07L21.4998 1.5162L27.9099 7.94855L1.55991e-06 7.94855L1.46618e-06 10.0927L27.9097 10.0927L21.4998 16.5249L23.0107 18.0412Z" fill="#2CB770"/>
                                </svg>                          
                            </a>
                        <?php endif; ?>                
                    </div>
                </div>
            </div>
            <?php
        endforeach;
    endif;
}

function breeza_get_service_grid_layout2($posts = [], $settings = []){ 
    extract($settings);

    $images_size = !empty($img_size) ? $img_size : '570x364';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";

                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $service_external_link = get_post_meta($post->ID, 'service_external_link', true);
            $service_excerpt = get_post_meta($post->ID, 'service_excerpt', true);
            $service_icon_type = get_post_meta($post->ID, 'service_icon_type', true);
            $service_icon_font = get_post_meta($post->ID, 'service_icon_font', true);
            $service_icon_img = get_post_meta($post->ID, 'service_icon_img', true);
            $gradient_color = breeza()->get_opt( 'gradient_color' );
            ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <?php if (has_post_thumbnail($post->ID) && wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false)): 
                    $img_id       = get_post_thumbnail_id( $post->ID );
                    $img          = breeza_get_image_by_size( array(
                        'attach_id'  => $img_id,
                        'thumb_size' => $images_size
                    ) );
                    $thumbnail    = $img['thumbnail']; ?>
                    <div class="pxl-item--featured">
                        <a href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>">
                            <?php echo wp_kses_post($thumbnail); ?>
                        </a>                       
                    </div>
                <?php endif; ?>
                <div class="pxl-item--holder">
                    <?php if($service_icon_type == 'icon' && !empty($service_icon_font)) : ?>
                        <div class="pxl-icon">
                            <i class="<?php echo esc_attr($service_icon_font); ?>"></i>
                        </div>
                    <?php endif; ?>
                    <?php if($service_icon_type == 'image' && !empty($service_icon_img)) : 
                        $icon_img = pxl_get_image_by_size( array(
                            'attach_id'  => $service_icon_img['id'],
                            'thumb_size' => '30x30',
                        ));
                        $icon_thumbnail = $icon_img['thumbnail'];
                        ?>
                        <div class="pxl-icon">
                            <?php echo wp_kses_post($icon_thumbnail); ?>
                        </div>
                    <?php endif; ?>   
                    <h6 class="pxl-item--title">
                        <a href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a>
                    </h6>   
                    <?php if($show_excerpt) : ?>                                
                        <div class="pxl-item--excerpt">
                            <?php echo wp_trim_words( $post->post_excerpt, $num_words, $more = null ); ?>
                        </div>      
                    <?php endif; ?>  
                </div>
                <?php if($show_button == 'true') : ?>
                    <div class="pxl-post--readmore btn">
                        <a href="<?php echo esc_url(get_permalink( $post->ID )); ?>">
                            <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none">
                              <path d="M0 6.77834H9.01985L5.51654 10.2816L6.61736 11.3825L12 5.99983L6.61736 0.617188L5.51654 1.71801L9.01985 5.22131H0V6.77834Z" fill="#194341"/>
                          </svg>
                          <span><?php if(!empty($button_text)) {
                            echo esc_attr($button_text);
                        } else {
                            echo esc_html__('Read More', 'breeza');
                        } ?></span>
                    </a>
                </div>
            <?php endif; ?>                
        </div>
    </div>
    <?php
endforeach;
endif;
}

function breeza_get_service_grid_layout3($posts = [], $settings = []){ 
    extract($settings);
    
    $images_size = !empty($img_size) ? $img_size : '740x460';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";
                
                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $service_excerpt = get_post_meta($post->ID, 'service_excerpt', true);
            $service_external_link = get_post_meta($post->ID, 'service_external_link', true);
            $service_icon_type = get_post_meta($post->ID, 'service_icon_type', true);
            $service_icon_font = get_post_meta($post->ID, 'service_icon_font', true);
            $service_icon_img = get_post_meta($post->ID, 'service_icon_img', true);
            $multi_text_country = get_post_meta($post->ID, 'multi_text_country', true);
            $icon_multi_text = get_post_meta($post->ID, 'icon_multi_text', true);
            ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <a class="link-box" href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"></a>
                    <div class="content">
                        <?php if($service_icon_type == 'icon' && !empty($service_icon_font)) : ?>
                            <div class="pxl-icon">
                                <i class="<?php echo esc_attr($service_icon_font); ?>"></i>
                            </div>
                        <?php endif; ?>
                        <?php if($service_icon_type == 'image' && !empty($service_icon_img)) : 
                            $icon_img = pxl_get_image_by_size( array(
                                'attach_id'  => $service_icon_img['id'],
                                'thumb_size' => 'full',
                            ));
                            $icon_thumbnail = $icon_img['thumbnail'];
                            ?>
                            <div class="pxl-icon">
                                <?php echo wp_kses_post($icon_thumbnail); ?>
                            </div>
                        <?php endif; ?>
                        <h8 class="pxl-item--title">
                            <a href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a>
                        </h8>
                    </div>
                    <div class="arrow">
                        <svg xmlns="http://www.w3.org/2000/svg" width="9" height="15" viewBox="0 0 9 15" fill="none">
                            <path d="M0.901424 13.9075C0.701919 13.708 0.589844 13.4373 0.589844 13.1552C0.589844 12.873 0.701919 12.6023 0.901424 12.4028L6.16916 7.13504L0.901424 1.8673C0.707573 1.66659 0.600309 1.39777 0.602733 1.11875C0.605158 0.83972 0.717078 0.572807 0.914387 0.375499C1.1117 0.178189 1.37861 0.0662708 1.65764 0.0638456C1.93666 0.0614214 2.20548 0.168686 2.40619 0.362536L8.42631 6.38265C8.62581 6.58222 8.73789 6.85285 8.73789 7.13504C8.73789 7.41722 8.62581 7.68785 8.42631 7.88742L2.40619 13.9075C2.20662 14.107 1.93599 14.2191 1.65381 14.2191C1.37162 14.2191 1.10099 14.107 0.901424 13.9075Z" fill="#111E21"/>
                        </svg>
                    </div>
                </div>
            </div>
            <?php
        endforeach;
    endif;
}

function breeza_get_service_grid_layout4($posts = [], $settings = []){ 
    extract($settings);

    $images_size = !empty($img_size) ? $img_size : '301x401';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";

                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $service_external_link = get_post_meta($post->ID, 'service_external_link', true);
            $service_excerpt = get_post_meta($post->ID, 'service_excerpt', true);
            $service_icon_type = get_post_meta($post->ID, 'service_icon_type', true);
            $service_icon_font = get_post_meta($post->ID, 'service_icon_font', true);
            $service_icon_img = get_post_meta($post->ID, 'service_icon_img', true);
            $gradient_color = breeza()->get_opt( 'gradient_color' );
            ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <div class="pxl-item--holder">
                        <?php if($service_icon_type == 'icon' && !empty($service_icon_font)) : ?>
                            <div class="pxl-icon">
                                <i class="<?php echo esc_attr($service_icon_font); ?>"></i>
                            </div>
                        <?php endif; ?>
                        <?php if($service_icon_type == 'image' && !empty($service_icon_img)) : 
                            $icon_img = pxl_get_image_by_size( array(
                                'attach_id'  => $service_icon_img['id'],
                                'thumb_size' => '50x50',
                            ));
                            $icon_thumbnail = $icon_img['thumbnail'];
                            ?>
                            <div class="pxl-icon">
                                <?php echo wp_kses_post($icon_thumbnail); ?>
                            </div>
                        <?php endif; ?>           
                        <div class="pxl-item--number">
                            <?php
                            if ($key + 1 > 9) {
                                echo htmlspecialchars($key + 1);
                            } else {
                                echo '0' . htmlspecialchars($key + 1);
                            }
                            ?>
                        </div>
                        <h6 class="pxl-item--title">
                            <a href="<?php if(!empty($service_external_link)) { echo esc_url($service_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a>
                        </h6>      
                        <?php if($show_excerpt) : ?>                                
                            <div class="pxl-item--excerpt">
                                <?php echo wp_trim_words( $post->post_excerpt, $num_words, $more = null ); ?>
                            </div>      
                        <?php endif; ?>                            
                        <?php if($show_button == 'true') : ?>                            
                            <a class="pxl-item--button" href="<?php echo esc_url(get_permalink( $post->ID )); ?>">
                                <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none">
                                  <path d="M0 6.77834H9.01985L5.51654 10.2816L6.61736 11.3825L12 5.99983L6.61736 0.617188L5.51654 1.71801L9.01985 5.22131H0V6.77834Z" fill="#687799 "/>
                              </svg>
                              <span><?php if(!empty($button_text)) {
                                echo esc_attr($button_text);
                            } else {
                                echo esc_html__('Read More', 'breeza');
                            } ?></span>
                        </a>                        
                    <?php endif; ?>                 
                </div>
            </div>
        </div>
        <?php
    endforeach;
endif;
}

// End Service Grid
//-------------------------------------------------

function breeza_get_case_grid_layout2($posts = [], $settings = []){ 
    extract($settings);

    $images_size = !empty($img_size) ? $img_size : '700x686';

    if (is_array($posts)):
        foreach ($posts as $key => $post):
            $item_class = "pxl-grid-item col-xl-{$col_xl} col-lg-{$col_lg} col-md-{$col_md} col-sm-{$col_sm} col-{$col_xs}";
            if(isset($grid_masonry) && !empty($grid_masonry[$key]) && (count($grid_masonry) > 1)) {
                $col_xl_m = 12 / $grid_masonry[$key]['col_xl_m'];
                $col_lg_m = 12 / $grid_masonry[$key]['col_lg_m'];
                $col_md_m = 12 / $grid_masonry[$key]['col_md_m'];
                $col_sm_m = 12 / $grid_masonry[$key]['col_sm_m'];
                $col_xs_m = 12 / $grid_masonry[$key]['col_xs_m'];
                $item_class = "pxl-grid-item col-xl-{$col_xl_m} col-lg-{$col_lg_m} col-md-{$col_md_m} col-sm-{$col_sm_m} col-{$col_xs_m}";

                $img_size_m = $grid_masonry[$key]['img_size_m'];
                if(!empty($img_size_m)) {
                    $images_size = $img_size_m;
                }
            } elseif (!empty($img_size)) {
                $images_size = $img_size;
            }

            if(!empty($tax))
                $filter_class = pxl_get_term_of_post_to_class($post->ID, array_unique($tax));
            else 
                $filter_class = '';

            $case_external_link = get_post_meta($post->ID, 'case_external_link', true);
            $gradient_color = breeza()->get_opt( 'gradient_color' );
            ?>
            <div class="<?php echo esc_attr($item_class . ' ' . $filter_class); ?>">
                <div class="pxl-item--inner <?php echo esc_attr($pxl_animate); ?>" data-wow-duration="1.2s">
                    <a href="<?php if(!empty($case_external_link)) { echo esc_url($case_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"></a>                       
                    <?php if (has_post_thumbnail($post->ID) && wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), false)): 
                    $img_id       = get_post_thumbnail_id( $post->ID );
                    $img          = breeza_get_image_by_size( array(
                        'attach_id'  => $img_id,
                        'thumb_size' => $images_size
                    ) );
                    $thumbnail    = $img['thumbnail']; ?>
                    <div class="pxl-item--featured">
                        <?php echo wp_kses_post($thumbnail); ?>
                    </div>
                <?php endif; ?>
                <div class="pxl-item--holder">
                    <?php if($show_category) : ?>            
                        <span class="pxl-item--category"><?php the_terms( $post->ID, 'case-category', '', ', ', '' ); ?></span>             
                    <?php endif; ?>
                    <h6 class="pxl-item--title">
                        <a href="<?php if(!empty($case_external_link)) { echo esc_url($case_external_link); } else { echo esc_url(get_permalink( $post->ID )); } ?>"><?php echo esc_attr(get_the_title($post->ID)); ?></a>
                    </h6>  
                    <?php if($show_button == 'true') : ?>
                        <div class="pxl-post--readmore">
                            <a href="<?php echo esc_url(get_permalink( $post->ID )); ?>">
                                <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15" fill="none">
                                    <path d="M7.30341 0.771319C7.49677 0.578199 7.75888 0.469726 8.03216 0.469726C8.30544 0.469726 8.56755 0.5782 8.76091 0.771319L14.6047 6.61507C14.7978 6.80843 14.9062 7.07054 14.9062 7.34382C14.9062 7.6171 14.7978 7.87921 14.6047 8.07257L8.76091 13.9163C8.5653 14.0984 8.30673 14.1975 8.03954 14.1929C7.77235 14.1883 7.51736 14.0803 7.32816 13.8916C7.13945 13.7024 7.03143 13.4474 7.02682 13.1802C7.0222 12.913 7.12134 12.6544 7.30341 12.4588L11.3872 8.37507L1.15716 8.37507C0.883652 8.37507 0.621351 8.26642 0.427953 8.07302C0.234557 7.87962 0.125908 7.61732 0.125908 7.34382C0.125908 7.07031 0.234557 6.80801 0.427953 6.61461C0.621351 6.42122 0.883652 6.31257 1.15716 6.31257L11.3872 6.31257L7.30341 2.22882C7.11029 2.03546 7.00181 1.77335 7.00181 1.50007C7.00181 1.22679 7.11029 0.964679 7.30341 0.771319Z" fill="white"/>
                                </svg>
                            </a>
                        </div>
                    <?php endif; ?>                
                </div>
            </div>
        </div>
        <?php
    endforeach;
endif;
}

add_action( 'wp_ajax_breeza_get_pagination_html', 'breeza_get_pagination_html' );
add_action( 'wp_ajax_nopriv_breeza_get_pagination_html', 'breeza_get_pagination_html' );
function breeza_get_pagination_html(){
    try{
        if(!isset($_POST['query_vars'])){
            throw new Exception(__('Something went wrong while requesting. Please try again!', 'breeza'));
        }
        $query = new WP_Query($_POST['query_vars']);
        ob_start();
        breeza()->page->get_pagination( $query,  true );
        $html = ob_get_clean();
        wp_send_json(
            array(
                'status' => true,
                'message' => esc_attr__('Load Successfully!', 'breeza'),
                'data' => array(
                    'html' => $html,
                    'query_vars' => $_POST['query_vars'],
                    'post' => $query->have_posts()
                ),
            )
        );
    }
    catch (Exception $e){
        wp_send_json(array('status' => false, 'message' => $e->getMessage()));
    }
    die;
}

add_action( 'wp_ajax_breeza_load_more_post_grid', 'breeza_load_more_post_grid' );
add_action( 'wp_ajax_nopriv_breeza_load_more_post_grid', 'breeza_load_more_post_grid' );
function breeza_load_more_post_grid(){
    try{
        if(!isset($_POST['settings'])){
            throw new Exception(__('Something went wrong while requesting. Please try again!', 'breeza'));
        }
        $settings = $_POST['settings'];
        set_query_var('paged', $settings['paged']);
        extract(pxl_get_posts_of_grid($settings['post_type'], [
            'source' => isset($settings['source'])?$settings['source']:'',
            'orderby' => isset($settings['orderby'])?$settings['orderby']:'date',
            'order' => isset($settings['order'])?$settings['order']:'desc',
            'limit' => isset($settings['limit'])?$settings['limit']:'6',
            'post_ids' => isset($settings['post_ids'])?$settings['post_ids']:[],
        ]));
        ob_start();

        breeza_get_post_grid($posts, $settings);
        $html = ob_get_clean();
        wp_send_json(
            array(
                'status' => true,
                'message' => esc_attr__('Load Successfully!', 'breeza'),
                'data' => array(
                    'html' => $html,
                    'paged' => $settings['paged'],
                    'posts' => $posts,
                    'max' => $max,
                ),
            )
        );
    }
    catch (Exception $e){
        wp_send_json(array('status' => false, 'message' => $e->getMessage()));
    }
    die;
}

add_action( 'wp_ajax_breeza_get_filter_html', 'breeza_get_filter_html' );
add_action( 'wp_ajax_nopriv_breeza_get_filter_html', 'breeza_get_filter_html' );
function breeza_get_filter_html(){
    try{
        if(!isset($_POST['settings'])){
            throw new Exception(__('Something went wrong while requesting. Please try again!', 'breeza'));
        }
        $settings = $_POST['settings'];
        $loadmore_filter = $_POST['loadmore_filter'];
        if($loadmore_filter == '1'){
            set_query_var('paged', 1);
            $limit = isset($settings['limit'])?$settings['limit']:'6';
            $limitx = (int)$limit * (int)$settings['paged'];
        }else{
            set_query_var('paged', $settings['paged']);
            $limitx = isset($settings['limit'])?$settings['limit']:'6';
        }
        extract(pxl_get_posts_of_grid($settings['post_type'], [
            'source' => isset($settings['source'])?$settings['source']:'',
            'orderby' => isset($settings['orderby'])?$settings['orderby']:'date',
            'order' => isset($settings['order'])?$settings['order']:'desc',
            'limit' => $limitx,
            'post_ids' => isset($settings['post_ids'])?$settings['post_ids']: [],
        ],
        $settings['tax']
    ));
    ob_start(); ?>

    <span class="filter-item active" data-filter="*">
        <?php echo esc_html($settings['filter_default_title']); ?>
        <?php if($settings['show_cat_count'] == '1'): ?>
            <span class="filter-item-count"><?php echo count($posts); ?></span> 
        <?php endif; ?>
    </span>
    <?php foreach ($categories as $category):
        $category_arr = explode('|', $category);
        $term = get_term_by('slug',$category_arr[0], $category_arr[1]);
        $tax_count = 0;
        foreach ($posts as $key => $post){
            $this_terms = get_the_terms( $post->ID,  $settings['tax'][0] );
            $term_list = [];
            foreach ($this_terms as $t) {
                $term_list[] = $t->slug;
            } 
            if(in_array($term->slug,$term_list))
                $tax_count++;
        } 
        if($tax_count > 0): ?>
            <span class="filter-item" data-filter="<?php echo esc_attr('.' . $term->slug); ?>">
                <?php echo esc_html($term->name); ?>
                <?php if($settings['show_cat_count'] == '1'): ?>
                    <span class="filter-item-count"><?php echo esc_attr($tax_count); ?></span> 
                <?php endif; ?>
            </span>
        <?php endif; ?>
    <?php endforeach; ?>

    <?php $html = ob_get_clean();
    wp_send_json(
        array(
            'status' => true,
            'message' => esc_attr__('Load Successfully!', 'breeza'),
            'data' => array(
                'html' => $html,
                'paged' => $settings['paged'],
                'posts' => $posts,
                'max' => $max,
            ),
        )
    );
}
catch (Exception $e){
    wp_send_json(array('status' => false, 'message' => $e->getMessage()));
}
die;
}