<?php
/*
 * Element: Contact Info
 */
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Utils;
use Elementor\Group_Control_Typography;
class PLS_Elementor_Contact_Info extends PLS_Elementor_Widget_Base {
	/**
	 * Retrieve the widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
        return 'pls-contact-info';
    }

	/**
     * Get widget title.
     *
     * Retrieve tabs widget title.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Contact Info', 'modave-core' );
    }

    /**
     * Get widget icon.
     *
     * Retrieve tabs widget icon.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'pls-icon eicon-info';
    }
	
	/**
	 * Get widget keywords.
	 *
	 * Retrieve the list of keywords the list widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 * @return array Widget keywords.
	 */
	public function get_keywords() {
		return [ 'Contact Info', 'about info' ];
	}
	
	/**
     * Register tabs 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(
            'pls_info_box_section',
            [
                'label'		=> esc_html__( 'General', 'modave-core' ),
            ]
        );
		$this->add_control(
            'title',
            [
                'label'			=> esc_html__('Title', 'modave-core'),
                'type'			=> Controls_Manager::TEXT,
				'description' 	=> esc_html__( 'Leave empty for hide title.', 'modave-core' ),
				'default'		=> 'Modave',
				'label_block'	=> true,
            ]
        );
		$this->add_control(
			'image',
			[
				'label'     => esc_html__( 'Choose image', 'modave-core' ),
				'type'      => Controls_Manager::MEDIA,
				'default' 	=> [
					'url'	=> Utils::get_placeholder_image_src(),
				]
			]
		);
		$this->add_control(
			'link',
			[
				'label' 		=> esc_html__( 'Add Link', 'modave-core' ),
				'type'  		=> Controls_Manager::URL,
				'placeholder' 	=> esc_html__( 'https://your-link.com', 'modave-core' ),
				'default'		=> [
					'url'		=> '#',
				],
			]
		);
		$this->add_control(
            'description',
            [
                'label'			=> esc_html__('Description', 'modave-core'),
				'type'			=> Controls_Manager::TEXTAREA,
                'default'		=> esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'modave-core'),
                'label_block'	=> true,
            ]
        );	
		$repeater = new Repeater();
		$repeater->add_control(
            'label',
            [
                'label' 	=> esc_html__('Label', 'modave-core'),
                'type' 		=> Controls_Manager::TEXT,
            ]
        );
		$repeater->add_control(
            'text',
            [
                'label' 	=> esc_html__('Text', 'modave-core'),
                'type' 		=> Controls_Manager::TEXTAREA,
            ]
        );
		$this->add_control(
			'info_items_view',
			[
				'label' 	=> esc_html__( 'Layout', 'modave-core' ),
				'type' 		=> Controls_Manager::CHOOSE,
				'default' 	=> 'traditional',
				'options' 	=> [
					'traditional' => [
						'title' 	=> esc_html__( 'Default', 'modave-core' ),
						'icon' 		=> 'eicon-editor-list-ul',
					],
					'inline' 	=> [
						'title' 	=> esc_html__( 'Inline', 'modave-core' ),
						'icon' 		=> 'eicon-ellipsis-h',
					],
				],
			]
		);
		$this->add_control(
            'info_items',
            [
                'label' 	=> esc_html__('Contact Info Items','modave-core'),
                'type' 		=> Controls_Manager::REPEATER,
                'fields' 	=> $repeater->get_controls(),
                'default'	=> [
					[
						'label'	=> 'Email:',						
						'text' 	=> 'info@domain.com',
					],
					[
						'label'	=> 'Phone:',						
						'text'	=> '(000) 898-7894',
					],
					[
						'label'	=> 'Address:',						
						'text'	=> '549 Oak St.Crystal Lake, IL 60014',
					],
					
				],
                'title_field' => '{{{ label }}}',
            ]
        );
		$this->end_controls_section();
		
		/**
		 * Contact Info Style.
		 */
		 
