<?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 About_Us2 extends Widget_Base {

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

	public function get_title() {
		return esc_html__( 'About Us 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(
			'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 1', 'dexen-core' ),
				'type'    => Controls_Manager::MEDIA,
				'dynamic' => array(
					'active' => true,
				),
				'default' => array(
					'url' => Utils::get_placeholder_image_src(),
				),

			)
		);

		$this->add_control(
			'image_2',
			array(
				'label'   => __( 'Image 1', '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', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => __( 'You’ll Get a Perfect <br> Design For your <br> Business', 'dexen-core' ),
			)
		);

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

		$this->end_controls_section();
	}

	protected function render() {
		$settings = $this->get_settings_for_display();

		$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'];

		$image_url_2 = ( $settings['image_2']['id'] != '' ) ? wp_get_attachment_url( $settings['image_2']['id'], 'full' ) : $settings['image_2']['url'];
		$image_id_2  = $settings['image_2']['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 );
		$alt_2 = get_post_meta( $image_id_2, '_wp_attachment_image_alt', true );
		?>
		 <section class="sec-pad-top about-two">
			<div class="container">
				<div class="row">
					<div class="col-xl-3 col-lg-6 col-sm-6 content-margin-30">
						<img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $alt ); ?>" />
					</div><!-- /.col-lg-3 -->
					<div class="col-xl-3 col-lg-6 col-sm-6 content-margin-30">
						<img src="<?php echo esc_url( $image_url_1 ); ?>" alt="<?php echo esc_attr( $alt_1 ); ?>" />
					</div><!-- /.col-lg-3 -->
					<div class="col-lg-6 content-margin-30">
						<img src="<?php echo esc_url( $image_url_2 ); ?>" alt="<?php echo esc_attr( $alt_2 ); ?>" />
					</div><!-- /.col-lg-6 -->
				</div><!-- /.row -->
				<div class="block-title ">
					<h2 class="block-title__title"><?php echo wp_kses_post( $settings['title_1'] ); ?></h2>
					<h2 class="block-title__text"><?php echo wp_kses_post( $settings['content'] ); ?></h2>
				</div><!-- /.block-title -->
			</div><!-- /.container -->
		</section>
		<?php
	}

	protected function content_template() {

	}

}

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