<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Game_Card 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-card-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 Card', '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(
			'content_section',
			[
				'label' => __( 'Game Card', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'image',
				[
				  'label' => __( 'Image', 'pubzi-core' ),
				  'type' => Controls_Manager::MEDIA,
				  'default' => ['url' => Utils::get_placeholder_image_src(),],
				]
		);	
		
		$this->add_control(
			'subtitle',
			[
				'label'       => __( 'Sub Title', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Get specialist cargo services worldwide', 'pubzi-core'),
				'dynamic'     => [
					'active' => true,
				],
			]
		);
		
	//Title
		
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your title', 'pubzi-core' ),
				'default'     => __( 'Default Title', 'pubzi-core' ),
			]
		);	


		$this->add_control(
			'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,
			  ],
			
		   ]
		);

		$this->add_control(
		  'repeat', 
			[
				'type' => Controls_Manager::REPEATER,
				'separator' => 'before',
				'default' => 
					[
						['block_title' => esc_html__('Projects Completed', 'pubzi-core')],
					],
				'fields' => 
					[		

						[
							'name' => 'section_icons',
							'label' => esc_html__('Enter The icons', 'pubzi-core'),
							'type' => Controls_Manager::ICONS,							
						],

						[
							'name' => 'section_title',
							'label' => esc_html__('Title', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],

						[
							'name' => 'section_button_link',
							'label' => __( 'Url', 'pubzi-core' ),
							'type' => Controls_Manager::URL,
							'placeholder' => __( 'https://your-link.com', 'pubzi-core' ),
							'show_external' => true,
							'default' => [
								'url' => '',
								'is_external' => true,
								'nofollow' => true,
							],
						],
						
					],
				'title_field' => '{{block_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-team-details-wrapper m-0 p-0">
		<div class="gt-team-details-content m-0 p-0">
			<div class="gt-details-card-item-4 m-0 p-0">
				<div class="gt-details-image">
					<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
						<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>
					<?php endif;?>
					<div class="gt-content">
						<h6><?php echo $settings['subtitle'];?></h6>
						<ul class="gt-social-item">
							<?php foreach($settings['repeat'] as $item):?>	
							<li>
								<a href="<?php echo esc_url($item['section_button_link']['url']);?>">
									<i class="<?php echo str_replace("icon ", " ", esc_attr( $item['section_icons']['value']));?>"></i>
									<?php echo wp_kses($item['section_title'], $allowed_tags);?>
								</a>
							</li>
							<?php endforeach; ?>
						</ul>
						<h3>
							<a href="<?php echo esc_url($settings['button_link']['url']);?>"><?php echo $settings['title'];?></a>
						</h3>
					</div>
				</div>
			</div>
		</div>
	</div>

             
		<?php 
	}


}

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