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

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

	public function get_title() {
		return esc_html__( 'Contact Two', '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(
			'title_1',
			array(
				'label'   => esc_html__( 'Title 1', 'dexen-core' ),
				'type'    => Controls_Manager::TEXT,
				'default' => esc_html__( 'Contact Us', 'dexen-core' ),
			)
		);

		$this->add_control(
			'title_2',
			array(
				'label'   => esc_html__( 'Title 2', 'dexen-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Send a Message',
			)
		);

		$this->add_control(
			'content',
			array(
				'label'   => esc_html__( 'Content', 'dexen-core' ),
				'type'    => Controls_Manager::TEXTAREA,
				'default' => '',
			)
		);

		$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'];
		$alt       = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
		?>

		<section class="contact-two thm-gray-bg">
			<div class="container">
				<div class="row no-gutters">
					<div class="col-lg-6 d-flex">
						<div class="my-auto">
							<div class="block-title">
								<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 -->
								<?php
								echo do_shortcode( $settings['content'] );
								?>
						</div><!-- /.my-auto -->
					</div><!-- /.col-lg-6 -->
					<div class="col-lg-6">
						<div class="contact-two__image-block">
							<img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $alt ); ?>" />
						</div><!-- /.contact-two__image-block -->
					</div><!-- /.col-lg-6 -->
				</div><!-- /.row -->
			</div><!-- /.container -->
		</section>
		<?php
	}

	protected function content_template() {

	}

}

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