<?php
get_header();
if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( 'single' ) ) {

$pzy_single_staff_template = pzy_get_option('pzy_single_staff_template');
if($pzy_single_staff_template){
    pzy_load_element_template($pzy_single_staff_template);
}else{

    $consulation_request_target = pzy_get_option('consulation_request_target');
    $consulation_request_target_blank_target = pzy_get_option('consulation_request_target_blank_target');

?>

<div class="container">
    <div class="pzy-staffs-consultation">

        <?php pzy_breadcrumb_enabled() && pzy_breadcrumb(); ?>

        <div id="staff-<?php the_ID(); ?>" <?php post_class('pzy-single-staff'); ?>>

            <?php
            $gallery = get_post_meta(get_the_ID(), 'gallery', true);
            $gallery_images = [];
            if ($gallery) {
                $gallery_images = json_decode($gallery);
            }
            if (count($gallery_images) > 0) {
                echo "<div class='pzy-gallery pzy-staff-gallery pzy-d-flex pzy-flex-column-reverse-nowrap pzy-gap-20'>";

                $thumbnail_settings = [
                    "rtl" => is_rtl(),
                    "direction" => 'horizontal',
                    "watchSlidesProgress" => true,
                    "navigation" => [
                        "nextEl" => '.swiper-button-next',
                        "prevEl" => '.swiper-button-prev',
                        "enabled" => false
                    ],
                    "breakpointsInverse" => true,
                    "observer" => true,
                    "slidesPerView" => 4,
                    "spaceBetween" => 30,
                    'loop' => true,
                ];

                echo "<div class='pzy-thumbnail-gallery'>";
                echo "<div class='swiper custom-init' data-settings='" . esc_attr(json_encode($thumbnail_settings, true)) . "'>";
                echo "<div class='swiper-wrapper'>";

                foreach ($gallery_images as $image) {
                    $gallery_image_url_thumbnail = wp_get_attachment_image_url($image);

                    echo '<div class="swiper-slide">';
                    echo '<div class="pzy-slide-content"><img src="' . esc_url($gallery_image_url_thumbnail) . '"></div>';
                    echo '</div>';
                }

                echo "</div>";

                echo '<div class="swiper-button-prev"></div>';
                echo '<div class="swiper-button-next"></div>';
                echo '<div class="swiper-pagination"></div>';

                echo "</div>";
                echo "</div>";


                $main_gallery_settings = [
                    "rtl" => is_rtl(),
                    "autoHeight" => true,
                    "watchSlidesProgress" => true,
                    "navigation" => [
                        "nextEl" => '.swiper-button-next',
                        "prevEl" => '.swiper-button-prev',
                        "enabled" => true
                    ],
                    "slidesPerView" => 1,
                    'spaceBetween' => 30,
                    "loop"=>true,
                ];

                /* main gallery */
                echo "<div class='pzy-main-gallery'>";
                echo "<div class='swiper custom-init' data-settings='" . esc_attr(json_encode($main_gallery_settings, true)) . "'>";
                echo "<div class='swiper-wrapper'>";

                foreach ($gallery_images as $image) {
                    $gallery_image_url_large = wp_get_attachment_image_url($image, 'large');

                    echo '<div class="swiper-slide">';
                    echo '<div class="pzy-slide-content"><img src="' . esc_url($gallery_image_url_large) . '" loading="lazy"/><div class="swiper-lazy-preloader"></div></div>';
                    echo '</div>';
                }

                echo "</div>";

                echo '<div class="swiper-button-next"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="92" viewBox="0 0 32 92" fill="none">
  <path d="M32 92L32 0L32 0.0714264L32 0.583168C32 10.635 26.0265 19.7254 16.8 23.7143L12.9824 25.4672C5.07084 29.1001 -1.41094e-06 37.0085 -1.79148e-06 45.7143C-2.17108e-06 54.3985 5.12298 62.2653 13.0654 65.7772L16.8 67.4286C26.0522 71.6025 32 80.8107 32 90.9609L32 92Z" fill="white"/>
</svg></div>';
                echo '<div class="swiper-button-prev"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="92" viewBox="0 0 32 92" fill="none">
<path d="M0 92L-4.02145e-06 0L-4.01833e-06 0.0714264L-3.99596e-06 0.583168C-3.55658e-06 10.635 5.97355 19.7254 15.2 23.7143L19.0176 25.4672C26.9292 29.1001 32 37.0085 32 45.7143C32 54.3985 26.877 62.2653 18.9346 65.7772L15.2 67.4286C5.94779 71.6025 -4.89099e-07 80.8107 -4.54226e-08 90.9609L0 92Z" fill="white"/>
</svg></div>';


                echo "</div>";
                echo "</div>";

                /* main gallery */


                echo "</div>";
            }
            ?>

            <div class="pzy-staff-content-box">
                <div class="py-staff-information">
                    <div class="py-staff-information-card">
                        <div class="pzy-staff-information-card-content">
                            <div class="pzy-staff-information-card-title"><?php esc_html_e('عضو ثابت', 'pezeshkyar'); ?></div>
                            <div class="pzy-staff-information-card-description">
                                <?php echo pzy_get_count(get_post_meta(get_the_ID(), 'fixed_member', true)); ?><?php esc_html_e('نفر', 'pezeshkyar'); ?></div>
                        </div>
                        <div class="pzy-staff-information-card-icon">
                            <i data-feather="user-check"></i>
                        </div>
                    </div>
                    <div class="py-staff-information-card">
                        <div class="pzy-staff-information-card-content">
                            <div class="pzy-staff-information-card-title"><?php esc_html_e('مشاوره آنلاین', 'pezeshkyar'); ?></div>
                            <div class="pzy-staff-information-card-description">
                                <?php echo pzy_get_count(get_post_meta(get_the_ID(), 'online_counseling', true)); ?><?php esc_html_e('ساعت', 'pezeshkyar'); ?></div>
                        </div>
                        <div class="pzy-staff-information-card-icon">
                            <i data-feather="headphones"></i>
                        </div>
                    </div>
                    <div class="py-staff-information-card">
                        <div class="pzy-staff-information-card-content">
                            <div class="pzy-staff-information-card-title"><?php esc_html_e('مشاوره های روزانه', 'pezeshkyar'); ?></div>
                            <div class="pzy-staff-information-card-description">
                                <?php echo pzy_get_count(get_post_meta(get_the_ID(), 'daily_consultations', true)); ?><?php esc_html_e('عدد', 'pezeshkyar'); ?></div>
                        </div>
                        <div class="pzy-staff-information-card-icon">
                            <i data-feather="users"></i>
                        </div>
                    </div>
                    <div class="py-staff-information-card">
                        <div class="pzy-staff-information-card-content">
                            <div class="pzy-staff-information-card-title"><?php esc_html_e(pzy_get_option('consultation_request_title'), 'pezeshkyar'); ?></div>
                            <div class="pzy-staff-information-card-description">
                                <?php echo pzy_get_count(get_post_meta(get_the_ID(), 'consultation_request', true)); ?><?php esc_html_e('عدد', 'pezeshkyar'); ?></div>
                        </div>
                        <div class="pzy-staff-information-card-icon">
                            <i data-feather="check-circle"></i>
                        </div>
                    </div>
                </div>
                <div class="pzy-staff-content">
                    <div class="pzy-staff-content-header">
                        <div class="pzy-d-flex pzy-flex-row-wrap pzy-align-items-start pzy-justify-content-between">
                            <div class="pzy-d-flex pzy-flex-column-wrap pzy-align-items-start">
                                <h2 class="text-primary-500 h4-18-bold"><?php the_title() ?></h2>
                                <div class="pzy-d-flex pzy-flex-row-wrap pzy-gap-40 pzy-align-items-center">
                                    <?php if ($job_description = get_post_meta(get_the_ID(), 'job_description', true)): ?>
                                        <h3 class="text-gray-300 p-16-regular"><?php echo $job_description; ?></h3>
                                    <?php endif; ?>
                                    <div class="pzy-staff-point">
                                        <?php echo apply_filters('pzy_core_staff_point', get_the_ID()) ?>

                                        <?php $rating_type = pzy_get_option('staff_rating_type')??'count';?>
                                        <?php if($rating_type == 'count'){?>
                                            <?php if (function_exists('rmp_get_vote_count') && ($vote_count = rmp_get_vote_count()) >0 ): ?>
                                                <span class="t-13-regular text-gray-300"><?php echo sprintf(esc_html__('%d نظر','pezeshkyar-core'), $vote_count)  ?></span>
                                            <?php endif; ?>
                                        <?php }elseif($rating_type=='average'){?>
                                            <?php if (function_exists('rmp_get_avg_rating') && ($vote_average = rmp_get_avg_rating(get_the_ID())) > 0): ?>
                                                <span class="t-13-regular text-gray-300"><?php echo $vote_average;?></span>
                                            <?php endif; ?>
                                        <?php }?>
                                    </div>
                                </div>
                            </div>
                            <?php if (get_post_meta(get_the_ID(), 'is_verified', true)): ?>
                                <div>
                                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
                                         fill="none">
                                        <g clip-path="url(#clip0_1422_4282)">
                                            <path d="M24 12C23.9777 11.1745 23.726 10.3715 23.2732 9.68087C22.8204 8.99027 22.1843 8.43934 21.4361 8.08976C21.7197 7.3141 21.7812 6.47468 21.6137 5.66596C21.4461 4.85725 21.0562 4.11135 20.4878 3.5122C19.8887 2.94377 19.1427 2.55386 18.334 2.38632C17.5253 2.21879 16.6859 2.28029 15.9102 2.5639C15.5618 1.8149 15.0111 1.17806 14.3203 0.72508C13.6294 0.272105 12.8258 0.0209858 12 0C11.1755 0.0204479 10.3733 0.271488 9.68422 0.724655C8.99516 1.17782 8.44685 1.81499 8.10146 2.5639C7.32403 2.2793 6.48261 2.21727 5.67185 2.3848C4.86109 2.55233 4.11316 2.94277 3.5122 3.5122C2.95564 4.11866 2.57876 4.868 2.4237 5.6764C2.26863 6.4848 2.3415 7.3204 2.63415 8.08976C1.87365 8.43041 1.22379 8.97729 0.75822 9.6684C0.292649 10.3595 0.0299848 11.1672 0 12C0.0299848 12.8328 0.292649 13.6405 0.75822 14.3316C1.22379 15.0227 1.87365 15.5696 2.63415 15.9102C2.34904 16.6849 2.28565 17.5236 2.4511 18.3323C2.61655 19.1409 3.0043 19.8874 3.57073 20.4878C4.17131 21.0539 4.91718 21.4422 5.72533 21.6097C6.53349 21.7771 7.37225 21.717 8.14829 21.4361C8.49339 22.1756 9.03526 22.806 9.7146 23.2582C10.3939 23.7104 11.1846 23.967 12 24C12.8258 23.979 13.6294 23.7279 14.3203 23.2749C15.0111 22.8219 15.5618 22.1851 15.9102 21.4361C16.6825 21.74 17.5267 21.8117 18.3392 21.6426C19.1516 21.4734 19.897 21.0707 20.4839 20.4839C21.0707 19.897 21.4734 19.1516 21.6426 18.3392C21.8117 17.5267 21.74 16.6825 21.4361 15.9102C22.1843 15.5607 22.8204 15.0097 23.2732 14.3191C23.726 13.6285 23.9777 12.8255 24 12ZM10.2907 16.9171L5.9122 12.5385L7.56293 10.8293L10.2088 13.4751L15.8283 7.35219L17.5493 8.94439L10.2907 16.9171Z"
                                                  fill="#1D9BF0"/>
                                        </g>
                                        <defs>
                                            <clipPath id="clip0_1422_4282">
                                                <rect width="24" height="24" fill="white"/>
                                            </clipPath>
                                        </defs>
                                    </svg>
                                </div>
                            <?php endif; ?>
                        </div>

                    </div>
                    <div class="pzy-staff-content-body">
                        <?php the_content(); ?>
                    </div>
                    <div class="pzy-staff-content-footer">
                        <div class="pzy-end-buttons">

                        <?php
                            if(in_array($consulation_request_target,['single_page','show_form'])){
                        ?>

                            <button class="pzy-staff-consultation-request" data-staff-name="<?php echo esc_attr(get_the_title());?>" data-staff="<?php the_ID() ?>">
                                <i data-feather="message-square"></i>
                                <span class="pzy-staff-consultation-request-title"><?php esc_html_e('Consultation Request','pezeshkyar');?></span>
                            </button>

                            <?php 
                                }else{
                                    $staff_link = '';

                                    if($consulation_request_target == 'specific_link'){
                                        $staff_link = get_post_meta(get_the_ID(),'pzy_specific_link',true);
                                    }
        
                                    if($consulation_request_target == 'single_page'){
                                        $staff_link = get_permalink(get_the_ID());
                                    }elseif($consulation_request_target == 'specific_link'){
                                        $staff_link = get_post_meta(get_the_ID(),'pzy_specific_link',true);
                                    }
                                    $consulation_request_target_blank_target = pzy_get_option('consulation_request_target_blank_target');
                                    ?>
                                    <a class="pzy-staff-consultation-request"
                                        <?php if($staff_link):?>
                                            href="<?php echo esc_url($staff_link)?>"
                                            <?php echo $consulation_request_target_blank_target?"target='_blank'":''?>
                                        <?php endif;?>  
                                    >
                                        <i data-feather="message-square"></i>
                                        <span class="pzy-staff-consultation-request-title"><?php esc_html_e('Consultation Request','pezeshkyar');?></span>
                                    </a>
                                    <?php
                                }
                            ?>
                            
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <?php

        if (in_array($consulation_request_target,['single_page','show_form']) && function_exists('pzy_show_consultation_form'))
            pzy_show_consultation_form();

        ob_start();
        if (comments_open() || get_comments_number())
            comments_template();
        $comments_template = ob_get_clean();

        $args = [
            'post_type' => 'pzy_staff',
            'posts_per_page' => 6,
            'post__not_in' => array(get_the_ID())
        ];
        $latest_posts_query = new \WP_Query($args);

        $slider_settings = [
            'slidesPerView' => 1,
            'spaceBetween' => 0,
            'navigation' => [
                "nextEl" => '.swiper-button-next',
                "prevEl" => '.swiper-button-prev',
                'enabled' => false
            ],
            'rtl' => is_rtl(),
            'spaceBetween' => 18,
            'breakpoints' => [
                "1024" => [
                    'slidesPerView' => 4.5,
                ],
                "768" => [
                    'slidesPerView' => 3,
                    'spaceBetween' => 18,
                ],
            ]
        ];

        if ($latest_posts_query->have_posts()) {
            ?>
            <div class="pzy-section pzy-mt-90">
                <header>
                    <div class="pzy-header-title">
                        <i data-feather="user"></i>
                        <?php esc_html_e('متخصصین مشابه','pezeshkyar'); ?>
                    </div>
                    <div class="pzy-header-divider"></div>
                    <a href="" class="pzy-header-link">
                        <?php esc_html_e('مشاهده همه','pezeshkyar');?>
                        <i data-feather="chevron-left"></i>
                    </a>
                </header>
                <div class="pzy-section-content pzy-mt-60">
                    <div class="slider-wrapper">
                        <div class="swiper pzy-wp-swiper pzy-posts-slider"
                            data-settings="<?php echo esc_attr(json_encode($slider_settings)) ?>">
                            <div class="swiper-wrapper">
                                <?php
                                while ($latest_posts_query->have_posts()) {
                                    $latest_posts_query->the_post();
                                    // Output your post template here
                                    ?>
                                    <div class="swiper-slide">
                                        <article class="pzy-staff-card">
                                            <?php if (get_post_meta(get_the_ID(), 'is_verified', true)): ?>
                                                <div class="pzy-staff-special">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        viewBox="0 0 16 16"
                                                        fill="none">
                                                        <g clip-path="url(#clip0_1422_4418)">
                                                            <path d="M16 8C15.9851 7.44966 15.8173 6.91432 15.5155 6.45392C15.2136 5.99352 14.7895 5.62623 14.2907 5.39317C14.4798 4.87606 14.5208 4.31645 14.4091 3.77731C14.2974 3.23817 14.0375 2.7409 13.6585 2.34146C13.2591 1.96252 12.7618 1.70257 12.2227 1.59088C11.6835 1.47919 11.1239 1.52019 10.6068 1.70927C10.3745 1.20993 10.0074 0.785371 9.54684 0.483387C9.08628 0.181403 8.55056 0.0139906 8 0C7.45035 0.0136319 6.91552 0.180992 6.45615 0.483103C5.99677 0.785214 5.63123 1.20999 5.40098 1.70927C4.88269 1.51953 4.32174 1.47818 3.78123 1.58987C3.24072 1.70155 2.7421 1.96185 2.34146 2.34146C1.97043 2.74578 1.71917 3.24533 1.6158 3.78426C1.51242 4.3232 1.561 4.88026 1.7561 5.39317C1.2491 5.62027 0.815861 5.98486 0.50548 6.4456C0.195099 6.90635 0.0199899 7.44482 0 8C0.0199899 8.55518 0.195099 9.09365 0.50548 9.5544C0.815861 10.0151 1.2491 10.3797 1.7561 10.6068C1.56602 11.1232 1.52376 11.6824 1.63407 12.2215C1.74437 12.7606 2.00286 13.2583 2.38049 13.6585C2.78088 14.0359 3.27812 14.2948 3.81689 14.4064C4.35566 14.5181 4.91483 14.478 5.4322 14.2907C5.66226 14.7838 6.0235 15.204 6.4764 15.5055C6.92929 15.8069 7.45639 15.978 8 16C8.55056 15.986 9.08628 15.8186 9.54684 15.5166C10.0074 15.2146 10.3745 14.7901 10.6068 14.2907C11.1217 14.4933 11.6845 14.5411 12.2261 14.4284C12.7678 14.3156 13.2647 14.0471 13.6559 13.6559C14.0471 13.2647 14.3156 12.7678 14.4284 12.2261C14.5411 11.6845 14.4933 11.1217 14.2907 10.6068C14.7895 10.3738 15.2136 10.0065 15.5155 9.54608C15.8173 9.08568 15.9851 8.55034 16 8ZM6.86049 11.278L3.94146 8.35902L5.04195 7.21951L6.80585 8.98341L10.5522 4.90146L11.6995 5.96293L6.86049 11.278Z"
                                                                fill="#1D9BF0"/>
                                                        </g>
                                                        <defs>
                                                            <clipPath id="clip0_1422_4418">
                                                                <rect width="16" height="16" fill="white"/>
                                                            </clipPath>
                                                        </defs>
                                                    </svg>
                                                </div>
                                            <?php endif; ?>

                                            <?php $color = get_post_meta(get_the_ID(), 'color', true); ?>
                                            <div class="pzy-staff-avatar-box" <?php echo ($color?"style=background:$color":"")?>>
                                                <a href="<?php the_permalink(); ?>" class="pzy-staff-avatar-link">
                                                    <img class="pzy-staff-card-avatar"
                                                        src="<?php echo get_the_post_thumbnail_url(get_the_ID()) ?>"
                                                        alt="<?php echo get_the_title() ?>"/>
                                                </a>
                                            </div>


                                            <a href="<?php the_permalink(); ?>"><h3
                                                        class="pzy-staff-title"><?php echo get_the_title() ?></h3></a>
                                            <h4 class="pzy-staff-subtitle"><?php echo get_post_meta(get_the_ID(), 'job_description', true) ?></h4>

                                            <div class="pzy-staff-point">
                                                <?php echo apply_filters('pzy_core_staff_point', get_the_ID()) ?>
                                                <span class="t-13-regular text-gray-300"><?php echo get_comments_number_text() ?></span>
                                            </div>

                                            <?php if($consulation_request_target == 'show_form'):?>
                                                <button class="pzy-staff-consultation-request" data-staff-name="<?php echo esc_attr(get_the_title());?>" data-staff="<?php the_ID() ?>">
                                                    <i data-feather="message-square"></i>
                                                    <span class="pzy-staff-consultation-request-title"><?php esc_html_e(pzy_get_option('consultation_request_title'),'pezeshkyar');?></span>
                                                </button>
                                            <?php else:?>
                                                <?php
                                                $staff_link = '';
                                                if($consulation_request_target == 'single_page'){
                                                    $staff_link = get_permalink(get_the_ID());
                                                }elseif($consulation_request_target == 'specific_link'){
                                                    $staff_link = get_post_meta(get_the_ID(),'pzy_specific_link',true);
                                                }
                                                ?>
                                                <a class="pzy-staff-consultation-request"
                                                <?php if($staff_link):?>
                                                    href="<?php echo esc_url($staff_link)?>"
                                                    <?php echo $consulation_request_target_blank_target?"target='_blank'":''?>
                                                <?php endif;?>   
                                                >
                                                    <i data-feather="message-square"></i>
                                                    <span class="pzy-staff-consultation-request-title"><?php esc_html_e(pzy_get_option('consultation_request_title'),'pezeshkyar');?></span>
                                                </a>
                                            <?php endif;?>
                                        </article>
                                    </div>
                                    <?php
                                }
                                ?>
                            </div>
                            <div class="swiper-button-next"></div>
                            <div class="swiper-button-prev"></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        }

        echo $comments_template;

        ?>

    </div>
</div>

<?php 
}
}
get_footer();
 ?>
