<?php
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

/**
 * Elementor oEmbed Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.0
 */
class Elementor_slider_our_customers_Widget extends \Elementor\Widget_Base {

/**
 * Get widget name.
 *
 * Retrieve oEmbed widget name.
 *
 * @return string Widget name.
 * @since 1.0.0
 * @access public
 */
public function get_name()
{
    return 'hyperkala_slider_our_customers';
}

/**
 * Get widget title.
 *
 * Retrieve oEmbed widget title.
 *
 * @return string Widget title.
 * @since 1.0.0
 * @access public
 */
public function get_title()
{
    return 'اسلایدر مشتریان ما';
}

/**
 * Get widget icon.
 *
 * Retrieve oEmbed widget icon.
 *
 * @return string Widget icon.
 * @since 1.0.0
 * @access public
 */
public function get_icon()
{
    return 'eicon-frame-expand';
}

/**
 * Get custom help URL.
 *
 * Retrieve a URL where the user can get more information about the widget.
 *
 * @return string Widget help URL.
 * @since 1.0.0
 * @access public
 */
public function get_custom_help_url()
{
    return 'https://developers.elementor.com/docs/widgets/';
}

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

/**
 * Get widget keywords.
 *
 * Retrieve the list of keywords the oEmbed widget belongs to.
 *
 * @return array Widget keywords.
 * @since 1.0.0
 * @access public
 */
public function get_keywords()
{
    return ['oembed', 'url', 'link'];
}

/**
 * Register oEmbed widget controls.
 *
 * Add input fields to allow the user to customize the widget settings.
 *
 * @since 1.0.0
 * @access protected
 */
protected function register_controls()
{
    $this->start_controls_section(
        'title_section',
        [
            'label' => 'تنظیمات عنوان',
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
    );
    $this->add_control(
        'customer_slider_content_title',
        [
            'label' => 'عنوان بخش',
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => '',
            'placeholder' => 'عنوان بخش را وارد کنید',
        ]
    );
    $this->add_control(
        'customer_slider_icon',
        [
            'label' => 'آيکن',
            'type' => \Elementor\Controls_Manager::ICONS,
            'default' => [
                'value' => 'fas fa-circle',
                'library' => 'fa-solid',
            ],
        ]
    );
    $this->add_control(
        'customer_slider_more_title',
        [
            'label' => 'متن دکمه',
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => '',
            'placeholder' => 'متن روی دکمه مشاهده بیشتر را وارد کنید',
        ]
    );
    $this->add_control(
        'customer_slider_more_link',
        [
            'label' => 'لینک دکمه',
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => '',
            'placeholder' => 'https://your-link.ir',
        ]
    );
    $this->end_controls_section();
    $this->start_controls_section(
        'content_section',
        [
            'label' => 'تنظیمات محتوا',
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
    );

    $repeater = new \Elementor\Repeater();

    $repeater->add_control(
        'slide_image',
        [
            'label' => 'تصویر را انتخاب کنید',
            'type' => \Elementor\Controls_Manager::MEDIA,
            'default' => [
                'url' => \Elementor\Utils::get_placeholder_image_src(),
            ],
        ]
    );
    $repeater->add_control(
        'customer_title',
            [
            'label' => 'عنوان',
            'type' => \Elementor\Controls_Manager::TEXT,
            'placeholder' => 'هایپرکالا',
        ]
    );
    $repeater->add_control(
        'customer_link',
        [
        'label' => 'لینک',
            'type' => \Elementor\Controls_Manager::TEXT,
            'placeholder' => 'https://your-link.com',
        ]
    );

    $this->add_control(
        'our_customers',
        [
            'label' => "متن شرکت",
            'type' => \Elementor\Controls_Manager::REPEATER,
            'fields' => $repeater->get_controls(),
            'default' => [
                [
                    'list_title' => 'اسلاید ۱',
                    'list_content' => '',
                ],
            ],
            'title_field' => 'مشتری',
        ]
    );




    $this->end_controls_section();
    $this->start_controls_section(
        'slider_settings_section',
        [
            'label' => 'تنظیمات اسلایدر',
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
    );

    $this->add_control(
        'slider_customers_count_mobile',
        [
            'label' => 'تعداد نمایش اسلاید در گوشی',
            'type' => \Elementor\Controls_Manager::NUMBER,
            'min' => 1,
            'max' => 4,
            'step' => 1,
            'default' => 2,
        ]
    );
    $this->add_control(
        'slider_customers_count_tablet',
        [
            'label' => 'تعداد نمایش اسلاید در تبلت',
            'type' => \Elementor\Controls_Manager::NUMBER,
            'min' => 2,
            'max' => 6,
            'step' => 1,
            'default' => 4,
        ]
    );
    $this->add_control(
        'slider_customers_count_desktop',
        [
            'label' => 'تعداد نمایش اسلاید در دسکتاپ',
            'type' => \Elementor\Controls_Manager::NUMBER,
            'min' => 4,
            'max' => 10,
            'step' => 1,
            'default' => 6,
        ]
    );

    $this->add_control(
        'slider_customers_loop',
        [
            'label' => 'چرخش حلقه',
            'type' => \Elementor\Controls_Manager::SWITCHER,
            'label_on' => 'روشن',
            'label_off' => 'خاموش',
            'return_value' => 'yes',
            'default' => 'yes',
        ]
    );
    $this->add_control(
        'slider_customers_autoplay',
        [
            'label' => 'حرکت خودکار',
            'type' => \Elementor\Controls_Manager::SWITCHER,
            'label_on' => 'روشن',
            'label_off' => 'خاموش',
            'return_value' => 'yes',
            'default' => 'yes',
        ]
    );
    $this->add_control(
        'slider_customers_dots',
        [
            'label' => 'نقطه‌ها',
            'type' => \Elementor\Controls_Manager::SWITCHER,
            'label_on' => 'روشن',
            'label_off' => 'خاموش',
            'return_value' => 'yes',
            'default' => 'yes',
        ]
    );
    $this->add_control(
        'customers_slide_speed',
        [
            'label' => __( 'سرعت حرکت اسلایدها', 'plugin-domain' ),
            'type' => \Elementor\Controls_Manager::NUMBER,
            'min' => 200,
            'max' => 10000,
            'step' => 1,
            'default' => 5000,
        ]
    );

    $this->end_controls_section();

}

/**
 * Render oEmbed widget output on the frontend.
 *
 * Written in PHP and used to generate the final HTML.
 *
 * @since 1.0.0
 * @access protected
 */

protected function render() {
$settings = $this->get_settings_for_display();
$our_customers = $settings['our_customers'];
?>
    <script>
        $(function (){
        $('.customers-slider-element').owlCarousel({
            loop:<?php if ($settings['slider_customers_loop']) {echo "true"; } else {echo "false"; } ?>,
            margin:10,
            nav:true,
            dots:<?php if ($settings['slider_customers_dots']) {echo "true"; } else {echo "false"; } ?>,
            autoplay:<?php if ($settings['slider_customers_autoplay']) {echo "true"; } else {echo "false"; } ?>,
            autoplayTimeout:<?php echo $settings['customers_slide_speed']; ?>,
            autoplayHoverPause: true,
            responsive:{
                0:{
                    items:<?php echo $settings['slider_customers_count_mobile']; ?>
                },
                600:{
                    items:<?php echo $settings['slider_customers_count_tablet']; ?>
                },
                1000:{
                    items:<?php echo $settings['slider_customers_count_desktop']; ?>
                }
            }
        });
        });
    </script>
    <div class="customers-slider">
        <?php if ($settings['customer_slider_content_title']){?>
            <div class="title-section">
                <div class="title-item">
                    <a href="<?php echo $settings['customer_slider_more_link'];?>"><i class="fas fa-arrow-left"></i>
                        <span><?php echo $settings['customer_slider_more_title'];?></span></a>
                </div>
                <div class="title-item">
                    <span><?php echo $settings['customer_slider_content_title'];?></span>
                    <?php \Elementor\Icons_Manager::render_icon( $settings['customer_slider_icon'], [ 'aria-hidden' => 'true' ] ); ?>
                </div>
            </div>
        <?php }?>
        <div id="customers-slider-element" class="customers-slider-element owl-carousel owl-theme ">
            <?php foreach ($our_customers as $item){?>
                <?php if (!empty($item['customer_link'])){ ?><a href="<?php echo $item['customer_link'];?>"><?php }?><div class="item">
                        <img src="<?php echo $item['slide_image']['url'];?>" alt="">
                    <?php if (!empty($item['customer_title'])){ ?><p style="padding: 5px;
border-radius: 15px;
border: 1px solid #ddd;
  border-bottom-color: rgb(221, 221, 221);
  border-bottom-style: solid;
  border-bottom-width: 1px;
box-shadow: 0px 0px 5px 1px #eee;
border-bottom: 2px solid var(--maincolor);
margin-top: 7px;"><?php echo $item['customer_title'];?></p><?php }?>
                    </div><?php if (!empty($item['customer_link'])){ ?></a><?php }?>
            <?php }?>
        </div>
    </div>
    <?php
}

}
