<?php
// End recent blog with thumlist for post single page

global $slider_id;
function enqueue_owl_carousel_team($atts) {
    wp_enqueue_script('glorious-slider-script', get_stylesheet_directory_uri() . '/elementor/owl-carousel/js/owl.carousel.min.js', array(
        'jquery'
    ));
    wp_enqueue_style('glorious-slider-style', get_stylesheet_directory_uri() . '/elementor/owl-carousel/css/owl.carousel.min.css');
    wp_enqueue_style('owl-slider', get_stylesheet_directory_uri() . '/elementor/owl-carousel/css/owl-team.css');
    wp_add_inline_script("glorious-slider-script", "
        

       
    ");


}
add_action('wp_footer', 'enqueue_owl_carousel_team');

// Register the widget
add_action('elementor/widgets/widgets_registered', function () {
    class Custom_Widget extends \Elementor\Widget_Base {

        public function get_name() {
            return 'owl-slider-team';
        }

        public function get_title() {
            return __('Team', 'text-domain');
        }

        public function get_icon() {
            return 'eicon-button';
        }

        public function get_categories() {
            return ['basic'];
        }

        protected function _register_controls() {
            // Repeater control for dynamic content
            $this->start_controls_section(
                'content_section',
                [
                    'label' => __('Content', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
                ]
            );

            $repeater = new \Elementor\Repeater();
                        // Title field
                $repeater->add_control(
                    'title',
                    [
                        'label' => __('Title', 'text-domain'),
                        'type' => \Elementor\Controls_Manager::TEXT,
                        'default' => __('Title', 'text-domain'),
                        'label_block' => true,
                        'dynamic' => [
                            'active' => true,
                        ],
                        'title' => __('Item Title', 'text-domain'),
                        'placeholder' => __('Enter your title', 'text-domain'),
                        'default' => __('Default Title', 'text-domain'),
                    ]
                );
             
             $repeater->add_control(
                'education',
                [
                    'label' => __('Education', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::TEXT,
                 
                    'label_block' => true,
                ]
            );
                $repeater->add_control(
                    'designation',
                    [
                        'label' => __('Designation', 'text-domain'),
                        'type' => \Elementor\Controls_Manager::TEXT,
                        'label_block' => true,
                    ]
                );

                $repeater->add_control(
                    'teamUrl',
                    [
                        'label' => __('Url', 'text-domain'),
                        'type' => \Elementor\Controls_Manager::TEXT,
                        'label_block' => true,
                    ]
                );



                 // Image field
            $repeater->add_control(
                'image',
                [
                    'label' => __('Image', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::MEDIA,
                ]
            );


            $this->add_control(
                'items',
                [
                    'type' => \Elementor\Controls_Manager::REPEATER,
                    'fields' => $repeater->get_controls(),
                    'default' => [
                        [
                            'title' => __('Default Title', 'text-domain'),
                            'content' => __('Default Content', 'text-domain'),
                            'image' => '',
                            'button_text' => __('Read More', 'text-domain'),
                            'button_url' => ['url' => 'https://example.com'],
                        ],
                    ],
                    'title_field' => '{{{ title }}}',
                ]
            );

            $this->end_controls_section();
            $this->start_controls_section(
                'title_style_section',
                [
                    'label' => __('Title', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                ]
            );
            
            // Title padding control
            $this->add_responsive_control(
                'title_padding',
                [
                    'label' => __('Padding', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .team_name' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );
            
            $this->add_responsive_control(
                'title_color',
                [
                    'label' => __('Color', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .team_name' => 'color: {{VALUE}};',
                    ],
                ]
            );
            
            $this->add_group_control(
                \Elementor\Group_Control_Typography::get_type(),
                [
                    'name' => 'font_typography',
                    'selector' => '{{WRAPPER}} .team_name',
                ]
            );
            $this->end_controls_section();
            

            $this->start_controls_section(
                'education_style_section',
                [
                    'label' => __('Education', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                ]
            );
        
            // Title padding control
            $this->add_responsive_control(
                'education_padding',
                [
                    'label' => __('Padding', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .team_education' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );
           
            $this->add_responsive_control(
                'education_color',
                [
                    'label' => __('Color', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .team_designation' => 'color: {{VALUE}};',
                    ],
                ]
            );
            $this->add_group_control(
                \Elementor\Group_Control_Typography::get_type(),
                [
                    'name' => 'education_typography',
                    'selector' => '{{WRAPPER}} .team_designation',
                ]
            );

            $this->end_controls_section();

            $this->start_controls_section(
                'designation_style_section',
                [
                    'label' => __('Designation', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                ]
            );
        
            // Title padding control
            $this->add_responsive_control(
                'designation_padding',
                [
                    'label' => __('Padding', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .team_designation' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );
           
            $this->add_responsive_control(
                'designation_color',
                [
                    'label' => __('Color', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .team_designation' => 'color: {{VALUE}};',
                    ],
                ]
            );

            $this->add_group_control(
                \Elementor\Group_Control_Typography::get_type(),
                [
                    'name' => 'designation_typography',
                    'selector' => '{{WRAPPER}} .team_designation',
                ]
            );
            $this->end_controls_section();





            $this->start_controls_section(
                'img_style_section',
                [
                    'label' => __('Image', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                ]
            );

             //  padding control
             $this->add_responsive_control(
                'img_padding',
                [
                    'label' => __('Padding', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .owl-img' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );

              //  padding control
              $this->add_responsive_control(
                'img_margin',
                [
                    'label' => __('Margin', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .owl-img' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );



            $this->end_controls_section();

            $this->start_controls_section(
                'content_style_section',
                [
                    'label' => __('Content', 'text-domain'),
                    'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                ]
            );

             //  padding control
             $this->add_responsive_control(
                'content_padding',
                [
                    'label' => __('Padding', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .testimonials_content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );

              //  padding control
              $this->add_responsive_control(
                'content_margin',
                [
                    'label' => __('Margin', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::DIMENSIONS,
                    'size_units' => ['px', '%', 'em'],
                    'selectors' => [
                        '{{WRAPPER}} .testimonials_content' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                ]
            );

            $this->add_responsive_control(
                'content_color',
                [
                    'label' => __('Color', 'text-domain'),
                    'type' => \Elementor\Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .testimonials_content' => 'color: {{VALUE}};',
                    ],
                ]
            );
        


            $this->end_controls_section();


            
        }

        protected function render() {
            $settings = $this->get_settings_for_display();
            global $slider_id;
            echo  '<div class="custom-nav-team">
            <button class="prev-btn3"></button>
            <button class="next-btn3"></button>
          </div>';
          echo '<div class="owl-carousel gl_slider_team_01" id="_gl_slider_team_01">';
            foreach ($settings['items'] as $item) {
                ?>
              <div class="item">
            <div class="item-box">
                <div class="team_inner">
                    <a href=" <?php echo $item['teamUrl']; ?>" class="fulllink">URL</a>
                    <?php if (!empty($item['image']['url'])) : ?>
                        <div class="owl-img">
                            <img src="<?php echo esc_url($item['image']['url']); ?>" alt="<?php echo esc_attr($item['title']); ?>">
                        </div>
                    <?php endif; ?>
                    <div class="team_name">
                        <?php echo $item['title']; ?>
                    </div>
                    <div class="team_education">
                        <?php echo $item['education']; ?>
                    </div>
                    <div class="team_designation">
                        <?php echo $item['designation']; ?>
                    </div>
                </div>
            </div>
        </div>
                <?php
            }
            echo "</div>";
            ?>

            <script>
                jQuery(document).ready(function($) {
                    var owl = jQuery('#_gl_slider_team_01');
            owl.owlCarousel({
                stagePadding: 0,
                margin: 30,
                nav: false,
                dots: false,
                loop: true,
                autoplay:false,
                autoplayTimeout:1000,
                responsive: {
                    0: {
                        items: 1
                    },
                    600: {
                        items:3
                    },
                    1000: {
                        items: 5
                    }
                }
            })
        
          var prevBtn3 = jQuery('.prev-btn3');
        var nextBtn3 = jQuery('.next-btn3');
        var mySlider3 = jQuery('#_gl_slider_team_01'); // Replace 'mySlider3' with your actual slider ID
        
        // Manually control the slider navigation
        prevBtn3.click(function() {
          mySlider3.trigger('prev.owl.carousel');
        });
        
        nextBtn3.click(function() {
          mySlider3.trigger('next.owl.carousel');
        });
        
        // Update button states based on current slide index
        mySlider3.on('changed.owl.carousel', function(event) {
          var currentSlide = event.relatedTarget.current();
          var totalSlides = event.relatedTarget.maximum();
          prevBtn3.prop('disabled', currentSlide === 0);
          nextBtn3.prop('disabled', currentSlide === totalSlides - 0);
        
         
        });

    });

        </script>
         <?php 
          

            
        }
    }

    \Elementor\Plugin::instance()->widgets_manager->register_widget_type(new Custom_Widget());
    
});




?>