<?php

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

namespace Elementor;

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

class meditest_team_box_slides extends Widget_Base
{

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

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

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

    /**
     * Get widget categories.
     *
     * Retrieve the list of categories the Elementor widget belongs to.
     *
     * @return array Widget categories.
     * @since 1.0.0
     * @access public
     *
     */
    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();
        $this->style_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(
            'image',
            [
                'label' => esc_html__('Add Image', 'textdomain'),
                'type' => Controls_Manager::MEDIA,
                'default' => [
                    'url' => Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $repeater->add_control(
            'box_name',
            [
                'label' => esc_html__('Name', 'textdomain'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Dr. Daisy Bins', 'textdomain'),
                'label_block' => true,
            ]
        );
        $repeater->add_control(
            'box_title',
            [
                'label' => esc_html__('Title', 'textdomain'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Dentist surgeon', 'textdomain'),
                'label_block' => true,
            ]
        );
        $repeater->add_control(
            'box_text',
            [
                'label' => esc_html__('Short Description', 'textdomain'),
                'type' => Controls_Manager::TEXTAREA,
                'default' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit Nulla', 'textdomain'),
            ]
        );


        $repeater->add_control(
            'link_text',
            [
                'label' => esc_html__('Link Text', 'textdomain'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Read More', 'textdomain'),
            ]
        );

        $repeater->add_control(
            'profile_select',
            [
                'label' => 'Select Doctor Profile Post',
                'type' => Controls_Manager::SELECT,
                'options' => $this->get_doctor_profile_posts(),
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'icon_bg_color',
            [
                'label' => esc_html__('Icon Background Color', 'textdomain'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} {{CURRENT_ITEM}}' => 'background: {{VALUE}}',
                ],
            ]
        );
        $repeater->add_control(
            'icon_box_shasow',
            [
                'label' => esc_html__('Icon Background Shadow Color', 'textdomain'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} {{CURRENT_ITEM}}' => 'box-shadow: 0px 4px 40px -10px {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'service_list',
            [
                'label' => esc_html__('Service Slides', 'textdomain'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'box_title' => esc_html__('Dental Care', 'textdomain'),
                        'box_text' => esc_html__('Hospitals are equipped with advanced medical technologies and facilities.', 'textdomain'),
                    ],
                ],
                'title_field' => '{{{ box_title }}}',
            ]
        );


        $this->end_controls_section();
    }


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


        $this->start_controls_section(
            'style_option',
            [
                'label' => __('Style Options', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Name Typography', 'textdomain'),
                'name' => 'name_typo',
                'selector' => '{{WRAPPER}} .service-two-icon-box-conent.team-info h3.team-name',
            ]
        );
        $this->add_control(
            'name_typo_color',
            [
                'label' => esc_html__('Name Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .service-two-icon-box-conent.team-info h3.team-name' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Title Typography', 'textdomain'),
                'name' => 'title_typo',
                'selector' => '{{WRAPPER}} .service-two-icon-box-conent.team-info p.designation',
            ]
        );
        $this->add_control(
            'Title_typo_color',
            [
                'label' => esc_html__('Title Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .service-two-icon-box-conent.team-info p.designation' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Text Typography', 'textdomain'),
                'name' => 'text_typo',
                'selector' => '{{WRAPPER}} .service-two-icon-box-conent.team-info p',
            ]
        );
        $this->add_control(
            'Text_typo_color',
            [
                'label' => esc_html__('Text Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .service-two-icon-box-conent.team-info p' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Link Typography', 'textdomain'),
                'name' => 'link_typo',
                'selector' => '{{WRAPPER}} .service-two-icon-box-conent .service-two-icon-box-link',
            ]
        );

        $this->add_control(
            'Link_typo_color',
            [
                'label' => esc_html__('Link Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .service-two-icon-box-conent .service-two-icon-box-link a' => 'color: {{VALUE}}'
                ],
            ]
        );

        $this->end_controls_section();
    }


    protected function render()
    {


        $settings = $this->get_settings_for_display();

        $service_list = $settings['service_list'];


        ?>


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

                /* Main Slider */
                $('.team-box-slide-active').slick({
                    infinite: true,
                    slidesToShow: 4,
                    slidesToScroll: 1,
                    dots: false,
                    arrows: true,
                    autoplay: true,
                    speed: 800,
                    responsive: [{
                        breakpoint: 1024,
                        settings: {
                            slidesToShow: 3
                        }
                    },
                        {
                            breakpoint: 768,
                            settings: {
                                slidesToShow: 2
                            }
                        },
                        {
                            breakpoint: 480,
                            settings: {
                                slidesToShow: 1
                            }
                        }
                    ],

                    prevArrow: '<div class="service-box-slide-arrow-left"><i class="icon-arrow-left-11"></div>',
                    nextArrow: '<div class="service-box-slide-arrow-right"><i class="icon-arrow-right-11"></div>',

                });


            });
        </script>


        <div class="team-box-slide-active">
            <?php
            foreach ($service_list as $s_list) { ?>

                <div class="service_slide_inner">
                    <div class="team-info-box-section">
                        <div class="team-box-img">
                            <?php echo '<img src="' . $s_list['image']['url'] . '">'; ?>
                        </div>
                        <div class="service-two-icon-box-conent team-info">
                            <h3 class="team-name"><?php echo $s_list['box_name']; ?></h3>
                            <p class="designation"><?php echo $s_list['box_title']; ?></p>
                            <p><?php echo $s_list['box_text']; ?></p>
                            <div class="service-two-icon-box-link">
                                <a href="<?php echo esc_url(get_permalink($s_list['profile_select'])); ?>"><?php echo $s_list['link_text']; ?> </a>
                                <i class="icon-arrow-right1"></i>
                            </div>
                        </div>
                    </div>
                </div>

            <?php } ?>
        </div>

        <?php
    }

    // Function to retrieve "doctorsprofile" posts
    protected function get_doctor_profile_posts()
    {
        $args = [
            'post_type' => 'doctorsprofile',
            'posts_per_page' => -1,
        ];

        $doctorsprofiles = new \WP_Query($args);

        $profiles = [];

        if ($doctorsprofiles->have_posts()) {
            while ($doctorsprofiles->have_posts()) {
                $doctorsprofiles->the_post();
                $profiles[get_the_ID()] = get_the_title();
            }

            wp_reset_postdata();
        }

        return $profiles;
    }
}


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