<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Game_Sidebar extends Widget_Base {

	/**
	 * Get widget name.
	 * Retrieve button widget name.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'pubzi-game-sidebar-widget';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Game Sidebar', 'pubzi-core' );
	}

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

	/**
	 * Get widget categories.
	 * Retrieve the list of categories the button widget belongs to.
	 * Used to determine where to display the widget in the editor.
	 *
	 * @since  2.0.0
	 * @access public
	 * @return array Widget categories.
	 */
	public function get_categories()
    {
        return ['pubzi_widgets'];
    }
	
	/**
	 * Register button 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->start_controls_section(
			'game_sidebar_content',
			[
				'label' => __( 'Game Sidebar Content', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'bg_image',
			[
				'label' => esc_html__('Background image', 'pubzi-core'),
				'type' => Controls_Manager::MEDIA,
				'default' => ['url' => Utils::get_placeholder_image_src(),],
			]
		);


		$this->end_controls_section();	


		$this->start_controls_section(
			'content_section',
			[
				'label' => __( 'Block', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);
		$this->add_control(
		  'repeat', 
			[
				'type' => Controls_Manager::REPEATER,
				'separator' => 'before',
				'default' => 
					[
						['section_title' => esc_html__('Projects Completed', 'pubzi-core')],
					],
				'fields' => 
					[		
						
						[
							'name' => 'section_bg_image',
							'label' => __( 'Image', 'pubzi-core' ),
							'type' => Controls_Manager::MEDIA,
							'default' => [
								'url' => Utils::get_placeholder_image_src(),
							],
						],

						[
							'name' => 'section_button_link',
							'label' => __( 'Button Url', 'pubzi-core' ),
							'type' => Controls_Manager::URL,
							'placeholder' => __( 'https://your-link.com', 'pubzi-core' ),
							'show_external' => true,
							'default' => [
								'url' => '',
								'is_external' => true,
								'nofollow' => true,
							],
						],	

						[
							'name' => 'section_title',
							'label' => esc_html__('Title', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],
						
					],
				'title_field' => '{{section_title}}',
			 ]
	);
		
		
	$this->end_controls_section();	

	
		}

	/**
	 * Render button 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();
		$allowed_tags = wp_kses_allowed_html('post');
		?> 

	


	<div class="gt-game-detaills-wrapper m-0 p-0">
		 <div class="gt-main-sideber">
			<div class="gt-single-sideber-widget">
				<h4>trending games</h4>

				<?php foreach($settings['repeat'] as $item):?>	
				<div class="gt-sideber-box bg-cover" style="background-image: url(<?php echo wp_get_attachment_url($item['section_bg_image']['id']);?>);">
					<div class="gt-box-item">
						<a href="<?php echo esc_url($item['section_button_link']['url']);?>">
						<h6>
							<?php echo wp_kses($item['section_title'], $allowed_tags);?>
						</h6>
						</a>
						<div class="icon">
							<i class="fa-solid fa-angles-right"></i>
						</div>
					</div>
				</div>
				<?php endforeach; ?>

			</div>
			<div class="gt-contact-bg bg-cover" style="background-image: url(<?php echo wp_get_attachment_url($settings['bg_image']['id']);?>);">
				<div class="gt-contact-content">
					<h3>Need Any Help</h3>
					<p>Nees Any Help, Call Us  24/7 Full Support</p>
					<div class="gt-contact-item">
						<div class="gt-icon">
							<i class="fa-solid fa-phone"></i>
						</div>
						<ul class="gt-list">
							<li><span>Call Us:</span></li>
							<li><a href="tel:+0094382229540">+009 438 222 9540</a></li>
						</ul>
					</div>
					<div class="gt-contact-item">
						<div class="gt-icon">
							<i class="fa-regular fa-envelope"></i>
						</div>
						<ul class="gt-list">
							<li><span>Mail Us</span></li>
							<li><a href="infor@gamil.com">
								infor@gamil.com
							</a></li>
						</ul>
					</div>
					<div class="gt-contact-item mb-0">
						<div class="gt-icon">
							<i class="fa-solid fa-location-dot"></i>
						</div>
						<ul class="gt-list">
							<li><span>Location:</span></li>
							<li>Toronto, Montreal, City</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		</div>

             
		<?php 
	}


}

Plugin::instance()->widgets_manager->register_widget_type(new Game_Sidebar());