<?php
get_header();

echo '<div class="container">';
pzy_breadcrumb_enabled() && pzy_breadcrumb();

$consulation_request_target = pzy_get_option('consulation_request_target');
$staff_archive_circle_avatar = pzy_get_option('staff_archive_circle_avatar');
$description = term_description();

?>
    <div class="pzy-section <?php echo pzy_breadcrumb_enabled()?'':'pzy-mt-40'?>">
        <header>
            <div class="pzy-header-title">
                <?php the_archive_title(); ?>
            </div>
            <div class="pzy-header-divider"></div>
            <div class="pzy_catalog_ordering">
                <i class="pzy_catalog_ordering_icon" data-feather="filter"></i>
                <span class="pzy_catalog_ordering_title"><?php esc_html_e('مرتب سازی بر اساس:', 'pezeshkyar') ?></span>
                <form method="get" id="pzy-sort-posts">
                    <input type="hidden" name="paged" value="<?php echo get_query_var('paged', '') ?>"/>
                    <select name="orderby" id="pzy-orderby" class="orderby">
                        <option value=""><?php esc_html_e('پیش فرض', "pezeshkyar") ?></option>
                        <option value="views" <?php isset($_GET['orderby']) && selected($_GET['orderby'], 'views'); ?>><?php esc_html_e('پربازدیدها', "pezeshkyar") ?></option>
                        <option value="popular" <?php isset($_GET['orderby']) && selected($_GET['orderby'], 'popular'); ?>><?php esc_html_e('محبوبیت', "pezeshkyar") ?></option>
                        <option value="new" <?php isset($_GET['orderby']) && selected($_GET['orderby'], 'new'); ?>><?php esc_html_e('جدیدترین', "pezeshkyar") ?></option>
                    </select>
                </form>
            </div>
        </header>
        <div class="pzy-section-content pzy-mt-40">
            <div class="pzy-archive">
                <aside class="pzy-archive-sidebar">
                    <?php get_sidebar('service'); ?>
                </aside>
                <section class="pzy-archive-content pzy-staffs-archive">
                    <div class="pzy-staffs-consultation">
                        <?php
                        if (have_posts()) {
                            ?>
                            <div class="pzy-services-loop">
                                <?php
                                while (have_posts()) {
                                    the_post();
                                    ?>
                                    <article class="pzy-staff-card">
                                        <div class="pzy-staff-special">
                                            <svg width="16" height="16" viewBox="0 0 16 16" fill="none"
                                                 xmlns="http://www.w3.org/2000/svg">
                                                <g id="Icon" clip-path="url(#clip0_2884_3321)">
                                                    <path id="path961"
                                                          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_2884_3321">
                                                        <rect width="16" height="16" fill="white"/>
                                                    </clipPath>
                                                </defs>
                                            </svg>
                                        </div>
                                        <?php $color = get_post_meta(get_the_ID(), 'color', true); ?>
                                        <div class="pzy-staff-avatar-box <?php echo $staff_archive_circle_avatar?'pzy-circle-avatar-box':''; ?> pzy-position-relative" <?php echo($color ? "style=background:$color" : "") ?>>
                                            <a href="<?php the_permalink(); ?>"
                                               class="pzy-d-block pzy-position-absolute 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>


                                        <h3 class="pzy-staff-title p-16-bold">
                                            <a href="<?php the_permalink(); ?>"><?php echo get_the_title() ?></a>
                                        </h3>
                                        <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()) ?>
                                            <?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>

                                        <?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 echo get_the_ID() ?>">
                                                <i class="pzy-staff-consultation-request-icon"
                                                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);
                                                }
                                                $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 class="pzy-staff-consultation-request-icon"
                                                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>
                                    <?php
                                }
                                ?>
                            </div>
                            <div class="pzy-pagination-links">
                                <?php
                                echo paginate_links();
                                ?>
                            </div>
                            <?php
                            if (pzy_get_option('consulation_request_target')=='show_form' && function_exists('pzy_show_consultation_form'))
                                pzy_show_consultation_form();
                        }
                        ?>
                </section>
            </div>
        </div>
        <?php if($description):?>
            <div class="pzy-service-description">
                <?php echo $description;?>
            </div>
        <?php endif;?>
    </div>
<?php

echo "</div>";

get_footer();