<?php
namespace Elementor;

/**
 * Elementor Widget
 * @package Pubzi
 * @since 1.0.0
 */ 
 
class Counter_Text 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-counter-text-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__( 'Counter text', '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(
			'section_number_content',
			[
				'label' => esc_html__( 'Repeat Content', 'pubzi-core' ),
			]
		);

		$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->add_control(
			'repeat',
			[
				'label' => esc_html__( 'Create New', 'pubzi-core' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => [
					
					[
						'name' => 'section_title',
						'label' => esc_html__( 'Title', 'pubzi-core' ),
						'type' => Controls_Manager::TEXTAREA,
						'default' => esc_html__( '150K', 'pubzi-core' ),
						'label_block' => true,
					],
					[
						'name' => 'section_subtitle',
						'label' => esc_html__( 'Subtitle', 'pubzi-core' ),
						'type' => Controls_Manager::TEXTAREA,
						'default' => esc_html__( 'Happy Customers', 'pubzi-core' ),
						'label_block' => true,
					],

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

					[
						'name' => 'section_class',
						'label' => esc_html__( 'Section Class', 'pubzi-core' ),
						'type' => Controls_Manager::TEXT,
						'default' => esc_html__( 'style-2', 'pubzi-core' ),
						'label_block' => true,
					],

				],
				'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="about-wrapper-2">
		<div class="about-content">
			<div class="counter-wrap-2">
				<?php foreach($settings['repeat'] as $item):?>	
				<div class="counter-item-2 <?php echo esc_attr($item['section_class']); ?> wow fadeInUp" data-wow-delay=".2s">
					<h2>
						<?php echo wp_kses($item['section_title'], $allowed_tags);?>
					</h2>
					<p><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></p>
				</div>
				<?php endforeach; ?>
			</div>
		</div>
	</div>

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

	<div class="feature-record-wrapper">
		<?php foreach($settings['repeat'] as $item):?>	
		<div class="feature-record-item <?php echo esc_attr($item['section_class']); ?>">
			<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">
				<h2><?php echo wp_kses($item['section_title'], $allowed_tags);?></h2>
				<p><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></p>
			</div>
		</div>
		<?php endforeach; ?>
	</div>

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


	<div class="gt-about-wrapper-6 border-0 p-0 m-0">
		<div class="gt-about-content">
			<div class="gt-about-count">

				<?php foreach($settings['repeat'] as $item):?>	
				<div class="gt-count-item wow fadeInUp" data-wow-delay=".2s">
					<h3><?php echo wp_kses($item['section_title'], $allowed_tags);?></h3>
					<p><?php echo wp_kses($item['section_subtitle'], $allowed_tags);?></p>
				</div>
				<?php endforeach; ?>

			</div>
		</div>
	</div> 
	


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

	

<?php endif ;?>	

             
		<?php 
	}


}

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