<?php

class PZY_Links_Slider extends \PEZESHKYAR\CORE\PZY_SWIPER
{
    public function get_name()
    {
        return 'pzy_links_slider';
    }

    public function get_title()
    {
        return esc_html__('اسلایدر لینک ', 'pezeshkyar');
    }

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

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

    public function get_keywords()
    {
        return ['pzy', 'links', 'slider'];
    }

    public function get_script_depends()
    {
        return ["swiper.js", "theme-script.js"];
    }

    public function get_style_depends()
    {
        return ['swiper.css'];
    }

    protected function register_controls()
    {

        // Content Tab Start

        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__('محتوای اسلایدر', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $links = new \Elementor\Repeater();

        $links->add_control('link_text', [
            'label' => esc_html__('متن', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__('Text Inside Link', 'pezeshkyar'),
            'label_block' => true,
        ]);
        $links->add_control('link_url', [
            'label' => esc_html__('پیوند', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::URL,
            'options' => ['url', 'is_external', 'nofollow'],
            'default' => [
                'url' => '#',
                'is_external' => false,
                'nofollow' => true,
            ],
            'label_block' => true,
            'dynamic' => [
                'active' => true,
            ],
        ]);

        $this->add_control(
            'links',
            [
                'label' => esc_html__('لیست لینک ها', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $links->get_controls(),
            ]
        );

        $this->add_control(
            'show_divider',
            [
                'label' => esc_html__( 'جدا کننده نشان داده شود؟', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('بله', 'pezeshkyar'),
                'label_off' => esc_html__('خیر', 'pezeshkyar'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'section_style',
            [
                'label' => esc_html__('استایل دهی اسلایدر', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_control(
            'link_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-service-name' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'link_typography',
                'selector' => '{{WRAPPER}} .pzy-service-name,{{WRAPPER}} a.pzy-service-name',
            ]
        );

        $this->add_control(
            'link_hover_color',
            [
                'label' => esc_html__('رنگ متن در حالت هاور', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-service-name:hover' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'link_hover_typography',
                'selector' => '{{WRAPPER}} .pzy-service-name:hover,{{WRAPPER}} a.pzy-service-name:hover',
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'divider_style',
            [
                'label' => esc_html__('جداکننده لینک ها', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'divider_width',
            [
                'label' => esc_html__('عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .swiper-slide:not(:last-child):after' => 'display: inline-block;content:"";width: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 0.5,
                ],
                'condition'=>[
                        'show_divider'=>'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_height',
            [
                'label' => esc_html__('ارتفاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .swiper-slide:not(:last-child):after' => 'height: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 12,
                ],
                'condition'=>[
                    'show_divider'=>'yes'
                ]
            ]
        );
        $this->add_responsive_control(
            'divider_margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .swiper-slide:not(:last-child):after' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'default' => [
                    'top' => 0,
                    'right' => 8,
                    'bottom' => 0,
                    'left' => 8,
                    'unit' => 'px',
                    'isLinked' => false,
                ],
                'condition'=>[
                    'show_divider'=>'yes'
                ]
            ]
        );

        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'background',
                'types' => [ 'classic', 'gradient', 'video' ],
                'selector' => '{{WRAPPER}} .pzy-links-slider .swiper-slide:not(:last-child):after',
                'condition'=>[
                    'show_divider'=>'yes'
                ]
            ]
        );

        $this->add_control(
            'divider_auto_width',
            [
                'label' => esc_html__( 'عرض لینکها اتوماتیک تنظیم شود؟', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => esc_html__('بله', 'pezeshkyar'),
                'label_off' => esc_html__('خیر', 'pezeshkyar'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->end_controls_section();

        parent::register_controls();

    }

    protected function render_slides()
    {
        $auto_width = $this->get_settings_for_display('divider_auto_width') == 'yes';
        foreach ($this->items as $link) {
            ?>
            <div class="swiper-slide <?php if ($auto_width) echo "pzy-auto-width";?>">
                <a class="pzy-service-name"
                   href="<?php echo $link['link_url']['url'] ?>"><?php echo $link['link_text']; ?></a>
            </div>
            <?php
        }
    }

    protected function render()
    {
        $links = $this->get_settings_for_display('links');
        if (count($links) > 0) {
            $this->set_items($links);
            ?>
            <div class="pzy-links-slider">
                <?php parent::render(); ?>
            </div>
            <?php
        }
    }
}