<?php

namespace Elementor;

if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly


class Rivax_Promo_Box_Widget extends Widget_Base {

    public function get_name() {
        return 'rivax-promo-box';
    }

    public function get_title() {
        return esc_html__('Promo Box', 'newsfy');
    }

    public function get_icon() {
        return 'eicon-image-rollover rivax-e-icon';
    }

    protected function get_html_wrapper_class() {
        return $this->get_name() . '-widget';
    }

    public function get_categories() {
        return ['rivax-elements'];
    }

    public function get_style_depends() {
        return [ 'rivax-promo-box' ];
    }

    protected function register_controls() {

        // Content Controls
        $this->start_controls_section(
            'section_promo_content',
            [
                'label' => esc_html__('Promo Content', 'newsfy'),
            ]
        );

        $this->add_control(
            'promo_image',
            [
                'label' => esc_html__('Promo Image', 'newsfy'),
                'type' => Controls_Manager::MEDIA,
                'default' => [
                    'url' => Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Image_Size::get_type(),
            [
                'name' => 'promo_image_size',
                'default' => 'large',
            ]
        );

        $this->add_control(
            'promo_effect',
            [
                'label' => esc_html__('Promo Effect', 'newsfy'),
                'type' => Controls_Manager::SELECT,
                'default' => 'effect-lily',
                'options' => [
                    'effect-lily' => esc_html__('Lily', 'newsfy'),
                    'effect-sadie' => esc_html__('Sadie', 'newsfy'),
                    'effect-layla' => esc_html__('Layla', 'newsfy'),
                    'effect-oscar' => esc_html__('Oscar', 'newsfy'),
                    'effect-marley' => esc_html__('Marley', 'newsfy'),
                    'effect-ruby' => esc_html__('Ruby', 'newsfy'),
                    'effect-roxy' => esc_html__('Roxy', 'newsfy'),
                    'effect-bubba' => esc_html__('Bubba', 'newsfy'),
                    'effect-romeo' => esc_html__('Romeo', 'newsfy'),
                    'effect-sarah' => esc_html__('Sarah', 'newsfy'),
                    'effect-chico' => esc_html__('Chico', 'newsfy'),
                    'effect-milo' => esc_html__('Milo', 'newsfy'),
                    'effect-apollo' => esc_html__('Apolo', 'newsfy'),
                    'effect-jazz' => esc_html__('Jazz', 'newsfy'),
                    'effect-ming' => esc_html__('Ming', 'newsfy'),
                ],
            ]
        );

        $this->add_control(
            'promo_heading',
            [
                'label' => esc_html__('Promo Heading', 'newsfy'),
                'type' => Controls_Manager::TEXT,
                'label_block' => true,
                'default' => esc_html__('I AM A PROMO BOX', 'newsfy'),
                'placeholder' => esc_html__('Enter heading for the promo', 'newsfy'),
            ]
        );

        $this->add_control(
            'promo_content',
            [
                'label' => esc_html__('Promo Content', 'newsfy'),
                'type' => Controls_Manager::TEXTAREA,
                'default' => esc_html__('This is a simple content.', 'newsfy'),
            ]
        );

        $this->add_control(
            'promo_link',
            [
                'label' => esc_html__( 'Link', 'newsfy' ),
                'type' => Controls_Manager::URL,
                'placeholder' => 'https://example.com/',
            ]
        );

        $this->add_control(
            'content_align',
            [
                'label' => esc_html__( 'Alignment', 'newsfy' ),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__( 'Left', 'newsfy' ),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__( 'Center', 'newsfy' ),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__( 'Right', 'newsfy' ),
                        'icon' => 'eicon-text-align-right',
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}} .content-wrapper' => 'text-align: {{VALUE}};'
                ]
            ]
        );

        $this->end_controls_section();

