<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Game_Feature_Box 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-feature-box-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 feature box', '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() {


		// Tab Start - 1

		$this->start_controls_section(
			'game_feature_box',
			[
				'label' => esc_html__( 'Game Feature Box', 'pubzi-core' ),
			]
		);	

		$this->add_control(
			'style',
				[
					'label' => __( 'Style', 'pubzi-core' ),
					'type' => Controls_Manager::SELECT,
					'default' => 'style1',
					'options' => [
						'style1'  => __( 'Style 01', 'pubzi-core' ),
						'style2'  => __( 'Style 02', 'pubzi-core' ),
						'style3'  => __( 'Style 03', 'pubzi-core' ),
					],
				]
		);	

		$this->add_control(
			'image',
				[
					'label' => __( 'Image', 'pubzi-core' ),
					'type' => Controls_Manager::MEDIA,
					'default' => ['url' => Utils::get_placeholder_image_src(),],
				]
		);	
		
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'pubzi-core' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your title', 'pubzi-core' ),
			]
		);

		$this->add_control(
			'bg_image',
				[
					'label' => __( 'Background Image', 'pubzi-core' ),
					'type' => Controls_Manager::MEDIA,
					'default' => ['url' => Utils::get_placeholder_image_src(),],
					'condition' => [
						'style' => 'style3',
					],
				]
		);

		$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->end_controls_section();


				// ===== Tab Start - 5: Title Settings =====

		$this->start_controls_section(
			'title_settings',
			[
				'label' => __( 'Title Setting', 'pubzi-core' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'show_title',
			[
				'label'   => esc_html__( 'Show Title', 'pubzi-core' ),
				'type'    => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => esc_html__( 'Show', 'pubzi-core' ),
						'icon'  => 'eicon-check-circle',
					],
					'none' => [
						'title' => esc_html__( 'Hide', 'pubzi-core' ),
						'icon'  => 'eicon-close-circle',
					],
				],
				'default'   => 'show',
				'selectors' => [
					'{{WRAPPER}} .game-feature-box-items h4' => 'display: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_alignment',
			[
				'label'     => esc_html__( 'Alignment', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::CHOOSE,
				'options'   => [
					'left' => [
						'title' => esc_html__( 'Left', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'pubzi-core' ),
						'icon'  => 'eicon-text-align-right',
					],
				],
				'toggle'    => true,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .game-feature-box-items h4' => 'text-align: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_margin',
			[
				'label'      => __( 'Margin', 'pubzi-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .game-feature-box-items h4' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_control(
			'title_padding',
			[
				'label'      => __( 'Padding', 'pubzi-core' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'condition'  => [ 'show_title' => 'show' ],
				'selectors'  => [
					'{{WRAPPER}} .game-feature-box-items h4' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name'      => 'title_typography',
				'label'     => __( 'Typography', 'pubzi-core' ),
				'selector'  => '{{WRAPPER}} .game-feature-box-items h4',
				'condition' => [ 'show_title' => 'show' ],
			]
		);

		$this->add_control(
			'title_color',
			[
				'label'     => __( 'Color', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .game-feature-box-items h4' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->add_control(
			'title_hover_color',
			[
				'label'     => __( 'Hover Color', 'pubzi-core' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'condition' => [ 'show_title' => 'show' ],
				'selectors' => [
					'{{WRAPPER}} .game-feature-box-items h4:hover' => 'color: {{VALUE}} !important',
				],
			]
		);

		$this->end_controls_section();

		// ===== End Tab - 5: Title Settings =====


	
		}

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

		<?php  if ( 'style1' === $settings['style'] ) : ?>		

			<div class="game-feature-box-items px-exclusive-item mt-0">
				<div class="shape-1">
					<svg xmlns="http://www.w3.org/2000/svg" width="30" height="27" viewBox="0 0 30 27" fill="none">
						<path d="M1 27V6C1 3.23858 3.23858 1 6 1H30" stroke="white" stroke-opacity="0.2"/>
					</svg>
				</div>
				<div class="shape-2">
					<svg xmlns="http://www.w3.org/2000/svg" width="30" height="27" viewBox="0 0 30 27" fill="none">
						<path d="M29 -9.53674e-07L29 21C29 23.7614 26.7614 26 24 26L-5.96046e-08 26" stroke="white" stroke-opacity="0.2"/>
					</svg>
				</div>
				<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
				<div class="icon">                                    	
					<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>							
				</div>
				<?php endif;?>
				<a href="<?php echo esc_url($settings['button_link']['url']);?>">
				<h4>
					<?php echo $settings['title'];?>
				</h4>
				</a>
			</div>

		<?php  elseif ( 'style2' === $settings['style'] ) : ?>
		
		<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
		<div class="game-feature-box-2 px-exclusive-item mt-0">                                    	
			<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>							
		</div>
		<?php endif;?>

		<?php  elseif ( 'style3' === $settings['style'] ) : ?>
		
		<div class="superhero-feature-box bg-cover px-exclusive-item mt-0" style="background-image: url('<?php echo wp_get_attachment_url($settings['bg_image']['id']);?>');">
			<?php  if ( !empty(esc_url($settings['image']['id']) )) : ?>   
			<div class="thumb">                                    	
				<img src="<?php echo wp_get_attachment_url($settings['image']['id']);?>" alt=""/>							
			</div>
			<?php endif;?>
		</div>

		<?php endif ;?>	

             
		<?php 
	}


}

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