		$this->start_controls_section(
			'style_section_title',
			[
				'label' => esc_html__( 'Title', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_control(
			'title_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .pls-contact-info-title' => 'color: {{VALUE}}',
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'title_typography',
				'label'    => esc_html__( 'Typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .pls-contact-info-title',
			]
		);
		$this->add_responsive_control(
			'title_mb',
			[
				'label'			=> esc_html__( 'Margin Bottom', 'modave-core' ),
				'label_block'	=> true,
				'type'			=> Controls_Manager::SLIDER,
				'range'			=> [ 'px' => [ 'min' => -50, 'max' => 100 ] ],
				'selectors'		=> [ 
					'{{WRAPPER}} .pls-contact-info-title' => 'margin-bottom: {{SIZE}}px' 
				],
			]
		);
		$this->end_controls_section();
		
		$this->start_controls_section(
			'style_section_desciption',
			[
				'label' => esc_html__( 'Description', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_control(
			'description_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .pls-contact-info-description' => 'color: {{VALUE}}',
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'description_typography',
				'label'    => esc_html__( 'Typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .pls-contact-info-description',
			]
		);
		$this->add_responsive_control(
			'description_mb',
			[
				'label'			=> esc_html__( 'Margin Bottom', 'modave-core' ),
				'label_block'	=> true,
				'type'			=> Controls_Manager::SLIDER,
				'range'			=> [ 'px' => [ 'min' => -50, 'max' => 100 ] ],
				'selectors'		=> [ 
					'{{WRAPPER}} .pls-contact-info-description' => 'margin-bottom: {{SIZE}}px' 
				],
			]
		);
		$this->end_controls_section();
		
		$this->start_controls_section(
			'style_section',
			[
				'label' => esc_html__( 'Label', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_control(
			'label_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .pls-contact-info-label' => 'color: {{VALUE}}',
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'label_typography',
				'label'    => esc_html__( 'Typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .pls-contact-info-label',
			]
		);
		$this->add_responsive_control(
			'label_min_width',
			[
				'label'			=> esc_html__( 'Min Width', 'modave-core' ),
				'label_block'	=> true,
				'type'			=> Controls_Manager::SLIDER,
				'range'			=> [ 'px' => [ 'min' => 10, 'max' => 250 ] ],
				'selectors'		=> [ 
					'{{WRAPPER}} .pls-contact-info-label' => 'min-width: {{SIZE}}px'
				],
				'condition' => [
					'info_items_view' => [ 'traditional' ],
				],
			]
		);
		$this->add_responsive_control(
			'label_gap',
			[
				'label'			=> esc_html__( 'Gap', 'modave-core' ),
				'label_block'	=> true,
				'type'			=> Controls_Manager::SLIDER,
				'range'			=> [ 'px' => [ 'min' => 0, 'max' => 100 ] ],
				'selectors'		=> [ 
					'{{WRAPPER}} .pls-info-items-inline .pls-contact-info-data li' => 'gap: {{SIZE}}px' 
				],
				'condition' => [
					'info_items_view' => [ 'inline' ],
				],
			]
		);
		$this->add_responsive_control(
			'label_mb',
			[
				'label'			=> esc_html__( 'Margin Bottom', 'modave-core' ),
				'label_block'	=> true,
				'type'			=> Controls_Manager::SLIDER,
				'range'			=> [ 'px' => [ 'min' => -50, 'max' => 100 ] ],
				'selectors'		=> [ 
					'{{WRAPPER}} .pls-contact-info-data li' => 'margin-bottom: {{SIZE}}px' 
				],
			]
		);
		$this->end_controls_section();
		
		/**
		 * Contact Info Style.
		 */
		$this->start_controls_section(
			'title_style_section',
			[
				'label' => esc_html__( 'Label Text', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_control(
			'label_text_color',
			[
				'label'     => esc_html__( 'Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .pls-contact-info-text' => 'color: {{VALUE}}',
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'label_text_typography',
				'label'    => esc_html__( 'Typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .pls-contact-info-text',
			]
		);
		$this->end_controls_section();
	}
	
	protected function render() {
		
		$settings = $this->get_settings();
		extract( $settings );
		$settings['id'] 		= pls_uniqid( 'pls-contact-info-' );
		$class					= array( 'pls-element', 'pls-contact-info' );
		$class[]				= ( $info_items_view == 'inline' ) ? 'pls-info-items-inline' : '';
		$settings['class'] 		= implode(' ', array_filter($class) );
		
		$logo_html 			= '';
		if ( isset( $settings['image']['id'] ) && $settings['image']['id'] ) {
			$icon_image_src = pls_get_image_src( $settings['image']['id'], 'full' );
			$logo_html 		= '<img src="'. esc_url($icon_image_src) .'" alt="'.strip_tags( $title ).'"/>';
		}
		$link_attributes = isset($link) ? pls_core_elementor_get_url_attribute($link) : '';
		
		$settings['logo_html'] 			= $logo_html;
		$settings['link_attributes'] 	= $link_attributes;
		
		pls_core_get_templates( 'elements-widgets/contact-info', $settings );
	}
}

$widgets_manager->register(new PLS_Elementor_Contact_Info());