<?php

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

namespace Elementor;

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

class meditest_patient_testimonials 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 'patient-testimonials';
    }

    /**
     * Get widget title.
     *
     * Retrieve Elementor widget title.
     *
     * @return string Widget title.
     * @since 1.0.0
     * @access public
     *
     */
    public function get_title()
    {
        return esc_html__('Testimonials', '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();
    }

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


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

        $this->add_control(
            'layout_style',
            [
                'label' => esc_html__('Select Layout Style', 'textdomain'),
                'type' => Controls_Manager::SELECT,
                'default' => 'st_one',
                'options' => [
                    'st_one' => esc_html__('Layout Style One', 'textdomain'),
                    'st_two' => esc_html__('Layout Style Two', 'textdomain'),
                    'st_three' => esc_html__('Layout Style Three', 'textdomain'),
                    'st_four' => esc_html__('Layout Style Four', 'textdomain'),
                    'st_five' => esc_html__('Layout Style Five', 'textdomain'),
                ],
            ]
        );

        $this->add_control(
            'number_of_slide',
            [
                'label' => esc_html__('Number of Slide Show', 'textdomain'),
                'description' => esc_html__('This number work only for Layout Style One', 'textdomain'),
                'type' => Controls_Manager::NUMBER,
                'min' => 1,
                'max' => 50,
                'step' => 1,
                'default' => 4,
            ]
        );

        $this->add_control(
            'autoplay_enable',
            [
                'label' => esc_html__('Enable Autoplay', 'textdomain'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Yes', 'textdomain'),
                'label_off' => esc_html__('No', 'textdomain'),
                'return_value' => 'true',
                'default' => 'false',
            ]
        );


        $repeater = new Repeater();


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

        $repeater->add_control(
            'testi_name',
            [
                'label' => esc_html__('Name', 'meditest-extra'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Carry Malan', 'meditest-extra'),
                'label_block' => true,
            ]
        );
        $repeater->add_control(
            'testi_deg',
            [
                'label' => esc_html__('Designation', 'meditest-extra'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Happy Patients', 'meditest-extra'),
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'testi_description',
            [
                'label' => esc_html__('Textimonial Text', 'meditest-extra'),
                'type' => Controls_Manager::TEXTAREA,
                'rows' => 10,
                'default' => esc_html__('hospitals play a vital role in medical research and education. Many hospitals are affiliated with academic	institutions, fostering an environment of constant learning, innovation, and the exchange of medical knowledge. These institutions serve as training grounds for aspiring healthcare professionals, where they can gain hands-on experience and learn from experienced mentors. Be ready to provide your full name, contact information,', 'meditest-extra'),
            ]
        );

        $repeater->add_control(
            'testi_rating',
            [
                'label' => esc_html__('Rating', 'textdomain'),
                'type' => Controls_Manager::NUMBER,
                'min' => 1,
                'max' => 5,
                'step' => 1,
                'default' => 5,
            ]
        );

        $this->add_control(
            'testi_lists',
            [
                'label' => esc_html__('Testimonial List', 'meditest-extra'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'testi_name' => esc_html__('Carry Malan', 'meditest-extra'),
                    ],
                ],
                'title_field' => '{{{ testi_name }}}',
            ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'review_layout_option',
            [
                'label' => __('Review Style', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Name Typography', 'meditest-extra'),
                'name' => 'review_name_Typography',
                'selector' => '{{WRAPPER}} .testi-patient-data h4',
            ]
        );
        $this->add_control(
            'review_name_color',
            [
                'label' => esc_html__('Name Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testi-patient-data h4' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Designation Typography', 'meditest-extra'),
                'name' => 'review_Designation_Typography',
                'selector' => '{{WRAPPER}} .testi-patient-data p',
            ]
        );
        $this->add_control(
            'review_Designation_color',
            [
                'label' => esc_html__('Designation Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testi-patient-data p' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => esc_html__('Decription Typography', 'meditest-extra'),
                'name' => 'review_Decription_Typography',
                'selector' => '{{WRAPPER}} p',
            ]
        );
        $this->add_control(
            'review_Decription_color',
            [
                'label' => esc_html__('Decription Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} p' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->end_controls_section();
        $this->start_controls_section(
            'review_array',
            [
                'label' => __('Review array style', 'meditest-extra'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'review_arrey_color',
            [
                'label' => esc_html__('Review Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-arrow-left.slick-arrow , {{WRAPPER}} .testimonial-arrow-right.slick-arrow' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_control(
            'review_arrey_hover_color',
            [
                'label' => esc_html__('Review Hover Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-arrow-right.slick-arrow:hover, {{WRAPPER}} .testimonial-arrow-left.slick-arrow:hover' => 'color: {{VALUE}}'
                ],
            ]
        );
        $this->add_control(
            'review_arrey_bg_color',
            [
                'label' => esc_html__('Review Background Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-arrow-left.slick-arrow, {{WRAPPER}} .testimonial-arrow-right.slick-arrow' => 'background-color: {{VALUE}}'
                ],
            ]
        );
        $this->add_control(
            'review_arrey_bg_hover_color',
            [
                'label' => esc_html__('Review Background Hover Color', 'meditest-extra'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-arrow-right.slick-arrow:hover, {{WRAPPER}} .testimonial-arrow-left.slick-arrow:hover' => 'background-color: {{VALUE}}'
                ],
            ]
        );
        $this->end_controls_section();
    }


    protected function render()
    {


        $settings = $this->get_settings_for_display();

        $layout_style = $settings['layout_style'];


        ?>


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

                var number_of_slide = "<?php (int)$settings['number_of_slide']; ?>";

                /* Style One */
                $('.navfor-img-slide').not('.slick-initialized').slick({
                    infinite: true,
                    dots: false,
                    arrows: false,
                    autoplay: false,
                    speed: 800,
                    slidesToShow: number_of_slide,
                    slidesToScroll: 1,
                    focusOnSelect: true,
                    asNavFor: '.navfor-testimonials-slide',
                });


                $('.navfor-testimonials-slide').not('.slick-initialized').slick({
                    infinite: true,
                    dots: false,
                    arrows: true,
                    autoplay: false,
                    speed: 600,
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    adaptiveHeight: true,
                    asNavFor: '.navfor-img-slide',


                    prevArrow: '<div class="testimonial-arrow-left"></div>',
                    nextArrow: '<div class="testimonial-arrow-right"></div>',
                });

                /* Style Two */
                $('.navfor-testimonials-slide-st-two').not('.slick-initialized').slick({
                    infinite: true,
                    dots: false,
                    arrows: true,
                    autoplay: true,
                    speed: 600,
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    adaptiveHeight: true,

                    prevArrow: '<div class="testimonial-arrow-left"></div>',
                    nextArrow: '<div class="testimonial-arrow-right"></div>',
                });

                /* Style Three */
                $('.navfor-testimonials-slide-st-three').not('.slick-initialized').slick({
                    infinite: true,
                    dots: true,
                    dotsClass: 'testi-slide-st-three-dots',
                    arrows: false,
                    autoplay: true,
                    speed: 600,
                    slidesToShow: 3,
                    slidesToScroll: 1,
                    adaptiveHeight: true,
                    centerMode: true,
                    responsive: [{
                        breakpoint: 767,
                        settings: {
                            slidesToShow: 1,
                            centerMode: false,
                        }

                    }],
                });

                /* Style Three */
                $('.navfor-testimonials-slide-st-four').not('.slick-initialized').slick({
                    infinite: true,
                    dots: true,
                    dotsClass: 'testi-slide-st-three-dots',
                    arrows: false,
                    autoplay: true,
                    speed: 600,
                    slidesToShow: 1,
                    slidesToScroll: 1,
                    adaptiveHeight: true,
                });


                /* Style Five */
                $('.navfor-testimonials-slide-st-five').not('.slick-initialized').slick({
                    infinite: true,
                    dots: true,
                    dotsClass: 'testi-slide-st-three-dots',
                    arrows: false,
                    autoplay: true,
                    speed: 600,
                    slidesToShow: 3,
                    slidesToScroll: 1,
                    adaptiveHeight: true,
                    responsive: [{
                        breakpoint: 768,
                        settings: {
                            slidesToShow: 1
                        }
                    }],
                });

            });
        </script>
        <?php
        switch ($layout_style) {
            // Style One
            case 'st_one': ?>
                <div class="testimonials-section-wrap">
                    <div class="meditest-testimonials">
                        <div class="navfor-img-slide">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>
                                    <div class="nav-for-img">
                                        <img src="<?php echo esc_url($testimonial['testi_image']['url']); ?>" alt="">
                                    </div>
                                <?php }
                            } ?>
                        </div>

                        <div class="navfor-testimonials-slide">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>

                                    <div class="navfor-testimonial-content">
                                        <p><?php echo wp_kses_post($testimonial['testi_description']); ?></p>
                                        <div class="testi-ratings">

                                            <div class="testi-ratings-line">
                                                <?php for ($i = 0; $i < 5; $i++) {
                                                    echo '<i class="ri-star-line"></i>';
                                                } ?>
                                            </div>
                                            <div class="testi-ratings-fill">
                                                <?php
                                                for ($r = 0; $r < $testimonial['testi_rating']; $r++) {
                                                    echo '<i class="ri-star-fill"></i>';
                                                }
                                                ?>
                                            </div>

                                        </div>

                                        <div class="testi-patient-info">
                                            <div class="testi-patient-img">
                                                <img src="<?php echo esc_url($testimonial['testi_image']['url']); ?>"
                                                     alt="">
                                            </div>
                                            <div class="testi-patient-data">
                                                <h4><?php echo wp_kses_post($testimonial['testi_name']); ?></h4>
                                                <p><?php echo wp_kses_post($testimonial['testi_deg']); ?></p>
                                            </div>
                                        </div>

                                    </div>

                                <?php }
                            } ?>

                        </div>
                    </div>
                </div>

                <?php
                break;

            // Style Two
            case 'st_two': ?>
                <div class="testimonials-section-wrap">
                    <div class="meditest-testimonials">

                        <div class="navfor-testimonials-slide-st-two">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>
                                    <div class="navfor-testimonial-content">

                                        <div class="testi-ratings">
                                            <div class="testi-ratings-line">
                                                <?php for ($i = 0; $i < 5; $i++) {
                                                    echo '<i class="ri-star-line"></i>';
                                                } ?>
                                            </div>
                                            <div class="testi-ratings-fill">
                                                <?php
                                                for ($r = 0; $r < $testimonial['testi_rating']; $r++) {
                                                    echo '<i class="ri-star-fill"></i>';
                                                }
                                                ?>
                                            </div>
                                        </div>

                                        <p><?php echo wp_kses_post($testimonial['testi_description']); ?></p>

                                        <div class="testi-patient-info">
                                            <div class="testi-patient-data">
                                                <h4><?php echo wp_kses_post($testimonial['testi_name']); ?></h4>
                                                <p><?php echo wp_kses_post($testimonial['testi_deg']); ?></p>
                                            </div>
                                        </div>

                                    </div>

                                <?php }
                            } ?>

                        </div>
                    </div>
                </div>
                <?php break;

            // Style Three
            case 'st_three': ?>
                <div class="testimonials-section-wrap">
                    <div class="meditest-testimonials">
                        <div class="navfor-testimonials-slide-st-three">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>
                                    <div class="navfor-testimonial-content">
                                        <div class="testi-patient-info">
                                            <div class="testi-patient-img">
                                                <img src="<?php echo esc_url($testimonial['testi_image']['url']); ?>"
                                                     alt="">
                                            </div>
                                            <div class="testi-patient-data">
                                                <h4><?php echo wp_kses_post($testimonial['testi_name']); ?></h4>
                                                <p><?php echo wp_kses_post($testimonial['testi_deg']); ?></p>
                                            </div>
                                        </div>
                                        <p><?php echo wp_kses_post($testimonial['testi_description']); ?></p>
                                    </div>

                                <?php }
                            } ?>

                        </div>
                    </div>
                </div>

                <?php
                break;


            // Style Four
            case 'st_four': ?>
                <div class="testimonials-section-wrap">
                    <div class="meditest-testimonials">
                        <div class="navfor-testimonials-slide-st-four">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>
                                    <div class="navfor-testimonial-content">
                                        <div class="testi-patient-info">
                                            <div class="testi-patient-img">
                                                <img src="<?php echo esc_url($testimonial['testi_image']['url']); ?>"
                                                     alt="">
                                            </div>
                                            <div class="testi-patient-data">
                                                <h4><?php echo wp_kses_post($testimonial['testi_name']); ?></h4>
                                                <p><?php echo wp_kses_post($testimonial['testi_deg']); ?></p>
                                            </div>
                                        </div>
                                        <p><?php echo wp_kses_post($testimonial['testi_description']); ?></p>
                                    </div>

                                <?php }
                            } ?>

                        </div>
                    </div>
                </div>

                <?php
                break;
            case 'st_five': ?>

                <div class="testimonials-section-wrap">
                    <div class="meditest-testimonials">
                        <div class="navfor-testimonials-slide-st-five">
                            <?php if ($settings['testi_lists']) {
                                foreach ($settings['testi_lists'] as $testimonial) {
                                    ?>
                                    <div class="navfor-testimonial-content">
                                        <div class="testi-patient-info">
                                            <div class="testi-patient-img">
                                                <img src="<?php echo esc_url($testimonial['testi_image']['url']); ?>"
                                                     alt="">
                                            </div>
                                            <div class="testi-patient-data">
                                                <h4><?php echo wp_kses_post($testimonial['testi_name']); ?></h4>
                                                <p><?php echo wp_kses_post($testimonial['testi_deg']); ?></p>
                                            </div>
                                        </div>
                                        <p><?php echo wp_kses_post($testimonial['testi_description']); ?></p>
                                    </div>

                                <?php }
                            } ?>

                        </div>
                    </div>
                </div>


                <?php
                break;
        }
        ?>


        <?php
    }
}


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