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

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

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

	/**
	 * Retrieve the widget icon.
	 *
	 * @since 1.0.0
	 *
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon()
	{
		return 'eicon-call-to-action 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'),
					'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_cta_content_settings',
			[
				'label' => esc_html__('Content', 'unlock-addons-for-elementor'),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'animation_delay',
			[
				'label' => esc_html__('Animation Delay', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('.2', 'unlock-addons-for-elementor'),
				'description' => $this->tp_get_allowed_html_desc('intermediate'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-10']
				]
			]
		);

		$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-1', 'layout-3', 'layout-4']
				]
			]
		);

		$this->add_control(
			'image_shape',
			[
				'label' => esc_html__('Choose Shape Image', '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_one',
			[
				'label' => esc_html__('Image One', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition' => [
					'wpr_design_style' => ['layout-2']
				]
			]
		);

		$this->add_control(
			'wpr_cta_subtitle',
			[
				'label' => esc_html__('Subtitle', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('ORVIO AI', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-1']
				]
			]
		);

		$this->add_control(
			'wpr_cta_title',
			[
				'label' => esc_html__('Title', 'unlock-addons-for-elementor'),
				'description' => $this->tp_get_allowed_html_desc('intermediate'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => 'Your Section Title',
				'placeholder' => esc_html__('Type Heading Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
			]
		);

		$this->add_control(
			'wpr_cta_title2',
			[
				'label' => esc_html__('Title 2', 'unlock-addons-for-elementor'),
				'description' => $this->tp_get_allowed_html_desc('intermediate'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => 'Your Section Title',
				'placeholder' => esc_html__('Type Heading Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-1']
				]
			]
		);

		$this->add_control(
			'wpr_cta_description',
			[
				'label' => esc_html__('Destination', 'unlock-addons-for-elementor'),
				'description' => $this->tp_get_allowed_html_desc('intermediate'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => 'Your Section Description',
				'placeholder' => esc_html__('Type Description Text', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'wpr_design_style' => ['layout-2', 'layout-3', 'layout-4'],
				]
			]
		);

		$this->add_control(
			'wpr_cta_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' => 'h2',
				'toggle' => false,
			],
		);

		$this->add_control(
			'wpr_btn_text',
			[
				'label' => esc_html__('Button Text', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__('Button Text', 'unlock-addons-for-elementor'),
				'title' => esc_html__('Enter button text', 'unlock-addons-for-elementor'),
				'label_block' => false,
				'condition' => [
					'wpr_design_style' => ['layout-1', 'layout-2', 'layout-4'],
				]
			]
		);

		// cta link 
		$this->tp_render_links_controls('cta_link');

		$this->end_controls_section();
	}

	protected function style_tab_content()
	{
		$this->tp_section_style_controls('cta_section', 'Section - Style', '.wpr-el-section');
		$this->tp_box_controls_style('wpr_rep_box_style', 'Box - Style', '.wpr-el-box', ['layout-10']);

		$this->tp_basic_style_controls('wpr_cta_subtitle', 'CTA SubTitle', '.wpr-el-subtitle', ['layout-1']);
		$this->tp_basic_style_controls('wpr_cta_title', 'CTA Title', '.wpr-el-title');
		$this->tp_basic_style_controls('wpr_cta_description', 'CTA Description', '.wpr-el-desc', ['layout-2', 'layout-3', 'layout-4']);

		$this->tp_link_controls_style('cta_btn1_style', 'CTA Button', '.wpr-el-btn', ['layout-1', 'layout-2', 'layout-4']);
	}

	/**
	 * 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') :

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

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

			<!--================= newsletter section start =================-->
			<section class="newsletter-2 section section-padding-top-bottom wpr-el-section" data-bg-src="<?php echo esc_url(wp_get_attachment_image_url($settings['bg_image']['id'], 'full')); ?>">
				<img src="<?php echo esc_url(wp_get_attachment_image_url($settings['image_shape']['id'], 'full')); ?>" alt="newsletter-2__shape-1" class="newsletter-2__shape-1" />
				<div class="container">
					<div class="row">
						<div class="col-12">
							<div class="section-header v2 ondark newsletter-2__content">
								<?php if (!empty($settings['wpr_cta_subtitle'])): ?>
									<span class="section-sub-title wpr-el-sub-title">
										<?php echo $this->tp_kses($settings['wpr_cta_subtitle']); ?>
									</span>
								<?php endif; ?>

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

								<?php if (!empty($settings['wpr_cta_title2'])): ?>
									<div class="section-title line-2 fade-anim">
										<?php echo $this->tp_kses($settings['wpr_cta_title2']); ?>

										<?php if (!empty($settings['wpr_btn_text'])): ?>
											<div class="contact-button">
												<a <?php echo $this->tp_implode_html_attributes($links_attrs); ?> class="contact">
													<span class="icon">
														<svg xmlns="http://www.w3.org/2000/svg" width="85" height="85" viewBox="0 0 85 85" fill="none">
															<path d="M85 85.0005H75.0626V16.964L7.02608 85.0005L0 77.9744L68.0365 9.93791L0 9.93743V0L85 0.00047338V85.0005Z" fill="white" />
														</svg>
														<svg xmlns="http://www.w3.org/2000/svg" width="85" height="85" viewBox="0 0 85 85" fill="none">
															<path d="M85 85.0005H75.0626V16.964L7.02608 85.0005L0 77.9744L68.0365 9.93791L0 9.93743V0L85 0.00047338V85.0005Z" fill="white" />
														</svg>
														<svg xmlns="http://www.w3.org/2000/svg" width="85" height="85" viewBox="0 0 85 85" fill="none">
															<path d="M85 85.0005H75.0626V16.964L7.02608 85.0005L0 77.9744L68.0365 9.93791L0 9.93743V0L85 0.00047338V85.0005Z" fill="white" />
														</svg>
													</span>
												</a>
												<span class="text wpr-el-btn">
													<?php echo $this->tp_kses($settings['wpr_btn_text']); ?>
												</span>
											</div>
										<?php endif; ?>
									</div>
								<?php endif; ?>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!--================= newsletter section end =================-->

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

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

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

		?>

			<div class="highlight__item special-offers wpr-el-section">
				<div class="item-content">
					<?php if (!empty($settings['wpr_cta_title'])): ?>
						<h5 class="item-title wpr-el-title">
							<?php echo $this->tp_kses($settings['wpr_cta_title']); ?>
						</h5>
					<?php endif; ?>

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

					<?php if (!empty($settings['wpr_btn_text'])): ?>
						<a <?php echo $this->tp_implode_html_attributes($links_attrs); ?> class="orvio-btn9 wpr-el-btn">
							<?php echo $this->tp_kses($settings['wpr_btn_text']); ?>
						</a>
					<?php endif; ?>
				</div>

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

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

			<?php if (!empty($settings['bg_image'])) : ?>
				<div class="highlight__item campaigns wpr-el-section">
					<div class="item-thumb">
						<img src="<?php echo esc_url(wp_get_attachment_image_url($settings['bg_image']['id'], 'full')); ?>" alt="campaigns-thumb" />
					</div>
					<div class="item-content">
						<?php if (!empty($settings['wpr_cta_title'])): ?>
							<h5 class="item-title wpr-el-title">
								<?php echo $this->tp_kses($settings['wpr_cta_title']); ?>
							</h5>
						<?php endif; ?>

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


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

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

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

		?>


			<div class="offer-countdown__content" data-bg-src="<?php echo esc_url(wp_get_attachment_image_url($settings['bg_image']['id'], 'full')); ?>">

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

				<div class="counter-clock" data-upcoming-date="16-08-2026">
					<div class="clock-box">
						<h2 class="days">20</h2>
						<span>Days</span>
					</div>
					<div class="clock-box">
						<h2 class="hours">10</h2>
						<span>Hours</span>
					</div>
					<div class="clock-box">
						<h2 class="minutes">49</h2>
						<span>Minutes</span>
					</div>
					<div class="clock-box">
						<h2 class="seconds">22</h2>
						<span>Seconds</span>
					</div>
				</div>

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

				<?php if (!empty($settings['wpr_btn_text'])): ?>
					<a <?php echo $this->tp_implode_html_attributes($links_attrs); ?> class="orvio-btn v4 wpr-el-btn">
						<span class="text">
							<?php echo $this->tp_kses($settings['wpr_btn_text']); ?>
						</span>
						<span class="icon"><i class="fa-solid fa-arrow-right-long"></i></span>
					</a>
				<?php endif; ?>
			</div>



		<?php elseif ($settings['wpr_design_style'] == 'layout-5') : ?>
			<div class="about-area-6">
				<div class="section-content fade-anim">
					<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;
	}
}


