<?php
/**
* Blogto Instagram
*
* @since Blogto 1.0.0
*/

if ( ! class_exists( 'Blogto_Instagram' ) ) :
class Blogto_Instagram{

	/**
	* Stores class instance
	* 
	* @since  Blogto 1.0.0
	* @access protected
	* @var    object
	*/
	protected static $instance = NULL;

	/**
	* Retrives the instance of this class
	* 
	* @since  Blogto 1.0.0
	* @access public
	* @return object
	*/
	public static function get_instance() {

	    if ( ! self::$instance ) {
	      self::$instance = new self();
	    }

	    return self::$instance;
	}

	
	public function __construct(){

		add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
	}

	/**
	* Add necessary scripts
	* 
	* @since  Blogto 1.0.0
	* @access public
	* @return null
	*/
	public function scripts(){
		
		if( blogto_get_option( 'enable_instagram' ) ){
			wp_enqueue_script( 'jquery-instagram', get_theme_file_uri( 'modules/instagram/main.js' ), array( 'jquery' ), null, true );
			wp_localize_script( 'jquery-instagram', 'INSTA', array(
			   'access_token' => blogto_get_option( 'insta_access_token' ),
			   'count'        => blogto_get_option( 'insta_count' ),
			   'new_link_text' => esc_html__( 'Open In New Window', 'blogto' )
			) );
		}
	}

	/**
	* Render User Interface
	* 
	* @since  Blogto 1.0.0
	* @access public
	* @return null
	*/
	public function init(){
		?>
			<div class="wrapper wrap-instagram-section">
				<?php if( blogto_get_option( 'enable_follow_us_button' ) ): ?>
					<h2 class="instagram-title" style="display: none">
						<a href="#" target="_blank">
							<span class="kfi kfi-instagram"></span>
							<?php echo esc_html__( 'Follow on Instagram', 'blogto' ); ?>
						</a>
					</h2>
				<?php endif; ?>
				<div class="keon-instagram owl-carousel owl-theme"></div>
				<div class="keon-instagram-error text-center" style="display:none"></div>
			</div>
		<?php
	}
}
endif;

if( ! function_exists( 'blogto_instagram' ) ):
/**
* Returns the instance of Blogto_Instagram class
* @since Blogto 1.0.0
*/
function blogto_instagram(){
	return Blogto_Instagram::get_instance();
}
endif;

blogto_instagram();
