<?php
namespace Elementor;
class ThemeDraft_Text_With_Title_Widget extends Widget_Base{

    public function get_name(){

        return 'themedraft_text_with_title';
    }

    public function get_title(){
        return esc_html__('Title With Text','themedraft-core');
    }

    public function get_icon() {

        return 'eicon-text';
    }

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


    protected function register_controls(){

        //Content tab start
        $this->start_controls_section(
            'text_and_title_settings',
            [
                'label' => esc_html__( 'Title And Text', 'themedraft-core' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'title',
            [
                'label'       => __( 'Title', 'themedraft-core' ),
                'type'        => Controls_Manager::WYSIWYG,
                'default'     => __( '<h2>We offer best industrial services. 35+ years of experience with global industries.</h2>', 'themedraft-core' ),
                'description' => __( 'Use headings (h1 - h6 ) for title', 'themedraft-core' ),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'desc_text',
            [
                'label' => esc_html__( 'Text', 'themedraft-core' ),
                'type' => Controls_Manager::WYSIWYG,
                'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themedraft-core' ),
                'placeholder' => esc_html__( 'Type your text here', 'themedraft-core' ),
            ]
        );


        $this->add_responsive_control(
            'text_align',
            [
                'label'       => esc_html__('Text Align', 'themedraft-core'),
                'description' => esc_html__('', 'themedraft-core'),
                'type'        => Controls_Manager::CHOOSE,
                'label_block' => false,

                'options' => [
                    'left' => [
                        'title' => __('Left', 'themedraft-core'),
                        'icon'  => 'fa fa-align-left',
                    ],

                    'center' => [
                        'title' => __('Center', 'themedraft-core'),
                        'icon'  => 'fa fa-align-center',
                    ],

                    'right' => [
                        'title' => __('Right', 'themedraft-core'),
                        'icon'  => 'fa fa-align-right',
                    ],
                ],

                'devices' => ['desktop', 'tablet', 'mobile'],

                'selectors' => [
                    '{{WRAPPER}} .td-text-with-title-wrapper' => 'text-align: {{VALUE}};',
                ],

            ]
        );
        $this->end_controls_section();


        //Style tab start
        $this->start_controls_section(
            'title_style_section',
            [
                'label' => esc_html__( 'Title Style', 'themedraft-core' ),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
	                'title!' => '',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'heading_typography',
                'label' => __( 'Typography', 'themedraft-core' ),
                'selector' => '{{WRAPPER}} .td-text-with-title-wrapper .title h1,{{WRAPPER}} .td-text-with-title-wrapper .title h2,{{WRAPPER}} .td-text-with-title-wrapper .title h3,{{WRAPPER}} .td-text-with-title-wrapper .title h4,{{WRAPPER}} .td-text-with-title-wrapper .title h5,{{WRAPPER}} .td-text-with-title-wrapper .title h6',
            ]
        );
        
        
        $this->add_control(
            'title_color',
            [
                'label'       => esc_html__('Color', 'themedraft-core'),
                'type'        => Controls_Manager::COLOR,
                'selectors'   => [
                    '{{WRAPPER}} .td-text-with-title-wrapper .title h1,{{WRAPPER}} .td-text-with-title-wrapper .title h2,{{WRAPPER}} .td-text-with-title-wrapper .title h3,{{WRAPPER}} .td-text-with-title-wrapper .title h4,{{WRAPPER}} .td-text-with-title-wrapper .title h5,{{WRAPPER}} .td-text-with-title-wrapper .title h6' => 'color: {{VALUE}};',
                ],
            ]
        );
        
        $this->add_responsive_control(
            'title_margin',
            [
                'label'      => esc_html__('Margin', 'themedraft-core'),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'selectors'  => [
                    '{{WRAPPER}} {{WRAPPER}} .td-text-with-title-wrapper .title h1,{{WRAPPER}} .td-text-with-title-wrapper .title h2,{{WRAPPER}} .td-text-with-title-wrapper .title h3,{{WRAPPER}} .td-text-with-title-wrapper .title h4,{{WRAPPER}} .td-text-with-title-wrapper .title h5,{{WRAPPER}} .td-text-with-title-wrapper .title h6' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

	    $this->add_control(
		    'title_animation',
		    [
			    'label' => __( 'Entrance Animation', 'themedraft-core' ),
			    'type' => Controls_Manager::ANIMATION,
			    'prefix_class' => 'animated ',
		    ]
	    );

	    $this->add_control(
		    'title_animation_duration',
		    [
			    'label'     => __( 'Animation Duration', 'themedraft-core' ),
			    'type'      => Controls_Manager::SELECT,
			    'default'   => 'data-wow-duration="1.25s"',
			    'options'   => [
				    'data-wow-duration="2s"'    => __( 'Slow', 'themedraft-core' ),
				    'data-wow-duration="1.25s"' => __( 'Normal', 'themedraft-core' ),
				    'data-wow-duration=".75s"'  => __( 'Fast', 'themedraft-core' ),
			    ],
			    'condition' => [
				    'title_animation!' => '',
			    ]
		    ]
	    );

        $this->end_controls_section();

        $this->start_controls_section(
            'text_style_section',
            [
                'label' => esc_html__( 'Text Style', 'themedraft-core' ),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'desc_text!' => '',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'text_typography',
                'label' => __( 'Typography', 'themedraft-core' ),
                'selector' => '{{WRAPPER}} .td-text-with-title-wrapper .description-text',
            ]
        );


        $this->add_control(
            'text_color',
            [
                'label'       => esc_html__('Color', 'themedraft-core'),
                'type'        => Controls_Manager::COLOR,
                'selectors'   => [
                    '{{WRAPPER}} .td-text-with-title-wrapper .description-text' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'text_margin',
            [
                'label'      => esc_html__('Margin', 'themedraft-core'),
                'type'       => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%', 'em'],
                'selectors'  => [
                    '{{WRAPPER}} .td-text-with-title-wrapper .description-text' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );


	    $this->add_control(
		    'desc_animation',
		    [
			    'label' => __( 'Entrance Animation', 'themedraft-core' ),
			    'type' => Controls_Manager::ANIMATION,
			    'prefix_class' => 'animated ',
		    ]
	    );

	    $this->add_control(
		    'desc_animation_duration',
		    [
			    'label'     => __( 'Animation Duration', 'themedraft-core' ),
			    'type'      => Controls_Manager::SELECT,
			    'default'   => 'data-wow-duration="1.25s"',
			    'options'   => [
				    'data-wow-duration="2s"'    => __( 'Slow', 'themedraft-core' ),
				    'data-wow-duration="1.25s"' => __( 'Normal', 'themedraft-core' ),
				    'data-wow-duration=".75s"'  => __( 'Fast', 'themedraft-core' ),
			    ],
			    'condition' => [
				    'desc_animation!' => '',
			    ]
		    ]
	    );
        $this->end_controls_section();


    }

    //Render
    protected function render() {
        $settings = $this->get_settings_for_display();
	    if($settings['title_animation']){
		    $title_animation = 'wow'.' ' . $settings['title_animation'];
		    $title_animation_duration = $settings['title_animation_duration'];
	    }else{
		    $title_animation ='';
		    $title_animation_duration ='';
	    }

	    if($settings['desc_animation']){
		    $desc_animation = 'wow'.' ' . $settings['desc_animation'];
		    $desc_animation_duration = $settings['desc_animation_duration'];
	    }else{
		    $desc_animation ='';
		    $desc_animation_duration ='';
	    }
        ?>
        <div class="td-text-with-title-wrapper">
            <?php if($settings['title']) : ?>

            <div class="title <?php echo $title_animation;?>" <?php echo $title_animation_duration;?>>
	            <?php echo $settings['title'];?>
            </div>
            <?php endif; ?>

	        <?php if($settings['desc_text']) : ?>
            <div class="description-text <?php echo $desc_animation;?>" <?php echo $desc_animation_duration;?>>
                <?php echo $settings['desc_text'];?>
            </div>
            <?php endif; ?>
        </div>


        <?php

    }
}
Plugin::instance()->widgets_manager->register( new ThemeDraft_Text_With_Title_Widget );