<?php

class Pzy_Product_Information extends \Elementor\Widget_Base
{
    public function get_name()
    {
        return 'pzy_product_information';
    }

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

    public function add_script_depends($handler)
    {
        return ['theme-script.js'];
    }

    public function get_style_depends()
    {
        return ['theme-style.css'];
    }

    protected function register_controls()
    {
        $this->start_controls_section(
            'content_section',
            [
                'label' => esc_html__('محتوا', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'show_status',
            [
                '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_comments_count',
            [
                '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_price',
            [
                '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(
            'content_style',
            [
                'label' => esc_html__('استایل', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'status_heading',
            [
                'label' => esc_html__( 'موجودی محصول', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'status_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-product-availability' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'status_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-product-availability' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'status_typography',
                'selector' => '{{WRAPPER}} .pzy-product-availability',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'status_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-product-availability',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'status_border',
                'selector' => '{{WRAPPER}} .pzy-product-availability',
            ]
        );
        $this->add_control(
            'status_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-product-availability' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'comments_count_heading',
            [
                'label' => esc_html__( 'تعداد دیدگاه', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'comments_count_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-review-count' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'comments_count_typography',
                'selector' => '{{WRAPPER}} .pzy-review-count',
            ]
        );
        $this->add_control(
            'comments_count_gap',
            [
                'label' => esc_html__('فاصله نوشته و آیکن', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-review-count' => 'gap: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'comments_count_icon_size',
            [
                'label' => esc_html__('سایز آیکون', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-review-count svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'comments_count_icon_color',
            [
                'label' => esc_html__('رنگ آیکن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-review-count svg' => 'stroke: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'old_price_heading',
            [
                'label' => esc_html__( 'قیمت قبل از تخفیف', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'old_price_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-price .pzy-regular-price' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'old_price_typography',
                'selector' => '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-price .pzy-regular-price',
            ]
        );

        $this->add_control(
            'price_heading',
            [
                'label' => esc_html__( 'قیمت کنونی', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'price_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-price .pzy-price' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'price_typography',
                'selector' => '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-price .pzy-price',
            ]
        );
        $this->add_control(
            'discount_badge_heading',
            [
                'label' => esc_html__( 'باکس تخفیف', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        /**/
        $this->add_control(
            'discount_badge_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'discount_badge_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount .pzy-product-discount-percentage' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'discount_badge_typography',
                'selector' => '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount .pzy-product-discount-percentage',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'discount_badge_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount ',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'discount_badge_border',
                'selector' => '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount',
            ]
        );
        $this->add_control(
            'discount_badge_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy_product_after_introduction .price .pzy-product-discount' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'quantity_style',
            [
                'label' => esc_html__('تعداد', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'quantity_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-add-to-cart-quantity' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'quantity_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-add-to-cart-quantity',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'quantity_border',
                'selector' => '{{WRAPPER}} .pzy-add-to-cart-quantity',
            ]
        );
        $this->add_control(
            'quantity_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-add-to-cart-quantity' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'change_quantity_buttons',
            [
                'label' => esc_html__( 'دکمه های افزایش و کاهش تعداد', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'change_quantity_padding',
            [
                'label' => esc_html__('فاصله داخلی', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-change-quantity' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'change_quantity_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} .pzy-change-quantity',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'change_quantity_border',
                'selector' => '{{WRAPPER}} .pzy-change-quantity',
            ]
        );
        $this->add_control(
            'change_quantity_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-change-quantity' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'change_quantity_color',
            [
                'label' => esc_html__( 'رنگ', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pzy-change-quantity svg path' => 'stroke: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'change_quantity_size',
            [
                'label' => esc_html__('سایز', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .pzy-change-quantity svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();

        $this->start_controls_section(
            'add_to_cart_style',
            [
                'label' => esc_html__('دکمه افزودن به سبد خرید', 'pezeshkyar'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'add_to_cart_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} form.cart .button',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Border::get_type(),
            [
                'name' => 'add_to_cart_border',
                'selector' => '{{WRAPPER}} form.cart .button',
            ]
        );
        $this->add_control(
            'add_to_cart_radius',
            [
                'label' => esc_html__('شعاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em', 'rem', 'custom'],
                'selectors' => [
                    '{{WRAPPER}} form.cart .button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'add_to_cart_width',
            [
                'label' => esc_html__('عرض', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} form.cart .button' => 'width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'add_to_cart_height',
            [
                'label' => esc_html__('ارتفاع', 'pezeshkyar'),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} form.cart .button' => 'height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'add_to_cart_text_color',
            [
                'label' => esc_html__('رنگ متن', 'textdomain'),
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} form.cart .button' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'add_to_cart_typography',
                'selector' => '{{WRAPPER}} form.cart .button',
            ]
        );

        $this->add_control(
            'add_to_cart_hover_heading',
            [
                'label' => esc_html__( 'حالت هاور دکمه', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'add_to_cart_hover_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} form.cart .button:hover',
            ]
        );
        $this->add_control(
            'add_to_cart_disabled_heading',
            [
                'label' => esc_html__( 'حالت غیرفعال دکمه', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'add_to_cart_disabled_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} form.cart .button.disabled',
            ]
        );
        $this->add_control(
            'add_to_cart_disabled_hover_heading',
            [
                'label' => esc_html__( 'حالت هاور و غیرفعال دکمه', 'pezeshkyar' ),
                'type' => \Elementor\Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name' => 'add_to_cart_disabled_hover_background',
                'types' => ['classic', 'gradient'],
                'selector' => '{{WRAPPER}} form.cart .button.disabled:hover',
            ]
        );
        $this->end_controls_section();
    }

    protected function render()
    {
        global $product;
        if (!$product) {
            return;
        }

        $show_status = $this->get_settings_for_display('show_status');
        $show_comments_count = $this->get_settings_for_display('show_comments_count');
        $show_price = $this->get_settings_for_display('show_price');
        ?>
        <div class='pzy_product_after_introduction'>
            <?php
            if ($show_status)
                pzy_show_stock_status();
            if ($show_comments_count)
                pzy_show_comments_count();
            if ($show_price)
                pzy_wc_template_single_price();
            ?>
        </div>
        <?php
        if ($show_price)
            woocommerce_template_single_add_to_cart();

        echo <<<EOL
<script>
feather.replace();
</script>
EOL;
    }
}