<?php
    use Elementor\Group_Control_Image_Size;

    // $settings = $this->get_settings();
    $cat_custom_image      = widgetkit_pro_array_get($settings, 'image');
    $cat_custom_image_url      = $cat_custom_image['url'];
    $show_hide_lp_categories_courses      = widgetkit_pro_array_get($settings, 'show_hide_lp_categories_courses');
    $lp_course_category_id      = widgetkit_pro_array_get($settings, 'lp_course_category_id');

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

    // $this->add_render_attribute( 'wrapper', 'class', 'elementor-image' );
    // if ( ! empty( $settings['shape'] ) ) {
    //     $this->add_render_attribute( 'wrapper', 'class', 'elementor-image-shape-' . $settings['shape'] );
    // }

    if (class_exists('LearnPress')) :
        if( $lp_course_category_id ):
            $category = get_term( $lp_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="lp-course-categories">
            <?php echo Group_Control_Image_Size::get_attachment_image_html( $settings ); ?>
            <div class="content-body">
                <div class="lp-course-meta">
                    <a href="<?php echo esc_url($category_archive_link); ?>">
                        <h2 class="lp-categories">
                            <?php echo esc_html($category->name); ?>
                        </h2>
                    </a>
                    <?php if($show_hide_lp_categories_courses == 'yes'): ?>
                        <div class="lp-course">
                            <span>
                                <?php esc_html_e($category_course_count.' Courses', 'widgetkit-pro') ; ?>
                            </span>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    <?php 
        endif;
            else : ?>
            <div class="plugin-is-deactive">
                <div class="wrapper">
                    <?php if (!class_exists('LearnPress')) : ?>
                        <h3><?php esc_html_e('Please active LearnPress First', 'widgetkit-pro') ?></h3>
                    <?php endif; ?>
                </div>
            </div>
<?php endif; ?>
