<!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_Lecturers_Area_Widget extends \Elementor\Widget_Base {

    public function get_name() {
        return 'myea_lecturers_area';
    }

    public function get_title() {
        return 'TG Lecturers Area';
    }

    public function get_icon() {
        return 'eicon-person';
    }

    public function get_categories() {
        return [ 'general' ];
    }

    protected function register_controls() {

        // Section Header
        $this->start_controls_section(
            'section_header',
            [
                'label' => 'Section Header',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title',
            [
                'label' => 'Main Title',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Our Skilled Lecturers',
            ]
        );

        $this->end_controls_section();

        // Lecturers Repeater
        $this->start_controls_section(
            'section_lecturers',
            [
                'label' => 'Lecturers List',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
            'lecturer_image',
            [
                'label' => 'Photo',
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $repeater->add_control(
            'lecturer_name',
            [
                'label' => 'Name',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Rosy Janner',
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'lecturer_designation',
            [
                'label' => 'Designation',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Senior Lecturer',
            ]
        );

        // Social Links
        $repeater->add_control(
            'facebook_link',
            [
                'label' => 'Facebook URL',
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => 'https://facebook.com/username',
            ]
        );

        $repeater->add_control(
            'twitter_link',
            [
                'label' => 'Twitter URL',
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => 'https://twitter.com/username',
            ]
        );

        $repeater->add_control(
            'linkedin_link',
            [
                'label' => 'Linkedin URL',
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => 'https://linkedin.com/in/username',
            ]
        );

        $this->add_control(
            'lecturers',
            [
                'label' => 'Lecturers',
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'lecturer_name' => 'Rosy Janner',
                        'lecturer_designation' => 'Senior Lecturer',
                    ],
                ],
                'title_field' => '{{{ lecturer_name }}}',
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();

        if ( empty( $settings['lecturers'] ) ) {
            return;
        }
        ?>
        
        <div class="lecturers-page-area">
            <div class="container">
                <?php if ( ! empty( $settings['title'] ) ) : ?>
                    <h2 class="title-default-left"><?php echo esc_html( $settings['title'] ); ?></h2>
                <?php endif; ?>

                <div class="row">
                    <?php foreach ( $settings['lecturers'] as $index => $item ) : ?>
                        <div class="col-xl-3 col-lg-3 col-md-6 col-sm-12 elementor-repeater-item-<?php echo esc_attr( $item['_id'] ); ?>">
                            <div class="single-item">
                                <div class="lecturers1-item-wrapper">
                                    <div class="lecturers-img-wrapper">
                                        <a href="#"><img class="img-responsive" src="<?php echo esc_url( $item['lecturer_image']['url'] ); ?>" alt="team"></a>
                                    </div>
                                    <div class="lecturers-content-wrapper">
                                        <h3 class="item-title"><a href="#"><?php echo esc_html( $item['lecturer_name'] ); ?></a></h3>
                                        <span class="item-designation"><?php echo esc_html( $item['lecturer_designation'] ); ?></span>
                                        <ul class="lecturers-social">
                                            <?php if ( ! empty( $item['facebook_link']['url'] ) ) : ?>
                                                <li><a href="<?php echo esc_url( $item['facebook_link']['url'] ); ?>"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
                                            <?php endif; ?>
                                            
                                            <?php if ( ! empty( $item['twitter_link']['url'] ) ) : ?>
                                                <li><a href="<?php echo esc_url( $item['twitter_link']['url'] ); ?>"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
                                            <?php endif; ?>

                                            <?php if ( ! empty( $item['linkedin_link']['url'] ) ) : ?>
                                                <li><a href="<?php echo esc_url( $item['linkedin_link']['url'] ); ?>"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>
                                            <?php endif; ?>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>

        <?php
    }
}