<?php
    use Elementor\Group_Control_Image_Size;
    use Elementor\Icons_Manager;

    $cat_custom_image      = widgetkit_pro_array_get($settings, 'image');
    $cat_custom_image_url      = $cat_custom_image['url'];
    $show_hide_sensei_categories_courses      = widgetkit_pro_array_get($settings, 'show_hide_sensei_categories_courses');
    $sensei_course_category_id      = widgetkit_pro_array_get($settings, 'sensei_course_category_id');
    $sensei_category_icon_enable      = widgetkit_pro_array_get($settings, 'sensei_category_add_icon');
    $sensei_category_icon      = widgetkit_pro_array_get($settings, 'sensei_category_icon');

    if ( empty( $cat_custom_image_url ) ) {
        return;
    }

    if( $sensei_course_category_id ):
        $category = get_term( $sensei_course_category_id );
        $category_archive_link = get_term_link( $category->term_id );
        $category_course_count = $category->count;
        $category_archive_link = get_term_link( $category);
        ?>
        
        <div class="sensei-course-categories">
            <?php echo Group_Control_Image_Size::get_attachment_image_html( $settings ); ?>
            <div class="content-body">
                <div class="sensei-course-meta">
                    <?php if($sensei_category_icon_enable):?>
                        <span class="cat-icon">
                            <?php Icons_Manager::render_icon( $sensei_category_icon, [ 'aria-hidden' => 'true', 'class' => 'sensei-category-icon' ] ); ?>
                        </span>
                    <?php endif; ?>

                    <a href="<?php echo esc_url($category_archive_link); ?>">
                        <h2 class="sensei-categories">
                            <?php echo esc_html($category->name); ?>
                        </h2>
                    </a>
                    <?php if($show_hide_sensei_categories_courses == 'yes'): ?>
                        <div class="sensei-course">
                            <span>
                                <?php esc_html_e($category_course_count.' Courses', 'widgetkit-pro') ; ?>
                            </span>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    <?php endif;