<?php
/**
 * Elementor Envy_Chimp Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.0
 */
class Elementor_Envy_Chimp_Widget extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve Envy_Chimp widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'EnvyChimp';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Envy_Chimp widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'EnvyChimp', 'envy-chimp' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Envy_Chimp widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-envelope';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Envy_Chimp widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'general' ];
	}

	/**
	 * Register Envy_Chimp 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(
			'content_section',
			[
				'label' => __( 'Content', 'envy-chimp' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'title',
			[
				'label' => __( 'Title', 'envy-chimp' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'TEXT',
				'placeholder' => __( 'Write title here', 'envy-chimp' ),
			]
		);

		$this->add_control(
			'form',
			[
				'label' => __( 'Form Type', 'envy-chimp' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'default' => 'subscribe',
				'options' => [
					'subscribe'  => __( 'Subscribe', 'envy-chimp' ),
					'login-signup' => __( 'Login & Signup', 'envy-chimp' ),
					'login' => __( 'Login', 'envy-chimp' ),
					'signup' => __( 'Signup', 'envy-chimp' )
				],
			]
		);

		$this->end_controls_section();

	}

	/**
	 * Render Envy_Chimp widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.0
	 * @access protected
	 */
	protected function render() {
		    
	    $settings = $this->get_settings_for_display();
    	if( ! $settings['title'] == '' ) : ?>
	        <h2 style="text-align:center;margin-bottom:20px;"><?php echo $settings['title']; ?></h2>
	    <?php endif;

	    if( $settings['form'] == 'subscribe' ) : ?>
	    	<p style="text-align:center"><?php echo do_shortcode("[envy_chimp_subscribe_form]"); ?>
	    	</p>
	    <?php elseif( $settings['form'] == 'login-signup' ) : ?>
		    <p style="text-align:center"><?php echo do_shortcode("[envy_chimp_login_signup_form]"); ?></p>
	    <?php elseif( $settings['form'] == 'login' ) : ?>
		    <p style="text-align:center"><?php echo do_shortcode("[envy_chimp_login_form]"); ?></p> 
		<?php elseif( $settings['form'] == 'signup' ) : ?>
		    <p style="text-align:center"><?php echo do_shortcode("[envy_chimp_signup_form]"); ?></p>
		<?php endif;
	}

}
