<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}
use Elementor\Group_Control_Typography;
use Elementor\Controls_Manager;

class PLS_Elementor_Heading extends  PLS_Elementor_Widget_Base{
    /**
     * Get widget name.
     * @return string Widget name.
     */
    public function get_name() {
        return 'pls-heading';
    }

    /**
     * Get widget title.
     *
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Heading', 'modave-core' );
    }

    /**
     * Get widget icon.
     *
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'pls-icon eicon-heading';
    }
	
	/**
	 * Get widget keywords.
	 *
	 * Retrieve the list of keywords the list widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return array Widget keywords.
	 */
	public function get_keywords() {
		return [ 'heading', 'title' ];
	}
	
    /**
     * Register tabs widget controls.
     * @since 1.0.0
     * @access protected
     */
    protected function register_controls() {
		
		$this->start_controls_section(
            'section_heading',
            [
                'label' => esc_html__( 'Heading', 'modave-core' ),
            ]
        );		
		$this->add_control(
            'title',
            [
                'label' 	=> esc_html__('Title', 'modave-core'),
                'type' 		=> Controls_Manager::TEXTAREA,
				'default'	=> esc_html__('Heading Text Here', 'modave-core'),
            ]
        );
        $this->add_control(
            'title_tag',
            [
                'label' 	=> esc_html__( 'Title HTML Tag', 'modave-core' ),
                'type' 		=> Controls_Manager::SELECT,
                'options' 	=> [
                    'h1' 	=> 'H1',
                    'h2' 	=> 'H2',
                    'h3' 	=> 'H3',
                    'h4' 	=> 'H4',
                    'h5' 	=> 'H5',
                    'h6' 	=> 'H6',
                    'div' 	=> 'div',
                    'span'	=> 'span',
                    'p' 	=> 'p',
                ],
                'default' 	=> 'h2',
            ]
        );		
		$this->add_control(
            'sub_title',
            [
                'label' 	=> esc_html__('Sub Title', 'modave-core'),
                'type' 		=> Controls_Manager::TEXTAREA,
            ]

		); 
        $this->add_control(
            'tagline',
            [
                'label' 	=> esc_html__('Tagline', 'modave-core'),
                'type' 		=> Controls_Manager::TEXTAREA,
				'default' 	=> esc_html__('Heading tagline text here...', 'modave-core'),
            ]
        );		
        $this->add_responsive_control(
            'title_align',
            [
                'label' 	=> esc_html__('Alignment', 'modave-core'),
                'type' 		=> Controls_Manager::CHOOSE,
                'options' 	=> $this->alignment_options(),
                'default' 	=> 'center',
				'selectors'		=> [
					'{{WRAPPER}} .pls-heading' => 'text-align: {{VALUE}};',
				],
            ]
        );
		$this->add_responsive_control(
            'title_width',
            [
                'label' 		=> esc_html__( 'Title Width', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ 'px', '%' ],
				'range'			=> [ 
					'px' 	=> [ 'min' => 0, 'max' => 1600, 'step' => 1 ], 
					'%' 	=> [ 'min' => 1, 'max' => 100, 'step' => 1 ] 
				],
				'default' 		=> [ 'unit' => '%', 'size' => 100 ],
				'selectors'		=> [
					'{{WRAPPER}} .pls-heading' => 'max-width: {{SIZE}}{{UNIT}};width: {{SIZE}}{{UNIT}};',
				],
            ]
		);     
        $this->end_controls_section();
		
		/**
		 * Title settings.
		 */
		$this->start_controls_section(
			'title_style_section',
			[
				'label'	=> esc_html__( 'Title', 'modave-core' ),
				'tab'	=> Controls_Manager::TAB_STYLE,
			]
		);	
		$this->add_control(
			'title_color',
			[
				'label'     => esc_html__( 'Title Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .heading-title' => 'color: {{VALUE}}',
				],
			]
		);		
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'title_typography',
				'label'    => esc_html__( 'Custom typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .heading-title',
			]
		);
		$this->add_responsive_control(
			'title_margin',
			[
				'label'			=> esc_html__( 'Margin Bottom', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ 'px' ],
				'range' 		=> [
					'px' 	=> [ 'min' => -50, 'max' => 100 ],
				],
				'selectors'		=> [
					'{{WRAPPER}} .heading-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->end_controls_section();
		
		/**
		 * Subtitle settings.
		 */
		$this->start_controls_section(
			'subtitle_style_section',
			[
				'label' => esc_html__( 'Subtitle', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);		
		$this->add_control(
			'subtitle_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .heading-subtitle' => 'color: {{VALUE}}',
				],
			]
		);		
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'subtitle_typography',
				'label'    => esc_html__( 'Custom typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .heading-subtitle',
			]
		);
		$this->add_responsive_control(
			'subtitle_margin',
			[
				'label'			=> esc_html__( 'Margin Bottom', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ 'px' ],
				'range' 		=> [
					'px' 	=> [ 'min' => -50, 'max' => 100 ],
				],
				'selectors'		=> [
					'{{WRAPPER}} .heading-subtitle' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->end_controls_section();
		
		/**
		 * Tagline settings.
		 */
		$this->start_controls_section(
			'tagline_style_section',
			[
				'label' => esc_html__( 'Tagline', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);		
		$this->add_control(
			'tagline_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .heading-tagline' => 'color: {{VALUE}}',
				],
			]
		);		
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'tagline_typography',
				'label'    => esc_html__( 'Custom typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .heading-tagline',
			]
		);
		$this->add_responsive_control(
			'tagline_margin',
			[
				'label'			=> esc_html__( 'Margin Top', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ 'px' ],
				'range' 		=> [
					'px' 	=> [ 'min' => -50, 'max' => 100 ],
				],
				'selectors'		=> [
					'{{WRAPPER}} .heading-tagline' => 'margin-top: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->end_controls_section();
    }
	
	protected function render() {
		
		$settings = $this->get_settings();
		
		if( empty( $settings['title_align'] ) ){
			$settings['title_align'] = 'center';
		}
		$settings['id'] 				= pls_uniqid('pls-header-');
		$settings['class']				= 'pls-element pls-heading pls-text-'.$settings['title_align'];
		
		pls_core_get_templates( 'elements-widgets/heading', $settings );		
	}

}
$widgets_manager->register(new PLS_Elementor_Heading());