<?php

namespace Unlockafe_addons\Widgets;

use Unlockafe_addons\Traits\Utils as UnlockafeUtils;
use Unlockafe_addons\Traits\Widget_helper;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use \Elementor\Utils;
use \Elementor\Control_Media;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Group_Control_Text_Shadow;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Image_Size;

if (!defined('ABSPATH'))
	exit; // Exit if accessed directly

/**
 * About Us Widget
 *
 * @since 1.0.0
 */
class About_Us extends Widget_Base
{

	use Widget_helper, UnlockafeUtils;

	/**
	 * Retrieve the widget name.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name()
	{
		return 'unlockafe-about-us';
	}

	/**
	 * Retrieve the widget title.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title()
	{
		return __('About Us', 'unlock-addons-for-elementor');
	}

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

	/**
	 * Retrieve the list of categories the widget belongs to.
	 *
	 * Used to determine where to display the widget in the editor.
	 *
	 * Note that currently Elementor supports only one category.
	 * When multiple categories passed, Elementor uses the first one.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories()
	{
		return ['unlockafe-addons'];
	}

	/**
	 * Retrieve the list of scripts the widget depended on.
	 *
	 * Used to set scripts dependencies required to run the widget.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return array Widget scripts dependencies.
	 */
	public function get_script_depends()
	{
		return [];
	}

	public function get_style_depends()
	{
		return ['unlockafe-global', 'unlockafe-about-us-style'];
	}

	/**
	 * Register the widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */

	protected function register_controls()
	{
		$this->register_controls_section();
		$this->style_tab_content();
	}

