<?php
namespace dexen\Widget;

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

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

class Banner_Home2 extends Widget_Base {

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

	public function get_title() {
		return esc_html__( 'Banner Home 2', 'dexen-core' );
	}

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

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

	protected function _register_controls() {

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

		$this->add_control(
			'years',
			array(
				'label'   => esc_html__( 'Years', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( '20', 'dexen-core' ),
			)
		);

		$this->add_control(
			'years_text',
			array(
				'label'   => esc_html__( 'Years Text', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'years experience', 'dexen-core' ),
			)
		);

		$this->add_control(
			'image',
			array(
				'label'   => __( 'Image', 'dexen-core' ),
				'type'    => Controls_Manager::MEDIA,
				'dynamic' => array(
					'active' => true,
				),
				'default' => array(
					'url' => Utils::get_placeholder_image_src(),
				),

			)
		);

		$this->add_control(
			'image_1',
			array(
				'label'   => __( 'Image', 'dexen-core' ),
				'type'    => Controls_Manager::MEDIA,
				'dynamic' => array(
					'active' => true,
				),
				'default' => array(
					'url' => Utils::get_placeholder_image_src(),
				),

			)
		);

		$this->add_control(
			'title_1',
			array(
				'label'   => esc_html__( 'Title 1', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Welcome to Dexen', 'dexen-core' ),
			)
		);

		$this->add_control(
			'title_2',
			array(
				'label'   => esc_html__( 'Title 2', 'dexen-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => __( 'Copying and Printing <br> Service Center', 'dexen-core' ),
			)
		);

		$this->add_control(
			'content',
			array(
				'label'   => esc_html__( 'Content', 'dexen-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'row'     => '10',
				'default' => 'There are many variations of passages of available but the majority have suffered alteration in some form, by injected humou or randomised words which don\'t look even slightly believable. If you are going to use a passage of you need to be sure there isn\'t anything embarr assing hidden in the middle of text.',
			)
		);

		$this->add_control(
			'discount__title',
			array(
				'label'   => esc_html__( 'Discount Title', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( '10% Off', 'dexen-core' ),
			)
		);

		$this->add_control(
			'discount__text',
			array(
				'label'   => esc_html__( 'Discount Text', 'dexen-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => __( 'on all services for new businesses', 'dexen-core' ),
			)
		);

		$this->end_controls_section();
	}

	protected function render() {
		$settings   = $this->get_settings_for_display();
		$years      = $settings['years'];
		$years_text = $settings['years_text'];

		$image_url = ( $settings['image']['id'] != '' ) ? wp_get_attachment_url( $settings['image']['id'], 'full' ) : $settings['image']['url'];
		$image_id  = $settings['image']['id'];

		$image_url_1 = ( $settings['image_1']['id'] != '' ) ? wp_get_attachment_url( $settings['image_1']['id'], 'full' ) : $settings['image_1']['url'];
		$image_id_1  = $settings['image_1']['id'];

		$alt   = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
		$alt_1 = get_post_meta( $image_id_1, '_wp_attachment_image_alt', true );

		?>

	  <section class="about-three sec-pad sec-pad-content-margin-50 thm-gray-bg">
			<div class="container">
				<div class="row justify-content-lg-between">
					<div class="col-lg-5">
						<div class="about-three__image content-margin-50">
							<div class="about-three__year">
								<span class="about-three__year__title"><?php echo wp_kses_post( $years ); ?></span>
								<span class="about-three__year__text"><?php echo wp_kses_post( $years_text ); ?></span>
							</div><!-- /.about-three__year -->
							<img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $alt ); ?>" />
							<div class="about-three__image-two">
								<img src="<?php echo esc_url( $image_url_1 ); ?>" alt="<?php echo esc_attr( $alt_1 ); ?>" />
							</div><!-- /.about-three__image-two -->
						</div><!-- /.about-three__image -->
					</div><!-- /.col-lg-6 -->
					<div class="col-lg-6">
						<div class="about-three__content content-margin-50">
							<div class="block-title mb-0">
								<p class="block-title__tag-line"><?php echo wp_kses_post( $settings['title_1'] ); ?></p>
								<h2 class="block-title__title"><?php echo wp_kses_post( $settings['title_2'] ); ?></h2>
							</div><!-- /.block-title -->
							<p class="about-three__text"><?php echo wp_kses_post( $settings['content'] ); ?></p><!-- /.about-three__text -->
							<div class="about-three__discount">
								<div class="about-three__discount__icon">
									<i class="dexen-icon-tag"></i>
								</div><!-- /.about-three__discount__icon -->
								<div class="about-three__discount__content">
									<h3 class="about-three__discount__title"><?php echo wp_kses_post( $settings['discount__title'] ); ?></h3><!-- /.about-three__discount__title -->
									<p class="about-three__discount__text"><?php echo wp_kses_post( $settings['discount__text'] ); ?></p><!-- /.about-three__discount__text -->
								</div><!-- /.about-three__discount__content -->
							</div><!-- /.about-three__discount -->
						</div><!-- /.about-three__content -->
					</div><!-- /.col-lg-6 -->
				</div><!-- /.row -->
			</div><!-- /.container -->
		</section><!-- /.about-three -->

		<?php
	}

	protected function content_template() {

	}

}

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