<?php
/**
 * Elementor Dexen one
 *
 * @since 1.0.0
 */
class Dexen_services__o extends \Elementor\Widget_Base {
	public function get_name() {
		return 'dexen_services__o';
	}
	public function get_title() {
		return esc_html__( 'Dexen services', 'plugin-name' );
	}
	public function get_icon() {
		return 'fa fa-object-ungroup';
	}
	public function get_categories() {
		return array( 'dexencore' );
	}
	public function get_script_depends() {
		return array(
			'dexen-elementor-script',
		);
	}

	protected function _register_controls() {
		$this->start_controls_section(
			'section_header_content',
			array(
				'label' => esc_html__( 'Dexen header', 'plugin-name' ),
				'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'service_whre',
			array(
				'label'   => esc_html__( 'Service section or pages', 'dexen' ),
				'type'    => \Elementor\Controls_Manager::SELECT,
				'options' => array(
					'layout_1'     => esc_html__( 'section', 'dexen' ),
					'service-page' => esc_html__( 'services page', 'dexen' ),

				),
				'default' => esc_html__( 'layout_1', 'dexen' ),
			)
		);
		$this->add_control(
			'service_single_page',
			array(
				'label'        => __( 'service page one', 'plugin-domain' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => __( 'yes', 'your-plugin' ),
				'label_off'    => __( 'no', 'your-plugin' ),
				'return_value' => 'yes',
				'default'      => 'no',
			)
		);
		$this->add_control(
			'section_title',
			array(
				'label'   => __( 'Section title', 'plugin-name' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Section Title', 'plugin-domain' ),
			)
		);
		$this->add_control(
			'section_sub',
			array(
				'label'   => __( 'Section subtitle', 'plugin-name' ),
				'type'    => \Elementor\Controls_Manager::TEXTAREA,
				'default' => __( 'Section subTitle', 'plugin-domain' ),
			)
		);
		$this->add_control(
			'section_content',
			array(
				'label'   => __( 'Section content', 'plugin-name' ),
				'type'    => \Elementor\Controls_Manager::TEXTAREA,
				'default' => __( 'Section content', 'plugin-domain' ),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'services_list_area',
			array(
				'label' => esc_html__( 'Services list', 'plugin-name' ),
				'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'service_layout',
			array(
				'label'   => esc_html__( 'Service Layout', 'dexen' ),
				'type'    => \Elementor\Controls_Manager::SELECT,
				'options' => array(
					'layout_1' => esc_html__( 'Layout 1', 'dexen' ),
					'layout_2' => esc_html__( 'Layout 2', 'dexen' ),
					'layout_3' => esc_html__( 'Layout 3', 'dexen' ),
					'layout_4' => esc_html__( 'Layout 4', 'dexen' ),

				),
				'default' => esc_html__( 'layout_1', 'dexen' ),
			)
		);

		$this->add_control(
			'show_more_link',
			array(
				'label'        => __( 'Show More Link', 'plugin-domain' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => __( 'Show', 'your-plugin' ),
				'label_off'    => __( 'Hide', 'your-plugin' ),
				'return_value' => 'yes',
				'default'      => 'yes',
			)
		);
		$repeater = new \Elementor\Repeater();
		$repeater->add_control(
			'services_title',
			array(
				'label'   => __( 'Service title', 'plugin-name' ),
				'type'    => \Elementor\Controls_Manager::TEXT,
				'default' => __( 'Service Title', 'plugin-domain' ),
			)
		);
		$repeater->add_control(
			'services_title_link',
			array(
				'label'         => esc_html__( 'Service title link', 'plugin-domain' ),
				'type'          => \Elementor\Controls_Manager::URL,
				'show_external' => true,
				'default'       => array(
					'url'         => '',
					'is_external' => true,
					'nofollow'    => true,
				),
			)
		);
		$repeater->add_control(
			'services_content',
			array(
				'label' => __( 'service content', 'dexen' ),
				'type'  => \Elementor\Controls_Manager::TEXTAREA,

			)
		);
		$repeater->add_control(
			'services_images',
			array(
				'label'   => __( 'services image', 'plugin-domain' ),
				'type'    => \Elementor\Controls_Manager::MEDIA,
				'default' => array(
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				),
			)
		);
		$repeater->add_control(
			'price_section',
			array(
				'label'        => __( 'Show Price field', 'plugin-domain' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => __( 'Show', 'your-plugin' ),
				'label_off'    => __( 'Hide', 'your-plugin' ),
				'return_value' => 'yes',
				'default'      => 'no',
			)
		);
		$repeater->add_control(
			'services_price',
			array(
				'label'     => __( 'price text', 'dexen' ),
				'type'      => \Elementor\Controls_Manager::TEXT,
				'condition' => array(
					'price_section' => 'yes',
				),
			)
		);
		$repeater->add_control(
			'services_price_c',
			array(
				'label'     => __( 'price', 'dexen' ),
				'type'      => \Elementor\Controls_Manager::TEXT,
				'condition' => array(
					'price_section' => 'yes',
				),
			)
		);
		$this->add_control(
			'services_list',
			array(
				'label'  => __( 'Service List', 'dexen' ),
				'type'   => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			)
		);
		$this->end_controls_section();
	}
	protected function render() {
		$settings = $this->get_settings_for_display();

		$section_title   = $settings['section_title'];
		$section_sub     = $settings['section_sub'];
		$section_content = $settings['section_content'];
		$service_whre    = $settings['service_whre'];

		$service_layout      = $settings['service_layout'];
		$services_list       = $settings['services_list'];
		$show_more_link      = $settings['show_more_link'];
		$service_single_page = $settings['service_single_page'];
		$service_page__one_c = '';
		if ( $service_single_page == '' ) :
			$service_page__one_c = 'service-page__one';
		endif;
		?>
		
		<?php if ( $service_layout == 'layout_1' ) : ?>
		  <section class="service-one sec-pad-top <?php echo esc_attr( $service_whre . ' ' . $service_page__one_c ); ?>">
			  <div class="container">
					<?php if ( $section_title || $section_sub || $section_content ) : ?>
					  <div class="block-title text-center">
						<?php if ( $section_title ) : ?>
						  <p class="block-title__tag-line "><?php echo wp_kses_post( $section_title ); ?></p>
						<?php endif; ?>
						<?php if ( $section_sub ) : ?>
						  <h2 class="block-title__title"><?php echo wp_kses_post( $section_sub ); ?></h2>
						<?php endif; ?>
					  </div>
					<?php endif; ?>
				  <div class="row">
					<?php if ( $services_list ) : ?>
						<?php
						foreach ( $services_list as $service ) {
							$services_title               = $service['services_title'];
							$services_content             = $service['services_content'];
							$services_title_link          = $service['services_title_link'];
							$services_title_link_url      = $service['services_title_link']['url'];
							$services_title_link_target   = $service['services_title_link']['is_external'] ? ' target=_blank' : '';
							$services_title_link_nofollow = $service['services_title_link']['nofollow'] ? ' rel=nofollow' : '';

							$services_images_url = ( $service['services_images']['id'] != '' ) ? wp_get_attachment_url( $service['services_images']['id'], 'full' ) : $service['services_images']['url'];

							$services_images_id = $service['services_images']['id'];
							$images_alt         = get_post_meta( $services_images_id, '_wp_attachment_image_alt', true );
							?>
						<div class="col-lg-4">
						  <div class="service-one__single">
							  <div class="service-one__image">
								  <img src="<?php echo esc_url( $services_images_url ); ?>" alt="<?php echo esc_attr( $images_alt ); ?>">
							  </div>
							  <!-- /.service-one__image -->
							  <div class="service-one__text-block">
								<?php if ( $services_title ) : ?>
								  <h3 class="service-one__title">
									<?php if ( $services_title_link_url ) : ?>
									  <a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>">
										<?php echo wp_kses_post( $services_title ); ?>
									  </a>
									<?php else : ?>
										<?php echo wp_kses_post( $services_title ); ?>
									<?php endif; ?>
								  </h3>
								<?php endif; ?>
								  <!-- /.service-one__title -->
								  <p class="service-one__text">
									<?php echo wp_kses_post( $services_content ); ?>
								  </p>
								  <?php if ( ( $services_title_link_url ) && ( $show_more_link == 'yes' ) ) : ?>
									<a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>" class="service-one__link"><i class="fa fa-angle-right"></i></a>
								  <?php endif; ?>
							  </div>
							  <!-- /.service-one__text-block -->
						  </div>
						  <!-- /.service-one__single -->
					  </div>
						<?php } ?>
					<?php endif; ?>
					  
				  </div>
				  <!-- /.row -->
			  </div>
			  <!-- /.container -->
		  </section>
		<?php endif; ?>
		<?php if ( $service_layout == 'layout_2' ) : ?>
		  <section class="service-two sec-pad sec-pad-content-margin-30 thm-gray-bg <?php echo esc_attr( $service_whre . ' ' . $service_page__one_c ); ?>">
			<div class="container">
				<div class="row">
					<div class="col-lg-6">
						<?php if ( $section_title || $section_sub || $section_content ) : ?>
						  <div class="block-title mb-0">
							<?php if ( $section_title ) : ?>
							  <p class="block-title__tag-line "><?php echo wp_kses_post( $section_title ); ?></p>
							<?php endif; ?>
							<?php if ( $section_sub ) : ?>
							  <h2 class="block-title__title"><?php echo wp_kses_post( $section_sub ); ?></h2>
							<?php endif; ?>
							
						  </div>
						<?php endif; ?>
					</div>
					<!-- /.col-lg-6 -->
					<div class="col-lg-6 d-flex">
						<div class="my-auto">
						  <?php if ( $section_content ) : ?>
							<p class="service-two__title-text"><?php echo wp_kses_post( $section_content ); ?></p>
						  <?php endif; ?>
						</div>
						<!-- /.my-auto -->
					</div>
					<!-- /.col-lg-6 -->
				</div>
				<!-- /.row -->
				<?php if ( $services_list ) : ?>
				  <div class="row-5-col">
					<?php
					foreach ( $services_list as $service ) {
						$services_title               = $service['services_title'];
						$services_title_link          = $service['services_title_link'];
						$services_title_link_url      = $service['services_title_link']['url'];
						$services_title_link_target   = $service['services_title_link']['is_external'] ? ' target=_blank' : '';
						$services_title_link_nofollow = $service['services_title_link']['nofollow'] ? ' rel=nofollow' : '';

						$services_images_url = ( $service['services_images']['id'] != '' ) ? wp_get_attachment_url( $service['services_images']['id'], 'full' ) : $service['services_images']['url'];
						$services_images_id  = $service['services_images']['id'];
						$images_alt          = get_post_meta( $services_images_id, '_wp_attachment_image_alt', true );
						?>
					<div class="col-5-col">
						<div class="service-two__single hvr-float-shadow content-margin-30">
							<img src="<?php echo esc_url( $services_images_url ); ?>" alt="<?php echo esc_attr( $images_alt ); ?>">
							<?php if ( $services_title ) : ?>
							  <h3 class="service-two__title">
								<?php if ( $services_title_link_url ) : ?>
								  <a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>">
									<?php echo wp_kses_post( $services_title ); ?>
								  </a>
								<?php else : ?>
									<?php echo wp_kses_post( $services_title ); ?>
								<?php endif; ?>
							  </h3>
							<?php endif; ?>
							<!-- /.service-two__title -->
						</div>
						<!-- /.service-two__single -->
					</div>
					<?php } ?>
				 </div>
				<?php endif; ?>
				<!-- /.row-5-col -->
			</div>
			<!-- /.container -->
		</section>
		<!-- /.service-two -->      
		<?php endif; ?>
		<?php if ( $service_layout == 'layout_3' ) : ?>
		<section class="service-three sec-pad-top <?php echo esc_attr( $service_whre . ' ' . $service_page__one_c ); ?>">
			<div class="container">

				<?php if ( $section_title || $section_sub ) : ?>
				  <div class="block-title text-center">
					  <p class="block-title__tag-line"><?php echo wp_kses_post( $section_title ); ?></p>
					  <h2 class="block-title__title"><?php echo wp_kses_post( $section_sub ); ?></h2>
				  </div><!-- /.block-title -->
				<?php endif; ?>

				<div class="row">
				<?php
				foreach ( $services_list as $service ) {
					  $services_title               = $service['services_title'];
					  $services_content             = $service['services_content'];
					  $services_title_link          = $service['services_title_link'];
					  $services_title_link_url      = $service['services_title_link']['url'];
					  $services_title_link_target   = $service['services_title_link']['is_external'] ? ' target=_blank' : '';
					  $services_title_link_nofollow = $service['services_title_link']['nofollow'] ? ' rel=nofollow' : '';

					$services_images_url  = ( $service['services_images']['id'] != '' ) ? wp_get_attachment_url( $service['services_images']['id'], 'full' ) : $service['services_images']['url'];
					  $services_images_id = $service['services_images']['id'];
					  $images_alt         = get_post_meta( $services_images_id, '_wp_attachment_image_alt', true );

					  $price_section    = $service['price_section'];
					  $services_price   = $service['services_price'];
					  $services_price_c = $service['services_price_c'];
					?>
					<div class="col-lg-4">
						<div class="service-three__single content-margin-80">
							<div class="service-three__image">
							<img src="<?php echo esc_url( $services_images_url ); ?>" alt="<?php echo esc_attr( $images_alt ); ?>">
							</div><!-- /.service-three__image -->
							<div class="service-three__text-block">
								<?php if ( $price_section == 'yes' ) : ?>
								  <div class="service-three__price-block">
									  <span class="service-three__price-text"><?php echo esc_html( $services_price ); ?></span>
									  <p class="service-three__price-amount"><?php echo esc_html( $services_price_c ); ?></p>
								  </div><!-- /.service-three__price-block -->
								<?php endif; ?>
								<?php if ( $services_title ) : ?>
								  <h3 class="service-three__title">
									<?php if ( $services_title_link_url ) : ?>
									  <a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>">
										<?php echo wp_kses_post( $services_title ); ?>
									  </a>
									<?php else : ?>
										<?php echo wp_kses_post( $services_title ); ?>
									<?php endif; ?>
								  </h3>
								<?php endif; ?>
								<p class="service-three__text"><?php echo wp_kses_post( $services_content ); ?></p><!-- /.service-three__text -->
								
								<?php if ( ( $services_title_link_url ) && ( $show_more_link == 'yes' ) ) : ?>
								  <a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>" class="service-three__link"><i class="fa fa-angle-right"></i></a>
								<?php endif; ?>
							</div><!-- /.service-three__text-block -->
						</div><!-- /.service-three__single -->
					</div><!-- /.col-lg-4 -->
					<?php } ?>
				</div><!-- /.row -->
			</div><!-- /.container -->
		</section><!-- /.service-three -->
		<?php endif; ?>
		<?php if ( $service_layout == 'layout_4' ) : ?>
		  <section class="service-four sec-pad sec-pad-content-margin-60 ">
			  <div class="container">
				  <div class="row">
				  <?php
					foreach ( $services_list as $service ) {
						$services_title               = $service['services_title'];
						$services_content             = $service['services_content'];
						$services_title_link          = $service['services_title_link'];
						$services_title_link_url      = $service['services_title_link']['url'];
						$services_title_link_target   = $service['services_title_link']['is_external'] ? ' target=_blank' : '';
						$services_title_link_nofollow = $service['services_title_link']['nofollow'] ? ' rel=nofollow' : '';

						$services_images_url = ( $service['services_images']['id'] != '' ) ? wp_get_attachment_url( $service['services_images']['id'], 'full' ) : $service['services_images']['url'];
						$services_images_id  = $service['services_images']['id'];
						$images_alt          = get_post_meta( $services_images_id, '_wp_attachment_image_alt', true );

						$price_section    = $service['price_section'];
						$services_price   = $service['services_price'];
						$services_price_c = $service['services_price_c'];
						?>
					  <div class="col-lg-4 col-md-6 col-sm-12">
						  <div class="service-four__single content-margin-60">
							  <div class="service-four__icon">
								<img src="<?php echo esc_url( $services_images_url ); ?>" alt="<?php echo esc_attr( $images_alt ); ?>">
							  </div><!-- /.service-four__icon -->
							  <?php if ( $services_title ) : ?>
								  <h3 class="service-four__title">
									<?php if ( $services_title_link_url ) : ?>
									  <a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>">
										<?php echo wp_kses_post( $services_title ); ?>
									  </a>
									<?php else : ?>
										<?php echo wp_kses_post( $services_title ); ?>
									<?php endif; ?>
								  </h3>
							  <?php endif; ?>
							  <?php if ( $services_content ) : ?>
								<p class="service-four__text"><?php echo wp_kses_post( $services_content ); ?></p>
							  <?php endif; ?>
							  <?php if ( ( $services_title_link_url ) ) : ?>
								<a <?php echo esc_attr( $services_title_link_target . $services_title_link_nofollow ); ?> href="<?php echo esc_url( $services_title_link_url ); ?>" class="service-four__link">Read More</a>
							  <?php endif; ?>
						  </div><!-- /.service-four__single -->
					  </div><!-- /.col-lg-4 -->
					<?php } ?>
				  </div><!-- /.row -->
			  </div><!-- /.container -->
		  </section><!-- /.service-four -->
		<?php endif; ?>
		  
		<?php
	}
}

\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Dexen_services__o() );