	protected function register_controls_section()
	{

		// layout Panel
		$this->start_controls_section(
			'wpr_layout',
			[
				'label' => esc_html__('Design Layout', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'wpr_design_style',
			[
				'label' => esc_html__('Select Layout', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'layout-1' => esc_html__('Layout 1', 'unlock-addons-for-elementor'),
					// 'layout-2' => esc_html__('Layout 2', 'unlock-addons-for-elementor'),
					// 'layout-3' => esc_html__('Layout 3', 'unlock-addons-for-elementor'),
					// 'layout-4' => esc_html__('Layout 4', 'unlock-addons-for-elementor'),
					// 'layout-5' => esc_html__('Layout 5', 'unlock-addons-for-elementor'),
					// 'layout-6' => esc_html__('Layout 6', 'unlock-addons-for-elementor'),
				],
				'default' => 'layout-1',
			]
		);

		$this->end_controls_section();

		/**
		 * 
		 * Start control for Style tab
		 */
		//Shape style tab start
		$this->start_controls_section(
			'wpr_image_group_settings',
			[
				'label' => esc_html__('Images', 'unlock-addons-for-elementor'),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'bg_image',
			[
				'label' => esc_html__('Choose BG Image', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition' => [
					'wpr_design_style' => ['layout-10']
				]
			]
		);

		$this->add_control(
			'image_one',
			[
				'label' => esc_html__('Choose Image one', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition'   => ['wpr_design_style'   => ['layout-1', 'layout-2', 'layout-3', 'layout-4', 'layout-5', 'layout-6']]

			]
		);
		$this->add_control(
			'image_two',
			[
				'label' => esc_html__('Choose Image two', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition'   => ['wpr_design_style'   => ['layout-1']]
			]
		);

		$this->add_control(
			'image_three',
			[
				'label' => esc_html__('Choose Image three', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition'   => ['wpr_design_style'   => ['layout-1']]
			]
		);

		$this->end_controls_section();

		// content section
		$this->start_controls_section(
			'wpr_about_content_section',
			[
				'label' => __('Content', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'wpr_about_shape_switcher',
			[
				'label' => esc_html__('Shape Switcher', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__('Yes', 'unlock-addons-for-elementor'),
				'label_off' => esc_html__('No', 'unlock-addons-for-elementor'),
				'return_value' => 'yes',
				'default' => 'no',
				'separator' => 'before',
				'condition' => [
					'wpr_design_style' => ['layout-1']
				]
			]
		);

		$this->add_control(
			'wpr_sub_title',
			[
				'label' => esc_html__('Section Sub Title', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Section Sub Title', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'wpr_title',
			[
				'label' => esc_html__('Section Title', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Section Title', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'wpr_number',
			[
				'label' => esc_html__('Number', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('$21m', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'wpr_number_desc',
			[
				'label' => esc_html__('Number Description', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Description', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-1'],
				]
			]
		);

		$this->add_control(
			'wpr_description',
			[
				'label' => esc_html__('Description ', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Description', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-1'],
				]
			]
		);

		$this->add_control(
			'wpr_privacy_text',
			[
				'label' => esc_html__('Privacy Text', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Privacy Policy', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'separator' => 'before',
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->add_control(
			'wpr_privacy_link',
			[
				'label' => esc_html__('Privacy Link', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::URL,
				'placeholder' => esc_html__('https://your-link.com', 'unlock-addons-for-elementor'),
				'show_external' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
					'nofollow' => true,
				],
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->add_control(
			'wpr_social_text',
			[
				'label' => esc_html__('Social Text', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Social Media', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'separator' => 'before',
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->add_control(
			'wpr_social_link',
			[
				'label' => esc_html__('Social Link', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::URL,
				'placeholder' => esc_html__('https://your-link.com', 'unlock-addons-for-elementor'),
				'show_external' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
					'nofollow' => true,
				],
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->end_controls_section();
	}

	protected function style_tab_content()
	{

		$this->tp_section_style_controls('section', 'Section - Style', '.wpr-el-section');
		$this->tp_basic_style_controls('wpr_about_sub_title', 'Video Sub Title', '.wpr-el-subtitle', ['layout-1']);
		$this->tp_basic_style_controls('wpr_about_title', 'Video Title', '.wpr-el-title', ['layout-1']);
		$this->tp_basic_style_controls('wpr_about_number', 'Number', '.wpr-el-number', ['layout-1']);
		$this->tp_basic_style_controls('wpr_about_number_desc', 'Number Description', '.wpr-el-number-desc', ['layout-1']);
		$this->tp_basic_style_controls('wpr_about_desc', 'Description', '.wpr-el-desc', ['layout-1']);
		$this->tp_link_controls_style('wpr_video_btn_style', 'Video Button', '.wpr-el-btn', ['layout-10']);

		$this->start_controls_section(
			'wpr_image_style_sec',
			[
				'label' => esc_html__('Image Styles', 'unlock-addons-for-elementor'),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => ['layout-10'],
			]
		);

		$this->add_control(
			'wpr_image_style_width',
			[
				'label' => esc_html__('Width', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em', 'rem', 'custom'],
				'selectors' => [
					'{{WRAPPER}} .wpr-el-image img' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->add_control(
			'wpr_image_style_height',
			[
				'label' => esc_html__('Height', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em', 'rem', 'custom'],
				'selectors' => [
					'{{WRAPPER}} .wpr-el-image img' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$this->add_control(
			'wpr_image_object_style',
			[
				'label' => esc_html__('Object Fit', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'cover',
				'options' => [
					'none' => esc_html__('None', 'unlock-addons-for-elementor'),
					'contain'  => esc_html__('Contain', 'unlock-addons-for-elementor'),
					'cover' => esc_html__('Cover', 'unlock-addons-for-elementor'),
					'fill' => esc_html__('fill', 'unlock-addons-for-elementor'),
				],
				'selectors' => [
					'{{WRAPPER}} .wpr-el-image img' => 'object-fit: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'team_hero_shape_bg',
			[
				'label' => esc_html__('Shape BG Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .team-details__card-thumb::before' => 'background: {{VALUE}}',
				],
				'condition' => [
					'wpr_design_style' => ['layout-6']
				],
				'separator' => 'before',
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Render the widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 *
	 * @access protected
	 */
	protected function render()
	{
		$settings = $this->get_settings_for_display();
?>

		<?php if ($settings['wpr_design_style'] == 'layout-1') : ?>


		<!--================= About section start =================-->
		<section id="about-section" class="about-5 section section-padding-top-bottom move-box-wrap wpr-el-section">
			<div class="container">
				<?php if (!empty($settings['wpr_about_shape_switcher'])): ?>
				<span class="shape-1"></span>
				<?php endif; ?>
				<div class="row g-4">
					<div class="col-md-6 col-lg-5">
						<div class="about-5__header section-header-5">
							<?php if (!empty($settings['wpr_sub_title'])): ?>
							<span class="section-sub-title wpr-el-subtitle">
								<?php echo $this->tp_kses($settings['wpr_sub_title']); ?>
							</span>
							<?php endif; ?>

							<div class="header-info">
								<?php if (!empty($settings['wpr_number'])): ?>
								<h2 class="price wpr-el-number">
									<?php echo $this->tp_kses($settings['wpr_number']); ?>
								</h2>
								<?php endif; ?>

								<?php if (!empty($settings['wpr_number_desc'])): ?>
								<p class="wpr-el-number-desc">
								<?php echo $this->tp_kses($settings['wpr_number_desc']); ?>
								</p>
								<?php endif; ?>
							</div>
						</div>
					</div>
					<div class="col-md-6 col-lg-7">
						<div class="about-5__content">
							<?php if (!empty($settings['image_one'])) : ?>
							<?php 
							$image_one_alt = !empty($settings['image_one']['alt']) ? esc_attr($settings['image_one']['alt']) : '';
							echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => 'image-1', 'alt' => $image_one_alt]); 
							?>
							<?php endif; ?>

							<?php if (!empty($settings['image_two'])) : ?>
							<?php 
							$image_two_alt = !empty($settings['image_two']['alt']) ? esc_attr($settings['image_two']['alt']) : '';
							echo wp_get_attachment_image($settings['image_two']['id'], 'full', '', ['class' => 'image-2', 'alt' => $image_two_alt]); 
							?>
							<?php endif; ?>

							<?php if (!empty($settings['image_three'])) : ?>
							<?php 
							$image_three_alt = !empty($settings['image_three']['alt']) ? esc_attr($settings['image_three']['alt']) : '';
							echo wp_get_attachment_image($settings['image_three']['id'], 'full', '', ['class' => 'image-3', 'alt' => $image_three_alt]); 
							?>
							<?php endif; ?>

							<?php if (!empty($settings['wpr_title'])): ?>
							<h2 class="info wpr-el-title">
								<?php echo $this->tp_kses($settings['wpr_title']); ?>
							</h2>
							<?php endif; ?>

							<?php if (!empty($settings['wpr_description'])): ?>
							<p class="wpr-el-desc">
								<?php echo $this->tp_kses($settings['wpr_description']); ?>
							</p>
							<?php endif; ?>

							<?php if (!empty($settings['wpr_privacy_text'])): ?>
							<div class="wpr-el-privacy">
								<?php 
								$privacy_link = !empty($settings['wpr_privacy_link']['url']) ? esc_url($settings['wpr_privacy_link']['url']) : '#';
								$privacy_target = !empty($settings['wpr_privacy_link']['is_external']) ? '_blank' : '_self';
								$privacy_rel = !empty($settings['wpr_privacy_link']['nofollow']) ? 'nofollow' : '';
								?>
								<a href="<?php echo $privacy_link; ?>" target="<?php echo $privacy_target; ?>" rel="<?php echo $privacy_rel; ?>">
									<?php echo $this->tp_kses($settings['wpr_privacy_text']); ?>
								</a>
							</div>
							<?php endif; ?>

							<?php if (!empty($settings['wpr_social_text'])): ?>
							<div class="wpr-el-social">
								<?php 
								$social_link = !empty($settings['wpr_social_link']['url']) ? esc_url($settings['wpr_social_link']['url']) : '#';
								$social_target = !empty($settings['wpr_social_link']['is_external']) ? '_blank' : '_self';
								$social_rel = !empty($settings['wpr_social_link']['nofollow']) ? 'nofollow' : '';
								?>
								<a href="<?php echo $social_link; ?>" target="<?php echo $social_target; ?>" rel="<?php echo $social_rel; ?>">
									<?php echo $this->tp_kses($settings['wpr_social_text']); ?>
								</a>
							</div>
							<?php endif; ?>
						</div>
					</div>
				</div>

				<?php if (!empty($settings['wpr_about_shape_switcher'])): ?>
				<span class="shape-2"></span>
				<?php endif; ?>
			</div>
		</section>
		<!--================= About section end =================-->


		<?php elseif ($settings['wpr_design_style'] == 'layout-2') : ?>

			<?php if (!empty($settings['image_one'])) : ?>
			<div class="choose-us__thumb">
				<?php 
				$image_one_alt = !empty($settings['image_one']['alt']) ? esc_attr($settings['image_one']['alt']) : '';
				echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => 'w-100', 'alt' => $image_one_alt, 'data-speed' => '0.8']); 
				?>
			</div>
			<?php endif; ?>



		<?php elseif ($settings['wpr_design_style'] == 'layout-3') : ?>

			<div class="about-thumb">
				<div class="btn-wrapper">
					<a href="<?php echo esc_url($settings['wpr_image_url']); ?>" class="circle-text btn-item">
						<?php echo wp_get_attachment_image($settings['image_two']['id'], 'full', '', ['class' => 'text']) ?>
						<?php echo wp_get_attachment_image($settings['image_three']['id'], 'full', '', ['class' => 'icon']) ?>
					</a>
				</div>

				<?php if (!empty($settings['image_one'])) : ?>
					<div class="image">
						<?php echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => '']) ?>
					</div>
				<?php endif; ?>
			</div>


		<?php elseif ($settings['wpr_design_style'] == 'layout-4') : ?>
			<div class="about-area-6">
				<div class="section-content">
					<div class="thumb thumb-1">
						<?php if (!empty($settings['image_two'])) : ?>
							<div class="shape-1">
								<?php echo wp_get_attachment_image($settings['image_two']['id'], 'full', '', ['class' => '']) ?>
							</div>
						<?php endif; ?>
						<?php if (!empty($settings['image_one'])) : ?>
							<div class="image img_anim_reveal wpr-el-image">
								<?php echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => '']) ?>
							</div>
						<?php endif; ?>
					</div>
				</div>
			</div>

		<?php elseif ($settings['wpr_design_style'] == 'layout-5') : ?>
			<div class="about-area-6">
				<div class="section-content">
					<div class="thumb thumb-3">
						<?php if (!empty($settings['image_one'])) : ?>
							<span class="brand-text wpr-el-sub-title"><?php echo $this->tp_kses($settings['wpr_image_text']); ?></span>
							<div class="image img_anim_reveal wpr-el-image">
								<?php echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => '']) ?>
							</div>
						<?php endif; ?>
					</div>
				</div>
			</div>

		<?php elseif ($settings['wpr_design_style'] == 'layout-6') : ?>
			<?php if (!empty($settings['image_one'])) : ?>
				<div class="team-details__card-thumb">
					<?php echo wp_get_attachment_image($settings['image_one']['id'], 'full', '', ['class' => '']) ?>
				</div>
			<?php endif; ?>


<?php endif;
	}
}


