<?php
/**
 * Elementor Counter area one
 *
 * @since 1.0.0
 */
class DexenCounter extends \Elementor\Widget_Base {
	public function get_name() {
		return 'dexen_counter';
	}
	public function get_title() {
		return esc_html__( 'Counter area one', 'plugin-name' );
	}
	public function get_icon() {
		return 'fa fa-object-ungroup';
	}
	public function get_categories() {
		return array( 'dexencore' );
	}
	protected function _register_controls() {
		$this->start_controls_section(
			'counter_area_content',
			array(
				'label' => esc_html__( 'Counter area Content', 'plugin-name' ),
				'tab'   => \Elementor\Controls_Manager::TAB_CONTENT,
			)
		);
		$repeater = new \Elementor\Repeater();

		$repeater->add_control(
			'counter_count_number',
			array(
				'label'       => __( 'Counter number', 'plugin-name' ),
				'type'        => \Elementor\Controls_Manager::TEXT,
				'placeholder' => __( 'number here', 'plugin-name' ),
			)
		);
		$repeater->add_control(
			'counter_count_text',
			array(
				'label'       => __( 'Counter text', 'plugin-name' ),
				'type'        => \Elementor\Controls_Manager::TEXT,
				'placeholder' => __( 'number text', 'plugin-name' ),
			)
		);
		$repeater->add_control(
			'button_text_link',
			array(
				'label'         => esc_html__( 'Button link', 'plugin-domain' ),
				'type'          => \Elementor\Controls_Manager::URL,
				'show_external' => true,
				'default'       => array(
					'url'         => '',
					'is_external' => true,
					'nofollow'    => true,
				),
			)
		);
		$this->add_control(
			'counter_count_list',
			array(
				'label'  => __( 'Counter list', 'plugin-name' ),
				'type'   => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
			)
		);

		$this->end_controls_section();
	}
	protected function render() {
		$settings           = $this->get_settings_for_display();
		$counter_count_list = $settings['counter_count_list'];
		?>
		   <section class="fun-fact-one  sec-pad-content-margin-50 sec-pad">
			<div class="container text-center">
				<div class="row">
				<?php if ( $counter_count_list ) : ?>
						<?php
						foreach ( $counter_count_list as $item ) {
							$counter_count_number = $item['counter_count_number'];
							$counter_count_text   = $item['counter_count_text'];
							?>
					<div class="col-lg-3 col-md-6 col-sm-12">
						<div class="fun-fact-one__single content-margin-50">
							<h3 class="fun-fact-one__title counter"><?php echo wp_kses_post( $counter_count_number ); ?></h3><!-- /.fun-fact-one__title -->
							<p class="fun-fact-one__text"><?php echo wp_kses_post( $counter_count_text ); ?></p><!-- /.fun-fact-one__text -->
							<?php if ( ! empty( $item['button_text_link']['url'] ) ) : ?>
									<a 
													class="fun-fact-one__link <?php echo esc_attr( $slider_btn_class ); ?>"
													href="<?php echo esc_url( $item['button_text_link']['url'] ); ?>"
													<?php
														$target   = $item['button_text_link']['is_external'] ? ' target=_blank' : '';
														$nofollow = $item['button_text_link']['nofollow'] ? ' rel=nofollow' : '';
														echo esc_attr( $target . $nofollow );
													?>
													><i class="fa fa-angle-right"></i></a>
									</a>   
								<?php endif; ?>
						</div><!-- /.fun-fact-one__single -->
					</div><!-- /.col-lg-3 -->
					<?php } ?>
					 <?php endif; ?>
				</div><!-- /.row -->
			</div><!-- /.container -->
		</section>

		<?php
	}
}

\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \DexenCounter() );
