<?php
class PZY_Breadcrumb extends \Elementor\Widget_Base
{
    public function get_name()
    {
        return 'pzy_breadcrumb';
    }

    public function get_title()
    {
        return esc_html__('مسیر راهنمای صفحات ', 'pezeshkyar');
    }

    public function get_icon()
    {
        return 'eicon-map-pin';
    }

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

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

    protected function register_controls(){
        $this->start_controls_section(
            'widget_style',
            [
                'label' => esc_html__( 'استایل دهی مسیر راهنما', 'pezeshkyar' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'content_typography',
                'selector' => '{{WRAPPER}} .pzy-breadcrumb-list-item',
            ]
        );
        $this->add_control(
            'margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'top' => 0,
                    'right' => 0,
                    'bottom' => 0,
                    'left' => 0,
                    'unit' => 'px',
                    'isLinked' => false,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-list' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'links_text_color',
            [
                'label' => esc_html__( 'رنگ لینک ها', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-list-item a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'links_hover_text_color',
            [
                'label' => esc_html__( 'رنگ لینک ها در حالت هاور', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-list-item a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'current_item_text_color',
            [
                'label' => esc_html__( 'رنگ مسیر صفحه جاری', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-list-item' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'breadcrumb_separator_icon',
            [
                'label' => esc_html__( 'جدا کننده', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::ICONS,
            ]
        );
        $this->add_control(
            'breadcrumb_gap',
            [
                'label' => esc_html__( 'فاصله جداکننده از آیتم ها', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-list' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'breadcrumb_separator_color',
            [
                'label' => esc_html__( 'رنگ', 'textdomain' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-separator svg' => 'fill: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'breadcrumb_separator_icon_size',
            [
                'label' => esc_html__( 'اندازه', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
                'default' => [
                    'unit' => 'px',
                    'size' => 16,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-separator svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'separator_align',
            [
                'label' => esc_html__( 'موقعیت جدا کننده', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'options' => [
                    'flex-start' => [
                        'title' => esc_html__( 'آغاز', 'pezeshkyar' ),
                        'icon' => 'eicon-flex eicon-align-start-v',
                    ],
                    'center' => [
                        'title' => esc_html__( 'مرکز', 'pezeshkyar' ),
                        'icon' => 'eicon-flex eicon-align-center-v',
                    ],
                    'flex-end' => [
                        'title' => esc_html__( 'پایان', 'pezeshkyar' ),
                        'icon' => 'eicon-flex eicon-align-end-v',
                    ],
                ],
                'default' => 'flex-start',
                'toggle' => true,
                'selectors' => [
                    '{{WRAPPER}} .pzy-breadcrumb-separator' => 'align-self: {{VALUE}};',
                ],
            ]
        );
        $this->end_controls_section();
    }

    protected function render()
    {
        $seperator = null;
        $breadcrumb_seperator_icon=$this->get_settings_for_display('breadcrumb_seperator_icon');
        if ($breadcrumb_seperator_icon && !empty($breadcrumb_seperator_icon['value'])) {
            ob_start();
            \Elementor\Icons_Manager::render_icon($breadcrumb_seperator_icon, ['aria-hidden' => 'true']);
            $seperator = ob_get_clean();
        }
        if (!empty($seperator)){
            pzy_breadcrumb($seperator);
        }else{
            pzy_breadcrumb();
        }
        echo <<<EOL
<script>
feather.replace();
</script>
EOL;
    }
}