<?php
/*
 * Elementor Confin CTA Widget
 * Author & Copyright: themexshaper
*/

namespace Elementor;

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

class Confin_CTA extends Widget_Base{

	/**
	 * Retrieve the widget name.
	*/
	public function get_name(){
		return 'tmx-confin_cta';
	}

	/**
	 * Retrieve the widget title.
	*/
	public function get_title(){
		return esc_html__( 'CTA', 'confin-core' );
	}

	/**
	 * Retrieve the widget icon.
	*/
	public function get_icon() {
		return 'eicon-call-to-action';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	*/
	public function get_categories() {
		return ['themexshaper-category'];
	}

	/**
	 * Retrieve the list of scripts the Confin CTA widget depended on.
	 * Used to set scripts dependencies required to run the widget.
	*/
	/*
	public function get_script_depends() {
		return ['tmx-confin_cta'];
	}
	*/
	
	/**
	 * Register Confin CTA widget controls.
	 * Adds different input fields to allow the user to change and customize the widget settings.
	*/
	protected function register_controls(){
		
		$this->start_controls_section(
			'section_CTA',
			[
				'label' => esc_html__( 'CTA Options', 'confin-core' ),
			]
		);
		$this->add_control(
			'cta_title',
			[
				'label' => esc_html__( 'Title Text', 'confin-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Title Text', 'confin-core' ),
				'placeholder' => esc_html__( 'Type title text here', 'confin-core' ),
				'label_block' => true,
			]
		);
		$this->add_control(
			'cta_content',
			[
				'label' => esc_html__( 'Content Text', 'confin-core' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Content Text', 'confin-core' ),
				'placeholder' => esc_html__( 'Type Content text here', 'confin-core' ),
				'label_block' => true,
			]
		);
		$this->add_control(
			'cta_number',
			[
				'label' => esc_html__( 'Number Text', 'confin-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'number Text', 'confin-core' ),
				'placeholder' => esc_html__( 'Type number text here', 'confin-core' ),
				'label_block' => true,
			]
		);
		$this->add_control(
			'email_number',
			[
				'label' => esc_html__( 'Email Text', 'confin-core' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Email Text', 'confin-core' ),
				'placeholder' => esc_html__( 'Type Email text here', 'confin-core' ),
				'label_block' => true,
			]
		);
		$this->end_controls_section();// end: Section

		// Section
		$this->start_controls_section(
			'section_cta_style',
			[
				'label' => esc_html__( 'Section', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'cta_bg_color',
				'label' => esc_html__( 'Shape Background', 'confin-core' ),
				'description' => esc_html__( 'Shape Background Color', 'confin-core' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .cta-section-s2:before',
			]
		);
		$this->end_controls_section();// end: Section


		// Title
		$this->start_controls_section(
			'section_title_style',
			[
				'label' => esc_html__( 'Title', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'confin_title_typography',
				'selector' => '{{WRAPPER}} .cta-section-s2 h3',
			]
		);
		$this->add_control(
			'title_color',
			[
				'label' => esc_html__( 'Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .cta-section-s2 h3' => 'color: {{VALUE}};',
				],
			]
		);	
		
		$this->add_control(
			'title_padding',
			[
				'label' => esc_html__( 'Title Padding', 'confin-core' ),
				'type' => Controls_Manager::DIMENSIONS,				
				'size_units' => [ 'px', '%', 'em' ],
				'selectors' => [
					'{{WRAPPER}} .cta-section-s2 h3' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);
		$this->end_controls_section();// end: Section

		// Content
		$this->start_controls_section(
			'section_content_style',
			[
				'label' => esc_html__( 'Content', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'confin_content_typography',
				'selector' => '{{WRAPPER}} .cta-section-s2 p',
			]
		);
		$this->add_control(
			'content_color',
			[
				'label' => esc_html__( 'Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .cta-section-s2 p' => 'color: {{VALUE}};',
				],
			]
		);	
		$this->end_controls_section();// end: Section

		// Number Title
		$this->start_controls_section(
			'cat_number_text_section_style',
			[
				'label' => esc_html__( 'Info Title', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'cta_number_text_typography',
				'selector' => '{{WRAPPER}} .cta-section-s2 .cta-text ul li ',
			]
		);
		$this->add_control(
			'cat_number_text_color',
			[
				'label' => esc_html__( 'Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .cta-section-s2 .cta-text ul li, .cta-section-s2 .cta-text ul li i:before' => 'color: {{VALUE}};',
				],
			]
		);	
		$this->end_controls_section();// end: Section



	}

	/**
	 * Render CTA widget output on the frontend.
	 * Written in PHP and used to generate the final HTML.
	*/
	protected function render() {
		$settings = $this->get_settings_for_display();

		$cta_title = !empty( $settings['cta_title'] ) ? $settings['cta_title'] : '';
		$cta_content = !empty( $settings['cta_content'] ) ? $settings['cta_content'] : '';
		$cta_number = !empty( $settings['cta_number'] ) ? $settings['cta_number'] : '';
		$email_number = !empty( $settings['email_number'] ) ? $settings['email_number'] : '';

		// Turn output buffer on
		ob_start(); ?>
		<div class="cta-section-s2">
		    <div class="row">
		        <div class="col col-lg-8 col-lg-offset-2 col-sm-10 col-sm-offset-1">
		            <div class="cta-text">
		                <?php 
	                   if( $cta_title ) { echo '<h3>'.esc_html( $cta_title ).'</h3>'; }
	                   if( $cta_content ) { echo '<p>'.esc_html( $cta_content ).'</p>'; }
                		?>
		                <ul>
		                <?php 
		                	if( $cta_number ) { echo '<li><i class="ti-headphone"></i>'.esc_html( $cta_number ).'</li>'; } 
		                	if( $email_number ) { echo '<li><i class="ti-email"></i>'.esc_html( $email_number ).'</li>'; } 
		                ?>
		                </ul>
		            </div>
		        </div>
		    </div>
		</div>
	<?php // Return outbut buffer
		echo ob_get_clean();
		
	}
	/**
	 * Render CTA widget output in the editor.
	 * Written as a Backbone JavaScript template and used to generate the live preview.
	*/
	
	//protected function _content_template(){}
	
}
Plugin::instance()->widgets_manager->register( new Confin_CTA() );