<?php

/**
 * Elementor Feature Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.0
 */
class Daltech_Feature extends \Elementor\Widget_Base
{

	/**
	 * Get widget name.
	 *
	 * Retrieve Feature widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name()
	{
		return 'daltech_feature_content';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Feature widget title.
	 *
	 * @since 1.0.0
	 * @access public 
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return esc_html__('Feature Content', 'daltech-core');
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Feature widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'eicon-code';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Feature widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories()
	{
		return ['daltech'];
	}

	public function get_script_depends()
	{
		return array('main');
	}

	// Add The Input For User
	protected function register_controls()
	{


		$this->start_controls_section(
			'feature_content',
			[
				'label'		=> esc_html__('Set Feature Content', 'daltech-core'),
				'tab'		=> \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'style',
			[
				'label' 	=> esc_html__('Style', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::SELECT,
				'default' 	=> '1',
				'options' 	=> [
					'1'  	=> esc_html__('Style One', 'daltech-core'),
					'2'  	=> esc_html__('Style Two', 'daltech-core'),
					'3'  	=> esc_html__('Style Three', 'daltech-core'),
				],
			]
		);

		$this->add_control(
			'sec_title',
			[
				'label'         => esc_html__('Section Title', 'daltech-core'),
				'type'             => \Elementor\Controls_Manager::TEXTAREA,
				'label_block'     => true,
				'placeholder'     => esc_html__('title', 'daltech-core'),
				'default'         => esc_html__('Default Title', 'daltech-core'),
				'rows' =>     '2',
				'condition'        => ['style'    =>    ['3']],
			]
		);

		$this->add_control(
			'sec_subtitle',
			[
				'label'         => esc_html__('Section Subtitle', 'daltech-core'),
				'type'             => \Elementor\Controls_Manager::TEXTAREA,
				'label_block'     => true,
				'placeholder'     => esc_html__('subtitle', 'daltech-core'),
				'default'         => esc_html__('Default SubTitle', 'daltech-core'),
				'rows' =>     '2',
				'condition'        => ['style'    =>    ['3']],
			]
		);


		$layout_one_feature_list = new \Elementor\Repeater();

		$layout_one_feature_list->add_control(
			'title',
			[
				'label' 		=> esc_html__('Title', 'daltech-core'),
				'type' 			=> \Elementor\Controls_Manager::TEXTAREA,
				'rows' => 2,
				'placeholder' => __('Title', 'daltech-core'),
				'default' => __('Default Title', 'daltech-core'),
				'label_block' => true,
			]
		);

		$layout_one_feature_list->add_control(
			'subtitle',
			[
				'label' 		=> esc_html__('Subtitle', 'daltech-core'),
				'type' 			=> \Elementor\Controls_Manager::TEXTAREA,
				'rows' => 4,
				'placeholder' => __('SubTitle', 'daltech-core'),
				'default' => __('Default SubTitle', 'daltech-core'),
				'label_block' => true,
			]
		);

		$layout_one_feature_list->add_control(
			'image',
			[
				'label' 	=> esc_html__('Icon Image', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
			]
		);

		$this->add_control(
			'layout_one_feature_list',
			[
				'label' 	=> esc_html__('Feature List', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::REPEATER,
				'fields' 	=> $layout_one_feature_list->get_controls(),
				'default' 	=> [
					[
						'list_title' => esc_html__('Add Feature', 'daltech-core'),
					],
				],
				'title_field' => '{{{ title }}}',
				'condition' => [
					'style' => ['1', '3']
				]
			]
		);

		$layout_two_feature_list = new \Elementor\Repeater();

		$layout_two_feature_list->add_control(
			'title',
			[
				'label' 		=> esc_html__('Title', 'daltech-core'),
				'type' 			=> \Elementor\Controls_Manager::TEXTAREA,
				'rows' => 2,
				'placeholder' => __('Title', 'daltech-core'),
				'default' => __('Default Title', 'daltech-core'),
				'label_block' => true,
			]
		);

		$layout_two_feature_list->add_control(
			'subtitle',
			[
				'label' 		=> esc_html__('Subtitle', 'daltech-core'),
				'type' 			=> \Elementor\Controls_Manager::TEXT,
				'rows' => 4,
				'placeholder' => __('SubTitle', 'daltech-core'),
				'default' => __('Default SubTitle', 'daltech-core'),
				'label_block' => true,
			]
		);

		$layout_two_feature_list->add_control(
			'form_icon_style',
			[
				'label'     => esc_html__('Form Icon Style', 'daltech-core'),
				'type'         => \Elementor\Controls_Manager::SELECT,
				'default'     => '1',
				'options'     => [
					'1'      => esc_html__('Flaticon', 'daltech-core'),
					'3'     => esc_html__('Icon Image', 'daltech-core'),
					'2'      => esc_html__('Custom Icon', 'daltech-core'),
				],
			]
		);

		$layout_two_feature_list->add_control(
			'flat_icon',
			[
				'label'      => esc_html__('Icon One', 'cleanu-core'),
				'type'       => \Elementor\Controls_Manager::ICON,
				'options'    => daltech_flaticons(),
				'include'    => daltech_include_flaticons(),
				'condition' => [
					'form_icon_style' => '1'
				]
			]
		);

		$layout_two_feature_list->add_control(
			'custom_icon',
			[
				'label'         => esc_html__('Custom Icon', 'daltech-core'),
				'type'             => \Elementor\Controls_Manager::TEXTAREA,
				'label_block'     => true,
				'rows'          => '2',
				'condition' => [
					'form_icon_style' => '2'
				]
			]
		);

		$layout_two_feature_list->add_control(
			'icon_image',
			[
				'label'            => esc_html__('Add Image Icon', 'daltech-core'),
				'type'             => \Elementor\Controls_Manager::MEDIA,
				'condition' => [
					'form_icon_style' => '3'
				]
			]
		);

		$layout_two_feature_list->add_control(
			'active_status',
			[
				'label' => __('Is active?', 'daltech-core'),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => __('Yes', 'ploming-addon'),
				'label_off' => __('No', 'ploming-addon'),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$this->add_control(
			'layout_two_feature_list',
			[
				'label' 	=> esc_html__('Feature List', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::REPEATER,
				'fields' 	=> $layout_two_feature_list->get_controls(),
				'default' 	=> [
					[
						'list_title' => esc_html__('Add Feature', 'daltech-core'),
					],
				],
				'title_field' => '{{{ title }}}',
				'condition' => [
					'style' => '2'
				]
			]
		);

		$this->add_control(
			'feature_shape_one',
			[
				'label' 	=> esc_html__('Background Shape One', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::MEDIA,
				'condition' => [
					'style' => ['1', '3']
				]
			]
		);

		$this->add_control(
			'feature_bg_one',
			[
				'label' 	=> esc_html__('Background One', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::MEDIA,
				'condition' => [
					'style' => ['3']
				]
			]
		);

		$this->add_control(
			'feature_bg_two',
			[
				'label' 	=> esc_html__('Background One', 'daltech-core'),
				'type' 		=> \Elementor\Controls_Manager::MEDIA,
				'condition' => [
					'style' => ['3']
				]
			]
		);

		$this->end_controls_section();

		include DALTECH_PLUGIN_WIDGET_STYLE_PATH . 'feature-style.php';
	}

	// Output For User
	protected function render()
	{
		$settings = $this->get_settings_for_display();
		if ($settings['style'] == '1') : ?>

			<!-- Start Our Features One
	============================================= -->
			<section class="feature-section fix section-padding">
				<div class="shape-image">
					<?php
					if (!empty($settings['feature_shape_one']['url'])) {
						echo daltech_img_tag(array(
							'url'	=> esc_url($settings['feature_shape_one']['url']),
						));
					}
					?>
				</div>
				<div class="container">
					<div class="row g-4">
						<?php
						$counter = 1;
						foreach ($settings['layout_one_feature_list'] as $item) :
						?>
							<div class="col-xxl-4 col-xl-6 wow fadeInUp" data-wow-delay=".3s">
								<div class="single-feature-items <?php if ($counter == '2') {
																		echo esc_attr("active", 'daltech-core');
																	} ?>">
									<div class="content">
										<span><?php echo wp_kses($item['subtitle'], 'daltech_allowed_tags'); ?></span>
										<h3>
											<?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?>
										</h3>
									</div>
									<div class="icon">
										<?php
										if (!empty($item['image']['url'])) {
											echo daltech_img_tag(array(
												'url'	=> esc_url($item['image']['url']),
											));
										}
										?>
									</div>
								</div>
							</div>
						<?php
							$counter++;
						endforeach;
						?>
					</div>
				</div>
			</section>
			<!-- End Our Features One -->

		<?php elseif ($settings['style'] == '2') : ?>

			<!-- Start Our Features Two  -->
			<section class="feature-icon-box-area">
				<div class="container">
					<div class="feature-icon-box-wrapper">
						<div class="row g-4">
							<?php
							foreach ($settings['layout_two_feature_list'] as $item) :
							?>
								<div class="col-xl-4 col-lg-6 col-md-6 wow fadeInUp" data-wow-delay=".3s">
									<div class="icon-box-items <?php echo esc_attr(('yes' == $item['active_status'] ? 'active' : '')); ?>">
										<div class="icon">
											<?php if (!empty($item['flat_icon'])) : ?>
												<i class="<?php echo esc_attr($item['flat_icon']); ?>"></i>
											<?php endif; ?>
											<?php if (!empty($item['icon_image']['url'])) : ?>
												<img src="<?php echo esc_url($item['icon_image']['url']); ?>" alt="<?php echo get_bloginfo('name'); ?>">
											<?php endif; ?>
											<?php
											if (!empty($item['custom_icon'])) : ?>
												<i class="<?php echo esc_attr($item['custom_icon']); ?>"></i>
											<?php endif; ?>
										</div>
										<div class="content">
											<h3> <?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?></h3>
											<p>
												<?php echo wp_kses($item['subtitle'], 'daltech_allowed_tags'); ?>
											</p>
										</div>
									</div>
								</div>
							<?php
							endforeach;
							?>
						</div>
					</div>
				</div>
			</section>
			<!-- Start Our Features Two  -->

		<?php elseif ($settings['style'] == '3') : ?>

			<!-- Start Our Features Three  -->
			<section class="feature-section section-padding fix pt-0">
				<div class="container">
					<div class="feature-single-wrapper">
						<div class="row">
							<div class="col-xl-6 col-lg-6">
								<div class="single-feature-content">
									<div class="section-title">
										<span class="wow fadeInLeft" data-wow-delay=".3s">
											<?php echo wp_kses_post($settings['sec_subtitle'], 'daltech_kses_allowed_html'); ?>
										</span>
										<h2 class="wow fadeInLeft" data-wow-delay=".5s">
											<?php echo wp_kses_post($settings['sec_title'], 'daltech_kses_allowed_html'); ?>
										</h2>
									</div>
									<?php
									foreach ($settings['layout_one_feature_list'] as $item) :
									?>
										<div class="feature-items mt-4 mt-md-0 wow fadeInLeft" data-wow-delay=".3s">
											<div class="icon">
												<?php
												if (!empty($item['image']['url'])) {
													echo daltech_img_tag(array(
														'url'	=> esc_url($item['image']['url']),
													));
												}
												?>
											</div>
											<div class="content">
												<h3>
													<?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?>
												</h3>
												<p>
													<?php echo wp_kses($item['subtitle'], 'daltech_allowed_tags'); ?>
												</p>
											</div>
										</div>
									<?php
									endforeach;
									?>
								</div>
							</div>
							<div class="col-xl-6 col-lg-6 mt-5 mt-lg-0">
								<div class="single-feature-image">
									<div class="quote-img float-bob-y">
										<?php
										if (!empty($settings['feature_shape_one']['url'])) {
											echo daltech_img_tag(array(
												'url'	=> esc_url($settings['feature_shape_one']['url']),
											));
										}
										?>
									</div>
									<div class="row">
										<div class="col-lg-6 col-md-6 col-sm-6">
											<div class="feature-image">
												<?php
												if (!empty($settings['feature_bg_one']['url'])) {
													echo daltech_img_tag(array(
														'url'	=> esc_url($settings['feature_bg_one']['url']),
													));
												}
												?>
											</div>
										</div>
										<div class="col-lg-6 col-md-6 col-sm-6">
											<div class="feature-image-2">
												<?php
												if (!empty($settings['feature_bg_two']['url'])) {
													echo daltech_img_tag(array(
														'url'	=> esc_url($settings['feature_bg_two']['url']),
													));
												}
												?>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!-- Start Our Features Three  -->
<?php
		endif;
	}
}
