<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Feature_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-feature-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__( 'Feature 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(
			'feature_card_content',
			[
				'label' => __( 'Feature Content', 'pubzi-core' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'style',
			[
				'label'   => esc_html__( 'Select Style', 'pubzi-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'style1',
				'options' => array(
					'style1'   => esc_html__( 'Style One', 'pubzi-core' ),
					'style2'   => esc_html__( 'Style Two', 'pubzi-core' ),
					'style3'   => esc_html__( 'Style Three', 'pubzi-core' ),
				),
			]
		);


		$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_image',
							'label' => __( 'Image', 'pubzi-core' ),
							'type' => Controls_Manager::MEDIA,
							'default' => [
								'url' => Utils::get_placeholder_image_src(),
							],
						],

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

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

						[
							'name' => 'section_class',
							'label' => esc_html__('Class', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('bg-color border-none', 'pubzi-core')
						],

						[
							'name' => 'section_image_2',
							'label' => __( 'Image 2', 'pubzi-core' ),
							'type' => Controls_Manager::MEDIA,
							'default' => [
								'url' => Utils::get_placeholder_image_src(),
							],
						],

						[
							'name' => 'section_subtitle_2',
							'label' => esc_html__('Subtitle 2', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('', 'pubzi-core')
						],	

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

						[
							'name' => 'section_class_2',
							'label' => esc_html__('Class 2', 'pubzi-core'),
							'type' => Controls_Manager::TEXTAREA,
							'default' => esc_html__('bg-color border-none', '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');
		?>

<?php  if ( 'style1' === $settings['style'] ) : ?>
	   <div class="gt-top-feature-wrapper m-0 p-0">
                    
			<div class="gt-top-feature-content">
				<ul class="gt-feature-icon">
					<?php foreach($settings['repeat'] as $item):?>	
					<li>
						<div class="gt-icon">
						<?php if(!empty(wp_get_attachment_url($item['section_image']['id']))): ?>
							<img src="<?php echo wp_get_attachment_url($item['section_image']['id']);?>" alt="">
						<?php endif;?>
						</div>
						<div class="gt-content">
							<h3><?php echo wp_kses($item['section_title'], $allowed_tags);?></h3>
							<p>
								<?php echo wp_kses($item['section_subtitle'], $allowed_tags);?>
							</p>
						</div>
					</li>
					<?php endforeach; ?>
				</ul>
			</div>

		</div>

<?php  elseif ( 'style2' === $settings['style'] ) : ?>

		<div class="about-wrapper-7 m-0 p-0">
			<div class="about-content m-0 p-0">
				<div class="about-box-wrapper m-0 p-0 wow fadeInUp" data-wow-delay=".3s">
					<?php foreach($settings['repeat'] as $item):?>	
					<div class="about-box-item">
						<div class="about-box <?php echo esc_attr($item['section_class_2']);?>">
							<div class="icon">
							<?php if(!empty(wp_get_attachment_url($item['section_image']['id']))): ?>
								<img src="<?php echo wp_get_attachment_url($item['section_image']['id']);?>" alt="">
							<?php endif;?>
							</div>
							<div class="content">
								<h5><?php echo wp_kses($item['section_title'], $allowed_tags);?></h5>
								<p>
									<?php echo wp_kses($item['section_subtitle'], $allowed_tags);?>
								</p>
							</div>
						</div>
						<div class="about-box <?php echo esc_attr($item['section_class_2']);?>">
							<div class="icon">
							<?php if(!empty(wp_get_attachment_url($item['section_image_2']['id']))): ?>
								<img src="<?php echo wp_get_attachment_url($item['section_image_2']['id']);?>" alt="">
							<?php endif;?>
							</div>
							<div class="content">
								<h5><?php echo wp_kses($item['section_title_2'], $allowed_tags);?></h5>
								<p>
									<?php echo wp_kses($item['section_subtitle_2'], $allowed_tags);?>
								</p>
							</div>
						</div>
					</div>
					<?php endforeach; ?>
				</div>
			</div>
		</div>

		<?php  elseif ( 'style3' === $settings['style'] ) : ?>

			<div class="gt-gaming-feature-wrapper">
				<div class="gt-gaming-feature-content m-0 p-0">
					<ul class="gt-icon-list m-0">
						<?php foreach($settings['repeat'] as $item):?>	
						<li>
							<div class="gt-icon">
							<?php if(!empty(wp_get_attachment_url($item['section_image']['id']))): ?>
								<img src="<?php echo wp_get_attachment_url($item['section_image']['id']);?>" alt="">
							<?php endif;?>
							</div>
							<div class="gt-content">
								<h4><?php echo wp_kses($item['section_title'], $allowed_tags);?></h4>
								<span><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></span>
							</div>
						</li>
						<?php endforeach; ?>
					</ul>
				</div>
			</div>		
			
<?php endif ;?>	

             
		<?php 
	}


}

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