<?php

/**
 *  Page Structure
 */

if( ! class_exists( 'Inspirelite_Page_Footer' ) ){

    class Inspirelite_Page_Footer{

        /**
         * Member Variable
         *
         * @var instance
         */
        private static $instance;

        /**
         *  Initiator
         */
        public static function get_instance() {
          
            if ( ! isset( self::$instance ) ) {
              self::$instance = new self;
            }
            return self::$instance;
        }

        public function __construct() {

        	add_action( 'inspirelite_footer', array( $this, 'inspirelite_footer_markup' ) );

        	add_action( 'inspirelite_footer_content', array( $this, 'inspirelite_footer_content_markup' ) );

        	add_action( 'inspirelite_footer_content_bottom', array( $this, 'inspirelite_footer_content_bottom_markup' ) ) ;

        	add_action( 'inspirelite_footer_widget', array( $this, 'inspirelite_footer_widget_markup' ) );
        }


        public function inspirelite_footer_markup(){

			inspirelite_footer_before(); ?>

				<footer itemtype="https://schema.org/WPFooter" itemscope="itemscope" id="colophon" <?php self:: inspirelite_footer_class(); ?>>

					<?php inspirelite_footer_content_top(); ?>

					<?php inspirelite_footer_content(); ?>

					<?php inspirelite_footer_content_bottom(); ?>

				</footer><?php 

			inspirelite_footer_after();
        }

		public function inspirelite_footer_content_markup(){

			inspirelite_footer_widget_area_top();

			inspirelite_footer_widget();

			inspirelite_footer_widget_area_bottom();
		}

		public function inspirelite_footer_content_bottom_markup(){

			$_tiny_footer_content = Inspirelite_Redux:: inspirelite_option( 'tiny_footer_content' );

			if( $_tiny_footer_content != '' ){

			   	printf('<div class="tiny-footer-white">
			   				<div class="container">
								<div class="row">
									<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">%1$s</div>
								</div>
							</div>
						</div>',

						/**
						 *  Inspirelite Copyrignt Content here
						 */
					   	$_tiny_footer_content
				);
			}
		}

		public function inspirelite_footer_class( $class = '' ) {

			echo 'class="' . esc_attr( join( ' ', self:: inspirelite_get_footer_class( $class ) ) ) . '"';
		}

		public function inspirelite_get_footer_class( $class = '' ) {

			// array of class names.
			$classes = array();

			// default class for content area.
			$classes[] = 'footer';

			// primary base class.
			$classes[] = 'site-footer';

			if ( ! empty( $class ) ) {
				if ( ! is_array( $class ) ) {
					$class = preg_split( '#\s+#', $class );
				}
				$classes = array_merge( $classes, $class );
			} else {

				// Ensure that we always coerce class to being an array.
				$class = array();
			}

			// Filter primary div class names.
			$classes = apply_filters( 'inspirelite_footer_class', $classes, $class );

			$classes = array_map( 'sanitize_html_class', $classes );

			return array_unique( $classes );
		}


		public static function inspirelite_footer_widget_markup(){

			/** Theme Option To Get Column **/
	        
			if( Inspirelite_Redux:: inspirelite_option( 'footer_column' ) == 'column_1' ){

				  print '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 easetemplate-footer-block">';
				        if ( is_active_sidebar( 'inspirelite-footer-v1-widget' ) ) {
				               dynamic_sidebar( 'inspirelite-footer-v1-widget' ); 
				        }
				  print '</div>';

			}elseif( Inspirelite_Redux:: inspirelite_option( 'footer_column' ) == 'column_2' ){

				foreach( array( '1', '2' ) as $args ){

				    print '<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 easetemplate-footer-block">';
				        if ( is_active_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ) ) {
				          dynamic_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ); 
				        }
				    print '</div>';
				}

			}elseif( Inspirelite_Redux:: inspirelite_option( 'footer_column' ) == 'column_3' ){

				foreach( array( '1', '2', '3' ) as $args ){

				    print '<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 easetemplate-footer-block">';
				        if ( is_active_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ) ) {
				          dynamic_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ); 
				        }
				    print '</div>';
				} 

			}elseif( Inspirelite_Redux:: inspirelite_option( 'footer_column' ) == 'column_4' ){

				foreach( array( '1', '2', '3', '4' ) as $args ){

				    print '<div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 easetemplate-footer-block">';
				        if ( is_active_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ) ) {
				          dynamic_sidebar( sprintf( 'inspirelite-footer-v%1$s-widget', absint( $args ) ) ); 
				        }
				    print '</div>';
				}
			}
		}
    }

    /**
    *  Kicking this off by calling 'get_instance()' method
    */
    Inspirelite_Page_Footer::get_instance();
}
