<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class MYEA_Courses1_Area_Widget extends \Elementor\Widget_Base {

    public function get_name() {
        return 'myea_courses1_area';
    }

    public function get_title() {
        return 'TG Courses1 Area';
    }

    public function get_icon() {
        return 'eicon-course';
    }

    public function get_categories() {
        return [ 'general' ];
    }

    protected function register_controls() {

        // Section Title Control
        $this->start_controls_section(
            'section_title_area',
            [
                'label' => 'Section Title',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'main_title',
            [
                'label' => 'Main Title',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Featured Courses',
            ]
        );

        $this->end_controls_section();

        // Repeater for Courses
        $this->start_controls_section(
            'section_courses',
            [
                'label' => 'Course Items',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
            'course_image',
            [
                'label' => 'Course Image',
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $repeater->add_control(
            'course_title',
            [
                'label' => 'Course Title',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Basic Philosophy',
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'course_content',
            [
                'label' => 'Description',
                'type' => \Elementor\Controls_Manager::TEXTAREA,
                'default' => 'Rmply dummy text printing setting industry it’s free demo.',
            ]
        );

        $repeater->add_control(
            'course_duration',
            [
                'label' => 'Duration (e.g. 1 Year)',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => '1 Year',
            ]
        );

        $repeater->add_control(
            'course_classes',
            [
                'label' => 'Total Classes',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => '40',
            ]
        );

        $repeater->add_control(
            'course_time',
            [
                'label' => 'Class Time',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => '10 am - 11 am',
            ]
        );

        $repeater->add_control(
            'course_link',
            [
                'label' => 'Course Link',
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => 'https://your-link.com',
            ]
        );

        $this->add_control(
            'courses',
            [
                'label' => 'Courses List',
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'course_title' => 'Basic Philosophy',
                    ],
                ],
                'title_field' => '{{{ course_title }}}',
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();

        if ( empty( $settings['courses'] ) ) {
            return;
        }
        ?>
        <div class="courses1-area">
            <div class="container">
                <?php if ( ! empty( $settings['main_title'] ) ) : ?>
                    <h2 class="title-default-left"><?php echo esc_html( $settings['main_title'] ); ?></h2>
                <?php endif; ?>
            </div>
            
            <div id="shadow-carousel" class="container">
                <div class="rc-carousel" 
                     data-loop="true" 
                     data-items="4" 
                     data-margin="20" 
                     data-autoplay="false" 
                     data-autoplay-timeout="10000" 
                     data-smart-speed="2000" 
                     data-dots="false" 
                     data-nav="true" 
                     data-r-x-small="1" 
                     data-r-x-medium="2" 
                     data-r-small="2" 
                     data-r-medium="3" 
                     data-r-large="4">
                    
                    <?php foreach ( $settings['courses'] as $index => $item ) : 
                        $link_key = 'link_' . $index;
                        if ( ! empty( $item['course_link']['url'] ) ) {
                            $this->add_link_attributes( $link_key, $item['course_link'] );
                        }
                    ?>
                    <div class="courses-box1 elementor-repeater-item-<?php echo esc_attr( $item['_id'] ); ?>">
                        <div class="single-item-wrapper">
                            <div class="courses-img-wrapper hvr-bounce-to-bottom">
                                <img class="img-responsive" src="<?php echo esc_url( $item['course_image']['url'] ); ?>" alt="<?php echo esc_attr( $item['course_title'] ); ?>">
                                <?php if ( ! empty( $item['course_link']['url'] ) ) : ?>
                                    <a <?php echo $this->get_render_attribute_string( $link_key ); ?>><i class="fa fa-link" aria-hidden="true"></i></a>
                                <?php endif; ?>
                            </div>
                            <div class="courses-content-wrapper">
                                <h3 class="item-title">
                                    <a <?php echo $this->get_render_attribute_string( $link_key ); ?>><?php echo esc_html( $item['course_title'] ); ?></a>
                                </h3>
                                <p class="item-content"><?php echo wp_kses_post( $item['course_content'] ); ?></p>
                                <ul class="courses-info">
                                    <li><?php echo esc_html( $item['course_duration'] ); ?>
                                        <br><span> Course</span></li>
                                    <li><?php echo esc_html( $item['course_classes'] ); ?>
                                        <br><span> Classes</span></li>
                                    <li><?php echo esc_html( $item['course_time'] ); ?>
                                        <br><span> Time</span></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                    
                </div>
            </div>
        </div>
        <?php
    }
}