<?php
namespace dexen\Widget;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Elementor\Controls_Manager;
use Elementor\Plugin;
use Elementor\Utils;
use Elementor\Widget_Base;

class CallToAction extends Widget_Base {

	public function get_name() {
		return 'dexen_call_to_action';
	}

	public function get_title() {
		return esc_html__( 'Call to Action', 'dexen-core' );
	}

	public function get_icon() {
		return 'eicon-post';
	}

	public function get_categories() {
		return array( 'dexencore' );
	}

	protected function _register_controls() {

		$this->start_controls_section(
			'section_comming_soon',
			array(
				'label' => esc_html__( 'Content', 'dexen-core' ),
			)
		);

		$this->add_control(
			'title_1',
			array(
				'label'   => esc_html__( 'Title', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => 'Book Your Seat Now',
			)
		);

		$this->add_control(
			'button_text',
			array(
				'label'   => esc_html__( 'Button Text', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => 'Learn More',
			)
		);

		$this->add_control(
			'button_text_link',
			array(
				'label'         => __( 'Action Link', 'dexen-core' ),
				'type'          => Controls_Manager::URL,
				'default'       => array(
					'url'         => '#',
					'is_external' => '',
				),
				'show_external' => true,
			)
		);

		$this->end_controls_section();
	}

	protected function render() {
		$settings = $this->get_settings();
		$url      = '';
		$target   = '';
		if ( ! empty( $settings['button_text_link'] ) ) {
			$link   = $settings['button_text_link'];
			$url    = $link['url'];
			$target = $link['is_external'] ? 'target="_blank"' : '';
		}
		?>
		<section class="cta-four  sec-pad sec-pad-content-margin-30">
			<div class="container">
				<h3 class="cta-four__title content-margin-30"><?php echo wp_kses_post( $settings['title_1'] ); ?></h3><!-- /.cta-four__title -->
				<?php if ( ! empty( $settings['button_text_link']['url'] ) ) : ?>
					<a class="content-margin-30 thm-btn cta-four__btn "
							href="<?php echo esc_url( $settings['button_text_link']['url'] ); ?>"
							<?php
								$target   = $settings['button_text_link']['is_external'] ? ' target=_blank' : '';
								$nofollow = $settings['button_text_link']['nofollow'] ? ' rel=nofollow' : '';
								echo esc_attr( $target . $nofollow );
							?>
							><?php echo wp_kses_post( $settings['button_text'] ); ?></a>
					</a>   
				<?php endif; ?>
			</div><!-- /.container -->
		</section>
		<?php
	}

	protected function content_template() {

	}

}

Plugin::instance()->widgets_manager->register_widget_type( new callToAction() );
