<?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

/**
 * Brand Slider Widget
 *
 * @since 1.0.0
 */
class Brand_Slider 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-brand-slider';
	}

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

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

	protected function register_content_controls()
	{

		// 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();

		// brand section
		$this->start_controls_section(
			'wpr_brand_title_settings',
			[
				'label' => __('Section - Title', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
				'condition' => ['wpr_design_style' => ['layout-2', 'layout-4']],
			]
		);

		$this->add_control(
			'wpr_brand_slide_title',
			[
				'label' => esc_html__('Title', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'label_block'   => true,
				'default' => esc_html__('Used by World Leading Companies', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Widget Title', 'unlock-addons-for-elementor'),
				'condition' => ['wpr_design_style' => ['layout-2', 'layout-4']],
			]
		);

		$this->add_control(
			'wpr_brand_slide_number',
			[
				'label' => esc_html__('Number', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'label_block'   => true,
				'default' => esc_html__('1.2k', 'unlock-addons-for-elementor'),
				'placeholder' => esc_html__('Number', 'unlock-addons-for-elementor'),
				'condition' => ['wpr_design_style' => ['layout-2']],
			]
		);

		$this->add_responsive_control(
			'wpr_heading_align',
			[
				'label' => esc_html__('Alignment', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::CHOOSE,
				'options' => [
					'left' => [
						'title' => esc_html__(
							'Left',
							'unlock-addons-for-elementor'
						),
						'icon' => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__('Center', 'unlock-addons-for-elementor'),
						'icon' => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__(
							'Right',
							'unlock-addons-for-elementor'
						),
						'icon' => 'eicon-text-align-right',
					],
				],
				'default' => 'left',
				'toggle' => true,
				'selectors' => [
					'{{WRAPPER}} .wpr-align-box' => 'text-align: {{VALUE}};',
				],
				'condition' => ['wpr_design_style' => ['layout-20', 'layout-30']],
			]
		);

		$this->end_controls_section();

		// brand section
		$this->start_controls_section(
			'wpr_brand_gallery_settings',
			[
				'label' => __('Brand Logo', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'wpr_brand_slide_gallery',
			[
				'label' => esc_html__('Add Images', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'show_label' => false,
				'default' => [],
			]
		);

		$this->end_controls_section();


		// brand section
		$this->start_controls_section(
			'wpr_brand_gallery2_settings',
			[
				'label' => __('Brand Logo 2', 'unlock-addons-for-elementor'),
				'tab' => Controls_Manager::TAB_CONTENT,
				'condition' => ['wpr_design_style' => ['layout-5']],
			]
		);

		$this->add_control(
			'wpr_brand_slide_gallery2',
			[
				'label' => esc_html__('Add Images', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'show_label' => false,
				'default' => [],
			]
		);

		$this->end_controls_section();


		// animation
		$this->tp_creative_animation('layout-10');
	}

	protected function style_tab_content()
	{
		$this->tp_section_style_controls('wpr_brand_slide_section', 'Section - Style', '.wpr-el-section');
		$this->tp_link_controls_style('wpr_brand_title_two', 'Section Title - Style', '.wpr-el-brand-title', ['layout-2', 'layout-30']);
		$this->tp_basic_style_controls('wpr_brand_number', 'Number - Style', '.wpr-el-brand-number', ['layout-2']);

		$this->start_controls_section(
			'wpr_brand_item_style',
			[
				'label' => esc_html__('Item box', 'unlock-addons-for-elementor'),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => ['wpr_design_style' => ['layout-1',]],
			]
		);

		$this->add_control(
			'wpr_brand_item_box_bg_color',
			[
				'label' => esc_html__('Background Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .wpr-el-brand-item' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'wpr_brand_item_box_bg_hover_color',
			[
				'label' => esc_html__('Background Hover Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .wpr-el-brand-item:hover' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'wpr_brand_item_box_bg_border_color',
			[
				'label' => esc_html__('Border Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .wpr-el-brand-item' => 'border-color: {{VALUE}};',
				],
			]
		);

		$this->end_controls_section();

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

		$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-brand-img 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-brand-img 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-brand-img img' => 'object-fit: {{VALUE}};',
				],
			]
		);

		$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();
		$layout = $settings['wpr_design_style'];
		$animation = $this->tp_animation_show($settings);
?>

		<?php if ($layout === 'layout-2') : ?>

			<div class="brands-3 section wpr-el-section">
				<div class="container large-container">
					<div class="row g-3">
						<div class="col-md-3 col-xl-2">
							<div class="brands-3__info">
								<?php if (!empty($settings['wpr_brand_slide_number'])): ?>
									<h4 class="total-number wpr-el-brand-number"><?php echo $this->tp_kses($settings['wpr_brand_slide_number']); ?></h4>
								<?php endif; ?>
								<?php if (!empty($settings['wpr_brand_slide_title'])): ?>
									<p class="wpr-el-brand-title"><?php echo $this->tp_kses($settings['wpr_brand_slide_title']); ?></p>
								<?php endif; ?>
							</div>
						</div>
						<div class="col-md-9 col-xl-10">
							<div class="swiper brands-3__slider">
								<div class="swiper-wrapper linear">
									<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
										<div class="swiper-slide">
											<div class="brand wpr-el-brand-img">
												<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
											</div>
										</div>
									<?php endforeach; ?>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>

		<?php elseif ($layout === 'layout-3') : ?>

			<div class="swiper brands__slider wpr-el-section">
				<div class="swiper-wrapper linear">
					<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
						<div class="swiper-slide">
							<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
						</div>
					<?php endforeach; ?>
				</div>
			</div>

		<?php elseif ($layout === 'layout-4') : ?>

			<!--================= brands section start =================-->
			<div class="brands section wpr-el-section">
				<div class="swiper brands__slider">
					<div class="swiper-wrapper linear">
						<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
							<div class="swiper-slide">
								<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
							</div>
						<?php endforeach; ?>
					</div>
				</div>
				<?php if (!empty($settings['wpr_brand_slide_title'])): ?>
					<div class="brands__content row-margin-top">
						<span class="info wpr-el-brand-title">
							<?php echo $this->tp_kses($settings['wpr_brand_slide_title']); ?>
						</span>
					</div>
				<?php endif; ?>
			</div>
			<!--================= brands section end =================-->

		<?php elseif ($layout === 'layout-5') : ?>

			<?php if ($settings['wpr_brand_slide_gallery']) : ?>
				<div class="partner-5__item-wrapper">
					<div class="row-1">
						<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
							<div class="partner-5__item wpr-el-brand-img">
								<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
							</div>
						<?php endforeach; ?>
					</div>
					<div class="row-2">
						<?php foreach ($settings['wpr_brand_slide_gallery2'] as $image) : ?>
							<div class="partner-5__item wpr-el-brand-img">
								<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
							</div>
						<?php endforeach; ?>
					</div>
				</div>
			<?php endif; ?>

		<?php elseif ($layout === 'layout-6') : ?>

			<?php if ($settings['wpr_brand_slide_gallery']) : ?>
				<div class="brands-2__items-wrapper brands-7__items-wrapper fade-anim">
					<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
						<div class="brands-2__item brands-7__item wpr-el-brand-img">
							<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
						</div>
					<?php endforeach; ?>
				</div>
			<?php endif; ?>

		<?php else: ?>

			<?php if ($settings['wpr_brand_slide_gallery']) : ?>
				<div class="brands-2__items-wrapper">
					<?php foreach ($settings['wpr_brand_slide_gallery'] as $image) : ?>
						<div class="brands-2__item fade-anim wpr-el-brand-img">
							<?php echo wp_get_attachment_image($image['id'], 'full'); ?>
						</div>
					<?php endforeach; ?>
				</div>
			<?php endif; ?>

		<?php endif; ?>
<?php
	}
}


