<?php

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

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

    public function get_script_depends()
    {
        return ["pzy-services-list"];
    }

    public function get_style_depends()
    {
        return ['swiper.css', 'pzy-services-list'];
    }

    protected function register_controls()
    {
        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__('خدمات', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $items = new \Elementor\Repeater();
        $items->add_control('icon', [
            'label' => esc_html__('آیکن', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::ICONS,
        ]);
        $items->add_control('title', [
            'label' => __('عنوان', 'pezeshkyar'),
            'show_label' => true,
            'label_block' => true,
            'type' => \Elementor\Controls_Manager::TEXT,
        ]);
        $items->add_control('subtitle', [
            'label' => __('زیر عنوان', 'pezeshkyar'),
            'show_label' => true,
            'label_block' => true,
            'type' => \Elementor\Controls_Manager::TEXT,
        ]);
        $items->add_control('short_description', [
            'label' => __('معرفی کوتاه', 'pezeshkyar'),
            'show_label' => true,
            'label_block' => true,
            'type' => \Elementor\Controls_Manager::WYSIWYG,
        ]);
        $items->add_control('button_link', [
            'label' => esc_html__('پیوند', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::URL,
            'options' => ['url', 'is_external', 'nofollow'],
            'default' => [
                'url' => '',
                'is_external' => false,
                'nofollow' => true,
            ],
            'dynamic' => [
                'active' => true
            ],
            'label_block' => true,
        ]);
        $items->add_control('button_text', [
            'label' => __('متن دکمه مشاهده بیشتر', 'pezeshkyar'),
            'show_label' => true,
            'label_block' => true,
            'default' => esc_html__('اطلاعات بیشتر', 'pezeshkyar'),
            'type' => \Elementor\Controls_Manager::TEXT,
        ]);

        $this->add_control(
            'items',
            [
                'label' => esc_html__('لیست خدمات', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $items->get_controls()
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'cart_box_style',
            [
                'label' => esc_html__('تنظیمات کلی کارت', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'cart_box_padding',
            [
                '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' => true,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'cart_box_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'cart_box_border',
                'selector' => '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item',
            ]
        );
        $this->add_control(
            'cart_box_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'cart_header_style',
            [
                'label' => esc_html__('هدر کارت', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'cart_header_margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'top' => 24,
                    'right' => 18,
                    'bottom' => 0,
                    'left' => 18,
                    'unit' => 'px',
                    'isLinked' => false,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-header' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'service_icon_size',
            [
                'label' => esc_html__('اندازه آیکن', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'default' => [
                    'unit' => 'px',
                    'size' => 48,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-item-image svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'service_icon_color',
            [
                'label' => esc_html__('رنگ آیکن', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'description'=>__('در صورتی که از کتابخانه استفاده کنید می توانید رنگ آیکن را انتخاب کنید','pezeshkyar'),
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-item-image svg' => 'fill: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'service_title_heading',
            [
                'label' => esc_html__( 'عنوان سرویس', 'textdomain' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'service_title_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-header .pzy-services-item-title' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'service_title_typography',
                'selector' => '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-header .pzy-services-item-title',
            ]
        );
        $this->add_control(
            'service_subtitle_heading',
            [
                'label' => esc_html__( 'زیر عنوان سرویس', 'textdomain' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'service_subtitle_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-header .pzy-services-item-description' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'service_subtitle_typography',
                'selector' => '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-header .pzy-services-item-description',
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'cart_body_style',
            [
                'label' => esc_html__('محتوای کارت', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'cart_body_margin',
            [
                'label' => esc_html__('حاشیه خارجی', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'default' => [
                    'top' => 14,
                    'right' => 24,
                    'bottom' => 0,
                    'left' => 24,
                    'unit' => 'px',
                    'isLinked' => false,
                ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-body' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'cart_body_height',
            [
                'label' => esc_html__( 'ارتفاع', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-body' => 'height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'cart_body_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-body' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'cart_body_typography',
                'selector' => '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-body',
            ]
        );
        $this->add_control(
            'text_align',
            [
                'label' => esc_html__('ترازبندی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__('چپ', 'pezeshkyar'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('وسط', 'pezeshkyar'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('راست', 'pezeshkyar'),
                        'icon' => 'eicon-text-align-right',
                    ],
                    'justify' => [
                        'title' => esc_html__('ترازشده', 'pezeshkyar'),
                        'icon' => 'eicon-text-align-justify',
                    ],
                ],
                'default' => 'justify',
                'toggle' => true,
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-body' => 'text-align: {{VALUE}};',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'cart_footer_style',
            [
                'label' => esc_html__('فوتر کارت', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'cart_footer_bottom',
            [
                'label' => esc_html__( 'فاصله از پایین', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-footer' => 'bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'cart_footer_left',
            [
                'label' => esc_html__( 'فاصله از چپ', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
                'selectors' => [
                    '{{WRAPPER}} .pzy-services-list-slider .pzy-services-item-footer' => 'left: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'details_style',
            [
                'label' => esc_html__( 'اطلاعات بیشتر', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_responsive_control(
            'cart_details_text_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-text' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'cart_details_text_color',
            [
                'label' => esc_html__('رنگ متن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-text' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'cart_details_typography',
                'selector' => '{{WRAPPER}} .pzy-show-service-detail-text',
            ]
        );
        $this->add_control(
            'cart_details_gap',
            [
                'label' => esc_html__('فاصله متن و آیکن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'details_icon_style',
            [
                'label' => esc_html__( 'آیکن اطلاعات بیشتر', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_responsive_control(
            'cart_details_icon_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar-core'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-icon-box' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'cart_details_icon_size',
            [
                'label' => esc_html__('اندازه آیکن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-icon' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'cart_details_icon_color',
            [
                'label' => esc_html__('رنگ آیکن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-icon' => 'stroke: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'cart_details_icon_background',
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .pzy-show-service-detail-icon-box',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'cart_details_icon_border',
                'selector' => '{{WRAPPER}} .pzy-show-service-detail-icon-box',
            ]
        );
        $this->add_control(
            'cart_details_icon_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-show-service-detail-icon-box' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();


        parent::register_controls();

    }

    protected function render_slides()
    {
        foreach ($this->items as $item) {
            ?>
            <div class="swiper-slide">
                <div class="pzy-services-item">
                    <div class="pzy-services-item-header">
                        <?php if (isset($item['icon'])): ?>
                            <div class="pzy-services-item-image">
                                <?php Elementor\Icons_Manager::render_icon($item['icon']) ?>
                            </div>
                        <?php endif; ?>

                        <div class="pzy-services-item-title-description">
                            <?php if (isset($item['title'])): ?>
                                <h3 class="pzy-services-item-title"><?php echo $item['title'] ?></h3>
                            <?php endif; ?>
                            <?php if (isset($item['subtitle'])): ?>
                                <h4 class="pzy-services-item-description"><?php echo $item['subtitle'] ?></h4>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="pzy-services-item-body">
                        <?php echo $item['short_description'] ?? '' ?>
                    </div>
                    <div class="pzy-services-item-footer">
                        <div class="pzy-show-service-detail">
                            <span class="pzy-show-service-detail-text"><?php echo $item['button_text'] ?? '' ?></span>
                            <a href="<?php echo $item['button_link']['url']??'';?>" class="pzy-show-service-detail-icon-box">
                                <?php if(is_rtl()):?>
                                    <i class="pzy-show-service-detail-icon" data-feather="arrow-left"></i>
                                <?php else:?>
                                    <i class="pzy-show-service-detail-icon" data-feather="arrow-right"></i>
                                <?php endif;?>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <?php
        }
    }


    protected function render()
    {
        $items = $this->get_settings_for_display('items') ?? [];
        if (count($items) > 0) {
            $this->set_items($items);
            ?>
            <div class="pzy-services-list-slider">
                <?php parent::render(); ?>
            </div>
            <?php
            echo <<<EOL
            <script>
            feather.replace();
            </script>
EOL;
        }
    }
}