<?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_Image_Size;
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\Repeater;

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

/**
 * Banner Widget
 *
 * @since 1.0.0
 */
class Banner 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-banner';
	}

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

	/**
	 * Retrieve the widget icon.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'eicon-banner 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'];
	}

	/**
	 * 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'),
				],
				'default' => 'layout-1',
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'banner_section',
			[
				'label' => esc_html__('Banner Controls', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'banner_subtitle',
			[
				'label' => esc_html__('Subtitle', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__('Digital', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Your Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'banner_title',
			[
				'label' => esc_html__('Title', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__('productivity', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Your Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'banner_description',
			[
				'label' => esc_html__('Description', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'default' => esc_html__('Description', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Your Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'banner_years',
			[
				'label' => esc_html__('Years Active', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__('We\'re since 2002', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Your Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'video_url',
			[
				'label' => esc_html__('Video URL', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => 'https://themeforest.wprealizer.com/unikon/assets/unikon_agency_video1.mp4',
				'label_block' => true,
				'description' => __("We recommended to put 'mp4' format video.", 'unlock-addons-for-elementor')
			]
		);

		$this->add_control(
			'banner_title_tag',
			[
				'label' => esc_html__('Title HTML Tag', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::CHOOSE,
				'options' => [
					'h1' => [
						'title' => esc_html__('H1', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h1'
					],
					'h2' => [
						'title' => esc_html__('H2', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h2'
					],
					'h3' => [
						'title' => esc_html__('H3', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h3'
					],
					'h4' => [
						'title' => esc_html__('H4', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h4'
					],
					'h5' => [
						'title' => esc_html__('H5', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h5'
					],
					'h6' => [
						'title' => esc_html__('H6', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-editor-h6'
					]
				],
				'default' => 'h4',
				'toggle' => false,
			]
		);

		$this->add_control(
			'banner_image',
			[
				'label' => esc_html__('Thumbnail', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
			]
		);

		$this->add_control(
			'banner_link_text',
			[
				'label' => esc_html__('Button Text', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Explore Service', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Your Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->tp_render_links_controls('banner_link');

		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			[
				'name' => 'tp_image_size',
				'default' => 'full',
				'exclude' => [
					'custom'
				]
			]
		);

		$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('b_heading_subtitle', 'Section - Subtitle', '.wpr-el-subtitle');
		$this->tp_basic_style_controls('b_heading_title', 'Section - Title', '.wpr-el-title');
		$this->tp_basic_style_controls('b_heading_desc', 'Section - Description', '.wpr-el-desc');
		$this->tp_link_controls_style('b_btn1_style', 'Button', '.wpr-el-btn');

		$this->start_controls_section(
			'banner_style_section',
			[
				'label' => esc_html__('Image Style', 'unlock-addons-for-elementor'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_responsive_control(
			'banner_border-radius',
			[
				'label' => esc_html__('Border Radius', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} .wpr_el_item_image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->add_responsive_control(
			'banner_width',
			[
				'label' => esc_html__('Width', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => ['px', '%'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .wpr_el_item_image' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$this->add_responsive_control(
			'banner_height',
			[
				'label' => esc_html__('Height', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => ['px', '%'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .wpr_el_item_image' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$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-2'): ?>

		<?php else:

			$img = $this->tp_get_img($settings, 'banner_image', 'tp_image_size');

			$attrs = $this->tp_get_repeater_links_attr($settings, 'banner_link');
			extract($attrs);

			$links_attrs = [
				'href' => $link,
				'target' => $target,
				'rel' => $rel,
			];

			$this->add_render_attribute('title_args', 'class', 'featured-shop-banner-title wpr-el-title');
		?>

			<!-- Hero start -->
			<div class="hero-digital wpr-el-section">
				<span class="hero-digital__circle-shape"></span>
				<div class="container container-fitness pb-150">
					<div class="row">
						<div class="col-12">
							<div class="hero-digital__header">
								<?php if (!empty($settings['banner_title'])): ?>
								<h1 class="h1 hero-digital__title">
								<span class="word word-animation wpr-el-subtitle"><?php echo $this->tp_kses($settings['banner_subtitle']); ?></span>
								<br />
								<span class="word word-animation wpr-el-title"><?php echo $this->tp_kses($settings['banner_title']); ?></span>
								</h1>
								<?php endif; ?>

								<?php if (!empty($settings['banner_link_text'])): ?>
								<a <?php echo $this->tp_implode_html_attributes($links_attrs) ?> class="hero-digital__btn-wrapper btn-hover btn-item d-none d-lg-block fade_up_anim wpr-el-btn" data-delay=".2">
									<span></span>
									<p class="hero-digital__btn-text">
									<?php echo $this->tp_kses($settings['banner_link_text']); ?>
									</p>
								</a>
								<?php endif; ?>
							</div>
						</div>
					</div>
					<div class="row g-4 hero-digital__content-container">
						<div
							class="col-sm-12 col-md-4 col-xl-5 d-none d-md-inline-block"
							>
							<a
								href="#about-digital"
								class="hero-digital__section-jump section-link"
								>
								<img src="<?php echo esc_url($img['banner_image']); ?>" alt="<?php echo esc_attr($img['banner_image_alt']); ?>" class="wpr_el_item_image">
							</a>
						</div>
						<div class="col-sm-12 col-md-8 col-xl-7">
							<div class="hero-digital__content">
								<?php if (!empty($settings['banner_years'])): ?>
								<span
									class="hero-digital__content-stablish-info fade_up_anim"
									data-delay=".4"
									>
									<?php echo $this->tp_kses($settings['banner_years']); ?>
								</span>
								<?php endif; ?>

								<?php if (!empty($settings['banner_description'])): ?>
								<p
									class="hero-digital__content-info fade_up_anim wpr-el-desc"
									data-delay=".8"
									>
									<?php echo $this->tp_kses($settings['banner_description']); ?>
								</p>
								<?php endif; ?>
							</div>
						</div>
						<?php if (!empty($settings['banner_link_text'])): ?>
						<div class="col-12 btn-item d-lg-none">
							<a
								<?php echo $this->tp_implode_html_attributes($links_attrs) ?>
								class="hero-digital__btn-wrapper btn-hover fade_up_anim wpr-el-btn"
								data-delay=".2"
								>
								<span></span>
								<p class="hero-digital__btn-text">
									<?php echo $this->tp_kses($settings['banner_link_text']); ?>
								</p>
							</a>
						</div>
						<?php endif; ?>
					</div>
				</div>
			</div>
			<!-- Hero End -->


<?php endif;
	}
}


