<?php

class PZY_Divider extends \Elementor\Widget_Base
{
    public function get_name()
    {
        return 'pzy_divider';
    }

    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', 'divider'];
    }

    protected function register_controls()
    {
        $this->start_controls_section(
            'divider_content',
            [
                'label' => esc_html__('جدا کننده', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'divider_width',
            [
                'label' => esc_html__('عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-layout' => 'width: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
            ]
        );
        $this->add_control(
            'divider_height',
            [
                'label' => esc_html__('ارتفاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget' => 'height: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 1,
                ],
            ]
        );
        $this->add_control(
            'show_before_widget',
            [
                '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->add_control(
            'show_after_widget',
            [
                '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(
            'divider_style',
            [
                'label' => esc_html__('جدا کننده', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'divider_opacity',
            [
                'label' => esc_html__( 'شفافیت', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ '%' ],
                'range' => [
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget' => 'opacity: {{SIZE}}{{UNIT}};',
                ],
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'divider_background',
                'types' => ['classic', 'gradient', 'video'],
                'selector' => '{{WRAPPER}} .pzy-divider-widget',
            ]
        );

        $this->add_control(
            'before_divider_heading',
            [
                'label' => esc_html__( 'خط عمودی قبل از جداکننده', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
                'condition' => [
                    'show_before_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_before_width',
            [
                'label' => esc_html__('عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-before' => 'width: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 1,
                ],
                'condition' => [
                    'show_before_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_before_height',
            [
                'label' => esc_html__('ارتفاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-before' => 'height: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 12,
                ],
                'condition' => [
                    'show_before_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_before_opacity',
            [
                'label' => esc_html__( 'شفافیت', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ '%' ],
                'range' => [
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-before' => 'opacity: {{SIZE}}{{UNIT}};',
                ],
                'condition' => [
                    'show_before_widget' => 'yes'
                ]
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'divider_before_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-divider-widget-before',
                'condition' => [
                    'show_before_widget' => 'yes'
                ]
            ]
        );

        $this->add_control(
            'after_divider_heading',
            [
                'label' => esc_html__( 'خط عمودی بعد از جداکننده', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_after_width',
            [
                'label' => esc_html__('عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-after' => 'width: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 1,
                ],
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_after_height',
            [
                'label' => esc_html__('ارتفاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-after' => 'height: {{SIZE}}{{UNIT}};',
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 12,
                ],
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->add_control(
            'divider_after_opacity',
            [
                'label' => esc_html__( 'شفافیت', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ '%' ],
                'range' => [
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'default' => [
                    'unit' => '%',
                    'size' => 100,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-divider-widget-after' => 'opacity: {{SIZE}}{{UNIT}};',
                ],
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'divider_after_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-divider-widget-after',
                'condition' => [
                    'show_after_widget' => 'yes'
                ]
            ]
        );
        $this->end_controls_section();
    }

    protected function render()
    {
        ?>
        <div class="pzy-divider-widget-layout pzy-d-flex pzy-justify-content-center pzy-align-items-center">
            <?php if ('yes' == $this->get_settings_for_display('show_before_widget')): ?>
                <div class="pzy-divider-widget-before"></div>
            <?php endif;; ?>
            <div class="pzy-divider-widget pzy-flex-1"></div>
            <?php if ('yes' == $this->get_settings_for_display('show_after_widget')): ?>
                <div class="pzy-divider-widget-after"></div>
            <?php endif;; ?>

        </div>
        <?php
    }
}