<?php
namespace Elementor;

class ThemeDraft_Team_Three_Widget extends Widget_Base {

	public function get_name() {

		return 'themedraft_team_member_three';
	}

	public function get_title() {
		return esc_html__( 'Team Member Three', 'themedraft-core' );
	}

	public function get_icon() {

		return 'flaticon-industry-engineer-4';
	}

	public function get_categories() {
		return [ 'themedraft_elements' ];
	}


	protected function register_controls() {

		//Content tab start
		$this->start_controls_section(
			'team_three_settings',
			[
				'label' => esc_html__( 'Team Member', 'themedraft-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

		$repeater = new Repeater();

		$repeater->add_control(
			'member_name',
			[
				'label'       => __( 'Member Name', 'themedraft-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => __( 'Md Nadim Khan', 'themedraft-core' ),
				'label_block' => true,
			]
		);

		$repeater->add_control(
			'designation',
			[
				'label'       => __( 'Designation', 'themedraft-core' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => __( 'Senior Engineer', 'themedraft-core' ),
				'label_block' => true,
			]
		);

		$repeater->add_control(
			'image',
			[
				'label'       => __( 'Member Image', 'themedraft-core' ),
				'type'        => Controls_Manager::MEDIA,
				'label_block' => true,
				'default'     => [
					'url' => Utils::get_placeholder_image_src(),
				],
			]
		);

		$repeater->add_control(
			'details_url',
			[
				'label'         => __( 'Details Url', 'themedraft-core' ),
				'type'          => Controls_Manager::URL,
				'placeholder'   => __( 'https://your-link.com', 'themedraft-core' ),
				'show_external' => true,
				'default'       => [
					'url'         => '',
					'is_external' => false,
					'nofollow'    => false,
				],
			]
		);

		$repeater->add_control(
			'entrance_animation',
			[
				'label' => __( 'Entrance Animation', 'themedraft-core' ),
				'type' => Controls_Manager::ANIMATION,
				'prefix_class' => 'animated ',
				'separator' => 'before ',
			]
		);

		$repeater->add_control(
			'team_3_anim_duration',
			[
				'label'     => __( 'Animation Duration', 'themedraft-core' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'data-wow-duration="1.25s"',
				'options'   => [
					'data-wow-duration="2s"'    => __( 'Slow', 'themedraft-core' ),
					'data-wow-duration="1.25s"' => __( 'Normal', 'themedraft-core' ),
					'data-wow-duration=".75s"'  => __( 'Fast', 'themedraft-core' ),
				],
				'condition' => [
					'entrance_animation!' => '',
				]
			]
		);

		$this->add_control(
			'members',
			[
				'label'       => __( 'Member List', 'themedraft-core' ),
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => [
					[
						'member_name' => __( 'Md Nadim Khan', 'themedraft-core' ),
						'designation' => __( 'Senior Engineer', 'themedraft-core' ),
					],
				],
				'title_field' => '{{{ member_name }}}',
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'column_settings',
			[
				'label' => esc_html__( 'Column', 'themedraft-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'desktop_col',
			[
				'label'   => __( 'Column On Desktop', 'themedraft-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'col-lg-3',
				'options' => [
					'col-lg-12' => __( '1 Column', 'themedraft-core' ),
					'col-lg-6'  => __( '2 Column', 'themedraft-core' ),
					'col-lg-4'  => __( '3 Column', 'themedraft-core' ),
					'col-lg-3'  => __( '4 Column', 'themedraft-core' ),
				],
			]
		);

		$this->add_control(
			'tab_col',
			[
				'label'   => __( 'Column On Tablet', 'themedraft-core' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'col-md-6',
				'options' => [
					'col-md-12' => __( '1 Column', 'themedraft-core' ),
					'col-md-6'  => __( '2 Column', 'themedraft-core' ),
					'col-md-4'  => __( '3 Column', 'themedraft-core' ),
					'col-md-3'  => __( '4 Column', 'themedraft-core' ),
				],
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'team_color_options',
			[
				'label' => esc_html__( 'Colors', 'themedraft-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'shape_one_color',
			[
				'label'       => esc_html__('Shape One Color', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-single-team-three-member .td-image-shape-1' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'shape_two_color',
			[
				'label'       => esc_html__('Shape Two Color', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-member-three-content .td-shape-2' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'background_color',
			[
				'label'       => esc_html__('Background Color', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-member-three-content' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'background_color_on_hover',
			[
				'label'       => esc_html__('Background Color On Hover', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-single-team-three-member:hover .td-member-three-content' => 'background-color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'mane_color',
			[
				'label'       => esc_html__('Name Color', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-member-three-content .name' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'mane_color_on_hover',
			[
				'label'       => esc_html__('Name Color On Hover', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-single-team-three-member:hover .td-member-three-content .name' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'designation_color',
			[
				'label'       => esc_html__('Designation Color', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-single-team-three-member .designation' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'designation_color_on_hover',
			[
				'label'       => esc_html__('Designation Color On Hover', 'themedraft-core'),
				'type'        => Controls_Manager::COLOR,
				'selectors'   => [
					'{{WRAPPER}} .td-single-team-three-member:hover .designation' => 'color: {{VALUE}};',
				],
			]
		);

		$this->end_controls_section();

	}

	//Render
	protected function render() {
		$settings = $this->get_settings_for_display();
		$item_col = $settings['desktop_col'] . ' '. $settings['tab_col'];
		?>

        <div class="td-team-three-wrapper">
            <div class="row">
				<?php
				if ( $settings['members'] ) {
					foreach ( $settings['members'] as $member ) {
						if($member['entrance_animation']){
							$td_animation = 'wow'.' ' . $member['entrance_animation'];
							$td_animation_duration = $member['team_3_anim_duration'];
						}else{
							$td_animation ='';
							$td_animation_duration ='';
						}
						?>

                        <div class="<?php echo $item_col;?>">
                            <div class="td-single-team-three-member <?php echo $td_animation;?>" <?php echo $td_animation_duration;?>>
                                <div class="td-image-wrapper">
                                    <div class="td-image-shape td-image-shape-1"></div>
									<?php if($member['details_url']['url']) : ?>
                                    <a class="member-image-link" href="<?php echo $member['details_url']['url'];?>">
										<?php endif; ?>
                                        <div class="td-member-three-image td-cover-bg" style="background-image: url(<?php echo esc_url($member['image']['url']);?>)">
                                        </div>
										<?php if($member['details_url']['url']) : ?>
                                    </a>
								<?php endif; ?>
                                </div>

                                <div class="td-member-three-content td-transition">
                                    <div class="td-shape-2"></div>
                                    <div class="team-three-name-designation">
										<?php if($member['details_url']['url']) : ?>
                                            <a href="<?php echo $member['details_url']['url'];?>" class="name td-transition"><?php echo $member['member_name'];?></a>
										<?php else : ?>
                                            <h3 class="name td-transition"><?php echo $member['member_name'];?></h3>
										<?php endif; ?>
                                        <span class="designation td-transition"><?php echo $member['designation'];?></span>
                                    </div>
                                </div>
                            </div>
                        </div>
						<?php
					}
				}
				?>
            </div>

        </div>

		<?php

	}

}

Plugin::instance()->widgets_manager->register( new ThemeDraft_Team_Three_Widget );