<?php

/**
 * Elementor Widget
 * @package Meditest
 * @since 1.0.0
 */

namespace Elementor;

if (!defined('ABSPATH')) exit; // Exit if accessed directly.

class meditest_main_top_slider extends Widget_Base
{

	/**
	 * Get widget name.
	 *
	 * Retrieve Elementor widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name()
	{
		return 'maintop-slider';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return esc_html__('Main Top Slider', 'meditest-extra');
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Elementor widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'fas fa-th-large';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Elementor widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories()
	{
		return ['meditest_widgets'];
	}

	/**
	 * Register Elementor widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.0
	 * @access protected
	 */


	protected function register_controls()
	{
		$this->layout_options();
	}

	/**
	 * Layout Options
	 */
	private function layout_options()
	{


		$this->start_controls_section(
			'layout_option',
			[
				'label' => __('Layout Options', 'meditest-extra'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);


		$repeater = new Repeater();


		$repeater->add_control(
			'doctor_image',
			[
				'label' => esc_html__('Select Image', 'meditest-extra'),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => Utils::get_placeholder_image_src(),
				],
			]
		);

		$repeater->add_control(
			'rev_title',
			[
				'label' => esc_html__('Title', 'meditest-extra'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Best Service', 'meditest-extra'),
				'label_block' => true,
			]
		);


		$this->add_control(
			'doctor_lists',
			[
				'label' => esc_html__('Slider Image List', 'meditest-extra'),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'rev_title' => esc_html__('Best Service', 'meditest-extra'),
					],
				],
				'title_field' => '{{{ rev_title }}}',
			]
		);


		$this->add_responsive_control(
			'grid_img_height',
			[
				'label' => esc_html__('Post Image Height', 'meditest-extra'),
				'type' => Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
					],
				],
				'devices' => ['desktop', 'tablet', 'mobile'],
				'desktop_default' => [
					'size' => 620,
					'unit' => 'px',
				],
				'tablet_default' => [
					'size' => 500,
					'unit' => 'px',
				],
				'mobile_default' => [
					'size' => 400,
					'unit' => 'px',
				],

				'default'  => [
					'unit' => 'px',
					'size' => 620,
				],

				'selectors' => [
					'{{WRAPPER}} .main-top-slider .main-top-slider-item img ' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->end_controls_section();
        $this->start_controls_section(
            'layout_style_option',
            [
                'label' => __('Array Style', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'array_style_left_bg',
            [
                'label' => esc_html__( 'Array Left Background Color', 'meditest-extra' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .slide-arrow-left.slick-arrow' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'array_style_hvoe_left_bg',
            [
                'label' => esc_html__( 'Array Left  Hover Background Color', 'meditest-extra' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .slide-arrow-left.slick-arrow:hover' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'array_style_right_bg',
            [
                'label' => esc_html__( 'Array Right Background Color', 'meditest-extra' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .slide-arrow-right.slick-arrow' => 'background-color: {{VALUE}}',
                ],
            ]
        );


        $this->add_control(
            'array_style_hvoe_right_bg',
            [
                'label' => esc_html__( 'Array Right Hover  Background Color', 'meditest-extra' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .slide-arrow-right.slick-arrow:hover' => 'background-color: {{VALUE}}',
                ],
            ]
        );

		$this->end_controls_section();
	}

	protected function render()
	{

		$settings = $this->get_settings_for_display();

?>


		<script type="text/javascript">
			jQuery(document).ready(function($) {

				/* Main Slider */
				$('.main-top-slider').slick({
					infinite: true,
					dots: false,
					arrows: true,
					fade: true,
					autoplay: true,
					speed: 800,
					slidesToShow: 1,

					prevArrow: '<div class="slide-arrow-left"></div>',
					nextArrow: '<div class="slide-arrow-right"></div>',

				});

			});
		</script>


		<div class="main-top-slider-section theme-main-top-slider-wrapper">

			<div class="main-top-slider">
				<?php foreach ($settings['doctor_lists'] as $doctor_item) { ?>
					<div class="main-top-slider-item">
						<img src="<?php echo $doctor_item['doctor_image']['url']; ?>" alt="<?php echo get_the_title($doctor_item['doctor_image']['id']); ?>">
					</div>
				<?php } ?>
			</div>

		</div>


<?php
	}
}

Plugin::instance()->widgets_manager->register_widget_type(new meditest_main_top_slider());
