<?php
namespace Elementor;

class ThemeDraft_Team_Minimal_Widget extends Widget_Base {

	public function get_name() {

		return 'themedraft_team_minimal';
	}

	public function get_title() {
		return esc_html__( 'Team Member Minimal', '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_member_settings',
			[
				'label' => esc_html__( 'Team Member', 'themedraft-core' ),
				'tab'   => Controls_Manager::TAB_CONTENT,
			]
		);

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

		$this->add_control(
			'member_name',
			[
				'label'       => __( 'Name', 'themedraft-core' ),
				'type'        => Controls_Manager::TEXT,
				'label_block' => true,
				'default'     => __( 'Marth Healey', 'themedraft-core' ),
			]
		);

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

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

        $this->add_responsive_control(
            'text_align',
            [
                'label'       => esc_html__('Text Align', 'themedraft-core'),
                'description' => esc_html__('', 'themedraft-core'),
                'type'        => Controls_Manager::CHOOSE,
                'label_block' => false,

                'options' => [
                    'left' => [
                        'title' => __('Left', 'themedraft-core'),
                        'icon'  => 'fa fa-align-left',
                    ],

                    'center' => [
                        'title' => __('Center', 'themedraft-core'),
                        'icon'  => 'fa fa-align-center',
                    ],

                    'right' => [
                        'title' => __('Right', 'themedraft-core'),
                        'icon'  => 'fa fa-align-right',
                    ],
                ],
                'devices' => ['desktop', 'tablet', 'mobile'],

                'selectors' => [
                    '{{WRAPPER}} .td-team-minimal-wrapper' => 'text-align: {{VALUE}};',
                ],

            ]
        );

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

		$this->add_control(
			'tm_animation_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->end_controls_section();

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

		$this->add_group_control(
		    Group_Control_Typography::get_type(),
		    [
		        'name' => 'name_typography',
		        'label' => __( 'Name Typography', 'themedraft-core' ),
		        'selector' => '{{WRAPPER}} .td-minimal-member-name',
		    ]
		);

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

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

		$this->add_group_control(
		    Group_Control_Typography::get_type(),
		    [
		        'name' => 'designation_typo',
		        'label' => __( 'Designation Typography', 'themedraft-core' ),
		        'selector' => '{{WRAPPER}} .td-team-minimal-wrapper .member-designation',
		    ]
		);

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

		$this->end_controls_section();

	}

	//Render
	protected function render() {
		$settings = $this->get_settings_for_display();
		if($settings['entrance_animation']){
			$td_animation = 'wow'.' ' . $settings['entrance_animation'];
			$td_animation_duration = $settings['tm_animation_duration'];
		}else{
			$td_animation ='';
			$td_animation_duration ='';
		}
		?>

		<div class="td-team-minimal-wrapper <?php echo $td_animation;?>" <?php echo $td_animation_duration;?>>
			<div class="td-minimal-team-content">
				<div class="td-minimal-member-image td-cover-bg" style="background-image: url(<?php echo $settings['image']['url'];?>)"></div>
				<?php if($settings['details_link']['url']) : ?>
                    <a href="<?php echo $settings['details_link']['url']?>">
				<?php endif; ?>

                    <h4 class="td-minimal-member-name"><?php echo $settings['member_name'];?></h4>
				<?php if($settings['details_link']['url']) : ?>
                    </a>
				<?php endif; ?>

				<span class="member-designation"><?php echo $settings['designation'];?></span>
			</div>
		</div>

		<?php

	}
}

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