        // Style Controls
        $this->start_controls_section(
            'section_style_promo',
            [
                'label' => esc_html__('Promo Box', 'newsfy'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'container_max_width',
            [
                'label' => esc_html__('Max Width', 'newsfy'),
                'type' => Controls_Manager::SLIDER,
                'default' => [
                    'size' => 480,
                    'unit' => 'px',
                ],
                'size_units' => ['px', '%'],
                'range' => [
                    'px' => [
                        'min' => 100,
                        'max' => 1000,
                        'step' => 5,
                    ],
                    '%' => [
                        'min' => 50,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-promo-box' => 'max-width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'container_height',
            [
                'label' => esc_html__('Height', 'newsfy'),
                'type' => Controls_Manager::SLIDER,
                'range' => [
                    'px' => [
                        'min' => 100,
                        'max' => 1000,
                        'step' => 5,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-promo-box' => 'height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'promo_border',
                'selector' => '{{WRAPPER}} .rivax-promo-box',
            ]
        );

        $this->add_control('promo_border_color_dark_mode',
            [
                'label' => esc_html__('Border Color - Dark Mode', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'condition' => [
                    'promo_border_border!' => '',
                ],
                'selectors' => [
                    'html[scheme="dark"] {{WRAPPER}} .rivax-promo-box' => 'border-color: {{VALUE}};',
                ],
            ]);

        $this->add_responsive_control(
            'promo_border_radius',
            [
                'label' => esc_html__('Border Radius', 'newsfy'),
                'type' => Controls_Manager::SLIDER,
                'selectors' => [
                    '{{WRAPPER}} .rivax-promo-box' => 'border-radius: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'promo_overlay',
                'label' => esc_html__('Overlay', 'newsfy'),
                'exclude' => [ 'image' ],
                'selector' => '{{WRAPPER}} .image-wrapper::before',
            ]
        );

        $this->add_control(
            'promo_overlay_opacity',
            [
                'label'     => esc_html__( 'Overlay Opacity', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 0,
                        'max' => 1,
                        'step' => 0.1,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-promo-box .image-wrapper::before' => 'opacity: {{SIZE}};',
                ],
            ]
        );

        $this->add_control(
            'promo_hover_overlay_opacity',
            [
                'label'     => esc_html__( 'Overlay Opacity On Hover', 'newsfy' ),
                'type'      => Controls_Manager::SLIDER,
                'range'     => [
                    'px' => [
                        'min' => 0,
                        'max' => 1,
                        'step' => 0.1,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .rivax-promo-box:hover .image-wrapper::before' => 'opacity: {{SIZE}};',
                ],
            ]
        );

        $this->end_controls_section();

        $this->start_controls_section(
            'section_style_content',
            [
                'label' => esc_html__('Content', 'newsfy'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control('container_padding',
            [
                'label' => esc_html__('Padding', 'newsfy'),
                'type' => Controls_Manager::DIMENSIONS,
                'selectors' => [
                    '{{WRAPPER}} .content-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]);

	    $this->add_control(
		    'title_heading',
		    [
			    'label' => esc_html__( 'Heading', 'newsfy' ),
			    'type' => Controls_Manager::HEADING,
		    ]
	    );

        $this->add_control(
            'promo_heading_color',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .promo-title' => 'color: {{VALUE}};',
                ],
            ]
        );

	    $this->add_group_control(
		    Group_Control_Background::get_type(),
		    [
			    'name' => 'promo_heading_background',
			    'label' => esc_html__('Background', 'newsfy'),
			    'exclude' => [ 'image' ],
			    'selector' => '{{WRAPPER}} .promo-title',
		    ]
	    );

	    $this->add_responsive_control(
		    'promo_heading_padding',
		    [
			    'label' => esc_html__( 'Padding', 'newsfy' ),
			    'type' => Controls_Manager::DIMENSIONS,
			    'selectors' => [
				    '{{WRAPPER}} .promo-title' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
		    ]
	    );

	    $this->add_control(
		    'promo_heading_border_radius',
		    [
			    'label'      => esc_html__( 'Border Radius', 'newsfy' ),
			    'type'       => Controls_Manager::DIMENSIONS,
			    'selectors'  => [
				    '{{WRAPPER}} .promo-title' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
			    ],
		    ]
	    );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'promo_title_typography',
                'selector' => '{{WRAPPER}} .promo-title',
            ]
        );

	    $this->add_control(
		    'title_content',
		    [
			    'label' => esc_html__( 'Content', 'newsfy' ),
			    'type' => Controls_Manager::HEADING,
			    'separator' => 'before',
		    ]
	    );

        $this->add_control(
            'promo_content_color',
            [
                'label' => esc_html__('Color', 'newsfy'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} p' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'promo_content_typography',
                'selector' => '{{WRAPPER}} p',
            ]
        );

        $this->end_controls_section();
    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();

        $widget_path_name = str_replace('rivax-', '', $this->get_name() );
        include RIVAX_THEME_DIR . '/elementor/templates/' . $widget_path_name . '/' . $widget_path_name . '.php';
    }

}