<?php
/**
 *	PLS Widget:Contact Info
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}


if ( ! class_exists( 'PLS_Widget_Base' ) ) {
	return;
}

class PLS_Contact_Info_Widget extends PLS_Widget_Base {

	/**
	 * Constructor.
	 */
	public function __construct() {

		$this->widget_cssclass 		= 'pls-contact-info-widget';
        $this->widget_description 	= esc_html__( 'Display Contact Info', 'modave-core' );
        $this->widget_id 			= 'pls-contact-info';
        $this->widget_name 			= esc_html__( 'PLS: Contact Info', 'modave-core' );
		$this->image_sizes 			= pls_core_get_all_image_sizes(true);
        array_shift($this->image_sizes);
		
		$this->settings = array(
            'title' => array(
                'type' => 'text',
                'label' => esc_html__( 'Title:', 'modave-core' ),
				'std' => __( 'About Us','modave-core' ),
            ),
			'hide_title' => array(
                'type' => 'checkbox',
                'label' => esc_html__( 'Hide Title?', 'modave-core' ),
				'std' => true,
            ),
			'logo' => array(
                'type' => 'image',
                'label' => esc_html__( 'Upload Logo:', 'modave-core' ),                
            ),
			'logo_size' => array(
                'type' => 'select',
                'label' => esc_html__( 'Logo Size:', 'modave-core' ),
                'options' => $this->image_sizes,
                'std' => 'full',
            ),
			'our_site_url' => array(
                'type' => 'text',
                'label' => esc_html__( 'Site Url:', 'modave-core' ),
            ),
			'about_tagline' => array(
                'type' => 'textarea',
                'label' => esc_html__( 'About Tagline:', 'modave-core' )
            ),
			'email_address' => array(
                'type' => 'text',
                'label' => esc_html__( 'Email:', 'modave-core' ),
            ),
			'phone_number' => array(
                'type' => 'text',
                'label' => esc_html__( 'Phone Number:', 'modave-core' ),
            ),
		);
		parent::__construct();
	}
	
	/**
     * Output widget.
     *
     * @see WP_Widget
     *
     * @param array $args
     * @param array $instance
     */
    public function widget($args, $instance){

        ob_start();
		
		$hide_title 	= ( ! empty( $instance['hide_title'] ) ) ? (bool) $instance['hide_title'] : false;
		if( $hide_title ) unset( $instance['title'] );
		
		$this->widget_start( $args, $instance );
		
		do_action( 'pls_core_before_about_us' );
		
		$logo 			= ( ! empty( $instance['logo'] ) ) ?  $instance['logo'] : '';		
		$logo_size 		= ( ! empty( $instance['logo_size'] ) ) ? esc_attr( $instance['logo_size'] ) : 'full';	
		$logo_url 		= '';
		if( $logo ){
			$logo_url =  pls_get_image_src( $logo, $logo_size );
		}
		$logo_url 		= apply_filters( 'pls_widget_contact_info_logo', $logo_url );
		$our_site_url 	= ( ! empty( $instance['our_site_url'] ) ) ?  $instance['our_site_url'] : '#';
		$about_tagline 	= apply_filters( 'about_tagline', empty( $instance['about_tagline'] ) ? false : $instance['about_tagline'] );
		$email_address 	= ( ! empty( $instance['email_address'] ) ) ?  $instance['email_address'] : '';		
		$phone_number 	= ( ! empty( $instance['phone_number'] ) ) ?  $instance['phone_number'] : '';
		//$icon_html = '';
		$html = '<div class="pls-contact-info">';
		
		if(  ! empty( $logo_url ) ) {
			$html.='<p class="pls-about-logo"><a href="'.esc_url( $our_site_url ) .'"><img src="'. esc_url( $logo_url ) .'" alt="logo" /></a></p>';			
		}
		
		if( ! empty( $about_tagline ) ) {
			$html.='<div class="pls-contact-info-description">'. wp_kses_post( $about_tagline ) .'</div>';
		}
		
		$html.='<ul class="pls-contact-info-data">';
			
			if( $email_address != '' ):
				$html.='<li><i class="picon-envelope"></i><span class="pls-contact-info-text">';
				if( is_email( $email_address ) ){
					$html.='<a href="mailto:'. esc_attr( $email_address ).' ">'.esc_html( $email_address ) .'</a>';
				}else{
					$html.= esc_html__( 'Invalid Email Address', 'modave-core' );
				}
				$html.='</span>';
				$html.='</li>';
			endif;
			
			if( $phone_number != '' ) {
				$html.='<li><i class="picon-phone"></i><span class="pls-contact-info-text">'. esc_html( $phone_number ) .'</span></li>';
			}
			
			do_action( 'pls_core_contacnt_info_bottom' );
			
		$html.='</ul>';
		$html.='</div>';
		
		echo $html;

		do_action( 'pls_core_after_contacnt_info' );

		$this-> widget_end( $args );

        echo ob_get_clean();
    }
}
