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


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

class PLS_Newsletter_Widget extends PLS_Widget_Base {

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

		$this->widget_cssclass 		= 'pls-newsletter-widget';
        $this->widget_description 	= esc_html__("Display newsletter.", 'modave-core');
        $this->widget_id 			= 'pls-newsletter';
        $this->widget_name 			= esc_html__('PLS: Newsletter', 'modave-core');
		$this->settings = array(
            
			'title' => array(
                'type' 	=> 'text',
                'label' => esc_html__('Title', 'modave-core'),
                'std' 	=> esc_html__('Newsletter','modave-core'),
            ),
			'newsletter_style' => array(
				'type' 		=> 'select',
				'label' 	=> esc_html__('Newsletter:', 'modave-core'),
				'options' 	=> array(
					'simple-form'	=> esc_html__( 'Simple Form', 'modave-core' ),
					'overlay-form'	=> esc_html__( 'Overlay Form', 'modave-core' ),
				),
				'std' 		=> 'overlay-form',
			),
			'newsletter_tagline' => array(
                'type' 				=> 'textarea',
                'label' 			=> esc_html__('Newsletter Tagline', 'modave-core'),
				'allow_esc_html'	=> false,
                'std' 				=> 'Sign up for our newsletter and get 10% off your first purchase.',
            ),
		);
		parent::__construct();
	}
	
    /**
     * Output widget.
     *
     * @see WP_Widget
     *
     * @param array $args
     * @param array $instance
     */
    public function widget($args, $instance){
		
        ob_start();

        $this->widget_start($args, $instance);
		do_action( 'pls_core_before_newsletter');
		
		$newsletter_style = isset( $instance['newsletter_style'] ) ?$instance['newsletter_style'] : 'overlay-form' ;
		$newsletter_tagline = apply_filters('newsletter_tagline', empty($instance['newsletter_tagline']) ? false : $instance['newsletter_tagline']);
		$style_class = 'overlay-form'; 
		if( $newsletter_style != 'overlay-form' ){ 
			$style_class = 'simple-form pls-newsletter-in-column';
		}
		?>
		<div class="pls-newsletter <?php echo esc_attr( $style_class );?>">
			<?php 			
				if( ! empty( $newsletter_tagline ) ){ ?>
					<div class="subscribe-tagline">
						<?php echo do_shortcode( $newsletter_tagline ) ?>
					</div>
					<?php
				}			
				pls_subscribe_form();
			?>
		</div>
		
		<?php		
		do_action( 'pls_core_after_newsletter');
		
		$this->widget_end($args);
		
        echo ob_get_clean();
    }

}