<?php

namespace TRANZIXPLUGIN\Element;

use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Plugin;

/**
 * Elementor button widget.
 * Elementor widget that displays a button with the ability to control every
 * aspect of the button design.
 *
 * @since 1.0.0
 */
class Team 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 'tranzix_team';
	}

	/**
	 * Get widget title.
	 * Retrieve button widget title.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Team', 'tranzix' );
	}

	/**
	 * Get widget icon.
	 * Retrieve button widget icon.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-briefcase';
	}

	/**
	 * 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 [ 'tranzix' ];
	}
	
	/**
	 * 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(
			'team',
			[
				'label' => esc_html__( 'Team', 'tranzix' ),
			]
		);
		$this->add_control(
            'style', 
				[
					'label'   => esc_html__( 'Choose Different Style', 'tranzix' ),
					'label_block' => true,
					'type'    => Controls_Manager::SELECT,
					'default' => 'style1',
					'options' => array(
						'style10' => esc_html__( 'Choose Style 10', 'tranzix' ),
					),
				]
		);
		
		$this->add_control(
			'subtitle',
			[
				'label'       => __( 'Sub Title', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style1',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style2',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style3',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),	
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style6',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style7',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style9',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style10',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style11',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style22',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Sub title', 'rashid' ),
			]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style1',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style2',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style3',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style4',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style5',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style6',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style7',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style8',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style9',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style10',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style11',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style12',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style13',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style14',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style15',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style16',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style17',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style18',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style19',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style20',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style21',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style22',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your title', 'rashid' ),
			]
		);
		$this->add_control(
			'text',
			[
				'label'       => __( 'Description Text', 'rashid' ),
				'conditions' => array(
					'relation' => 'or',
					'terms'    => array(
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style1',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style9',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style15',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style16',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style17',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style18',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style19',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style20',
						),
						array(
							'name'     => 'style',
							'operator' => '==',
							'value'    => 'style21',
						),
					),
				),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Description', 'rashid' ),
			]
		);
		$this->add_control(
			'column',
			[
				'label'   => esc_html__( 'Column', 'rashid' ),
				'type'    => Controls_Manager::SELECT,
				'default' => '3',
				'options' => array(
					'12'   => esc_html__( 'One Column', 'rashid' ),
					'6'   => esc_html__( 'Two Column', 'rashid' ),
					'4'   => esc_html__( 'Three Column', 'rashid' ),
					'3'   => esc_html__( 'Four Column', 'rashid' ),
					'2'   => esc_html__( 'Six Column', 'rashid' ),
				),
			]
		);
		$this->add_control(
			'sec_class',
			[
				'label'       => __( 'Section Class', 'rashid' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter Section Class', 'rashid' ),
			]
		);
		$this->add_control(
			'text_limit',
			[
				'label'   => esc_html__( 'Text Limit', 'tranzix' ),
				'type'    => Controls_Manager::NUMBER,
				'default' => 3,
				'min'     => 1,
				'max'     => 100,
				'step'    => 1,
			]
		);
		$this->add_control(
			'query_number',
			[
				'label'   => esc_html__( 'Number of post', 'tranzix' ),
				'type'    => Controls_Manager::NUMBER,
				'default' => 3,
				'min'     => 1,
				'max'     => 100,
				'step'    => 1,
			]
		);
		$this->add_control(
			'query_orderby',
			[
				'label'   => esc_html__( 'Order By', 'tranzix' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'date',
				'options' => array(
					'date'       => esc_html__( 'Date', 'tranzix' ),
					'title'      => esc_html__( 'Title', 'tranzix' ),
					'menu_order' => esc_html__( 'Menu Order', 'tranzix' ),
					'rand'       => esc_html__( 'Random', 'tranzix' ),
				),
			]
		);
		$this->add_control(
			'query_order',
			[
				'label'   => esc_html__( 'Order', 'tranzix' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'DESC',
				'options' => array(
					'DESc' => esc_html__( 'DESC', 'tranzix' ),
					'ASC'  => esc_html__( 'ASC', 'tranzix' ),
				),
			]
		);
		$this->add_control(
			'query_exclude',
			[
				'label'       => esc_html__( 'Exclude', 'tranzix' ),
				'type'        => Controls_Manager::TEXT,
				'description' => esc_html__( 'Exclude posts, pages, etc. by ID with comma separated.', 'tranzix' ),
			]
		);
		$this->add_control(
            'query_category', 
				[
				  'type' => Controls_Manager::SELECT,
				  'label' => esc_html__('Category', 'tranzix'),
				  'options' => get_team_categories()
				]
		);
		$this->add_control(
			'show_pagination',
			[
				'label' => __( 'Enable/Disable Pagination', 'tranzix' ),
				'type'     => Controls_Manager::SWITCHER,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enable/Disable Pagination', 'tranzix' ),
			]
		);
		
		
		$this->end_controls_section();
		
		
		
		// New Tab#1

		$this->start_controls_section(
					'content_section',
					[
						'label' => __( 'Image Block', 'rashid' ),
						'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
					]
				);
				$this->add_control(
					'bgimg',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style3',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style4',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style7',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style13',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style22',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg1',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style3',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style13',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg2',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style3',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style12',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style13',
								),
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style14',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				$this->add_control(
					'bgimg3',
					[
						'label' => esc_html__('Background image', 'rashid'),
						'conditions' => array(
							'relation' => 'or',
							'terms'    => array(
								array(
									'name'     => 'style',
									'operator' => '==',
									'value'    => 'style3',
								),
							),
						),
						'type' => Controls_Manager::MEDIA,
						'default' => ['url' => Utils::get_placeholder_image_src(),],
					]
				);
				
				
		$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();
        
        $paged = tranzix_set($_POST, 'paged') ? esc_attr($_POST['paged']) : 1;

		$this->add_render_attribute( 'wrapper', 'class', 'templatepath-tranzix' );
		$args = array(
			'post_type'      => 'tranzix_team',
			'posts_per_page' => tranzix_set( $settings, 'query_number' ),
			'orderby'        => tranzix_set( $settings, 'query_orderby' ),
			'order'          => tranzix_set( $settings, 'query_order' ),
			'paged'         => $paged
		);
		if ( tranzix_set( $settings, 'query_exclude' ) ) {
			$settings['query_exclude'] = explode( ',', $settings['query_exclude'] );
			$args['post__not_in']      = tranzix_set( $settings, 'query_exclude' );
		}
		if( tranzix_set( $settings, 'query_category' ) ) $args['team_cat'] = tranzix_set( $settings, 'query_category' );
		$query = new \WP_Query( $args );

		if ( $query->have_posts() ) 
		{
		?>
		
		<?php  if ( 'style10' === $settings['style'] ) : ?>
		
		<section class="team-five about-page-1 p_relative pt_140 centred pb_140 <?php echo esc_attr($settings['sec_class']);?>">
            <div class="auto-container">
				<?php if($settings['title']): ?>
                <div class="sec-title-three p_relative d_block mb_50">
                    <h6 class="d_block fs_18 lh_26 fw_sbold font_family_inter uppercase mb_12"><?php echo $settings['subtitle'];?></h6>
                    <h2 class="d_block fs_50 fw_bold font_family_inter"><?php echo $settings['title'];?></h2>
                </div>
				<?php endif; ?>
                <div class="row clearfix">
				
					<?php while ( $query->have_posts() ) : $query->the_post(); ?>
				
                    <div class="col-lg-<?php echo esc_attr($settings['column'], true );?> col-md-6 col-sm-12 team-block">
                        <div class="team-block-one wow fadeInUp animated" data-wow-delay="00ms" data-wow-duration="1500ms">
                            <div class="inner-box p_relative d_block b_radius_5">
                                <div class="image-box p_relative d_block">
                                    <figure class="image p_relative d_block">
										<?php the_post_thumbnail(); ?>
									</figure>
									
									
									<?php	
									$icons = get_post_meta( get_the_id(), 'social_profile', true );
										if ( ! empty( $icons ) ) :?>
                                    <ul class="social-links-two">
									
										<?php
										foreach ( $icons as $h_icon ) :
										$header_social_icons = json_decode( urldecode( tranzix_set( $h_icon, 'data' ) ) );
										if ( tranzix_set( $header_social_icons, 'enable' ) == '' ) {
										continue;
										}
										$icon_class = explode( '-', tranzix_set( $header_social_icons, 'icon' ) );?>
									
                                        <li class="p_relative d_iblock"><a href="<?php echo tranzix_set( $header_social_icons, 'url' ); ?>" class="w_40 h_40 lh_40 fs_17 centred"><i class="fab <?php echo esc_attr( tranzix_set( $header_social_icons, 'icon' ) ); ?>"></i></a></li>
										
										<?php endforeach; ?>
										
                                    </ul>
									<?php endif; ?>
									
									
									
                                </div>
                                <div class="lower-content p_relative d_block pt_25">
                                    <h4 class="p_relative d_iblock fs_24 lh_30 fw_sbold"><a href="<?php echo esc_url(get_post_meta( get_the_id(), 'team_link', true ));?>"><?php the_title(); ?></a></h4>
                                    <span class="designation fs_16 p_relative d_block font_family_poppins"><?php echo (get_post_meta( get_the_id(), 'designation', true ));?></span>
                                </div>
                            </div>
                        </div>
                    </div>
					
					<?php endwhile; ?>
					
                </div>
				
				<?php if($settings['show_pagination']){ ?>
				<div class="pagination-wrapper p_relative d_block pt_40">
					<?php tranzix_the_pagination2(array('total'=>$query->max_num_pages, 'next_text' => '<i class="fa fa-long-arrow-right"></i> ', 'prev_text' => '<i class=" fa fa-long-arrow-left"></i>')); ?>
				</div>
				<?php } ?>
				
            </div>
        </section>
		
		<?php endif;?>
		
  
        <?php }
		wp_reset_postdata();
	}

}