<?php

if( ! function_exists( 'moment_wp_head' ) ) :

    /**
     * moment wp_head hook
     *
     * @since  moment 1.0.0
     */
    function moment_wp_head(){
      
        global $moment_customizer_all_values;
        global $moment_google_fonts;
        
        $moment_home_showcase_column = $moment_customizer_all_values['moment-home-showcase-column'];
        
        $moment_primary_color_option = $moment_customizer_all_values['moment-primary-color'];
        $moment_site_identity_color_option = $moment_customizer_all_values['moment-site-identity-color'];
        $moment_main_title_color_option = $moment_customizer_all_values['moment-main-title-color'];
        $moment_main_sub_title_color_option = $moment_customizer_all_values['moment-main-sub-title-color'];
        $moment_menu_color_option = $moment_customizer_all_values['moment-menu-color'];
        $moment_link_color_option = $moment_customizer_all_values['moment-link-color'];
        $moment_primary_hover_color_option = $moment_customizer_all_values['moment-primary-hover-color'];
        
        $moment_bg_breadcrumb_color_option = $moment_customizer_all_values['moment-bg-breadcrumb-color'];
        $moment_bg_letest_post_color_option = $moment_customizer_all_values['moment-bg-letest-post-color'];
        $moment_bg_footer_color_option = $moment_customizer_all_values['moment-bg-footer-color'];
        

        /*font settings*/
        $moment_font_family_primary_option = $moment_google_fonts[$moment_customizer_all_values['moment-font-family-Primary']];
        $moment_font_family_site_identity_option = $moment_google_fonts[$moment_customizer_all_values['moment-font-family-site-identity']];
        $moment_font_family_title_option = $moment_google_fonts[$moment_customizer_all_values['moment-font-family-title']];
        $moment_font_family_subtitle_option = $moment_google_fonts[$moment_customizer_all_values['moment-font-family-subtitle']];

        /*about section background image*/
        $moment_home_about_posts = salientthemes_customizer_get_repeated_all_value(1 , array('moment-about-pages-ids'));
        $moment_home_about_posts_ids = array();
        if (null != $moment_home_about_posts) {
            foreach ($moment_home_about_posts as $moment_home_about_post) {
                if (0 != $moment_home_about_post['moment-about-pages-ids']) {
                    $moment_home_about_posts_ids = $moment_home_about_post['moment-about-pages-ids'];
                }
            }
        }
        if (has_post_thumbnail($moment_home_about_posts_ids)){
            $moment_home_about_bg = wp_get_attachment_image_src( get_post_thumbnail_id($moment_home_about_posts_ids), 'full' );
        }  
        else{
            $moment_home_about_bg[0] = get_template_directory_uri()."/assets/img/about-bg.jpg";
        }
        /*end of about section*/
        ?>

        <style type="text/css">
        /*=====COLOR OPTION=====*/

        /*Color*/
        /*----------------------------------*/

        /*Primary*/
        <?php

        if( 3 == $moment_home_showcase_column ){
        ?>
          .element-item {
            width: 33.33%;
          }
        <?php
        }
        if( 4 == $moment_home_showcase_column ){
        ?>
        .element-item {
          width: 25%;
        }
        <?php
        }
        if( !empty($moment_primary_color_option) ){
        ?>
            section.wrapper-slider .slide-pager .cycle-pager-active,
            section.wrapper-slider .slide-pager .cycle-pager-active:visited,
            section.wrapper-slider .slide-pager .cycle-pager-active:hover,
            section.wrapper-slider .slide-pager .cycle-pager-active:focus,
            section.wrapper-slider .slide-pager .cycle-pager-active:active,
            .title-divider,
            .title-divider:visited,
            .block-overlay-hover,
            .block-overlay-hover:visited,
            .salientthemes-back-to-top,
            .salientthemes-back-to-top:visited,
            .search-form .search-submit,
            .search-form .search-submit:visited,
            .widget_calendar tbody a,
            .widget_calendar tbody a:visited{
              background-color: <?php echo esc_attr( $moment_primary_color_option );?>;
            }

            .widget-title,
            .widgettitle{
              border-color: <?php echo esc_attr( $moment_primary_color_option );?>; /*#2e5077*/
            }

            @media screen and (min-width: 768px){
            .main-navigation li:hover > a:after,
            .main-navigation .current_page_item > a:after,
            .main-navigation .current-menu-item > a:after,
            .main-navigation .current_page_ancestor > a:after,
            .main-navigation li.active > a:after,
            .main-navigation li.active > a:after,
            .main-navigation li.active > a:after,
            .main-navigation li.current_page_parent a:after,
            .wrapper-slider .slider-button,
            .about-button, .showcase-button, .btn {
                background-color: <?php echo esc_attr( $moment_primary_color_option );?>;
              }
            }

            .latestpost-footer .moredetail a,
            .latestpost-footer .moredetail a:visited{
              color: <?php echo esc_attr( $moment_primary_color_option );?>;
            }

            button,
            a.btn,
            html input[type="button"],
            input[type="button"],
            input[type="reset"],
            input[type="submit"],
            button:visited,
            a.btn:visited,
            input[type="button"]:visited,
            input[type="reset"]:visited,
            input[type="submit"]:visited,
            .search-section button.pageselect,
            .search-section button.pageselect:visited{
              color: <?php echo esc_attr( $moment_primary_color_option );?>;
            }
        <?php
        }         
        if( !empty($moment_site_identity_color_option) ){
        ?>
            /*Site identity / logo & tagline*/
            .site-title a,
            .site-title a:visited,
            .site-description {
              color: <?php echo esc_attr( $moment_site_identity_color_option );?>; /*#545C68*/
            }
        <?php
        } 
        if( !empty($moment_main_title_color_option) ){
        ?>
            /*Main Titile*/
            .title-section h2,
            .latestpost-content h3 a,
            .latestpost-content h3 a:visited{
              color: <?php echo esc_attr( $moment_main_title_color_option );?>;
            }
        <?php
        } 
        if( !empty($moment_main_sub_title_color_option) ){
        ?>
            /*Main Sub Titile*/
            .title-section h3{
              color: <?php echo esc_attr( $moment_main_sub_title_color_option );?>;
            }
        <?php
        } 
        if( !empty($moment_menu_color_option) ){
        ?>
            /*Menu*/
            .main-navigation a {
              color: <?php echo esc_attr( $moment_menu_color_option );?>;
            }
        <?php
        } 
        if( !empty($moment_link_color_option) ){
        ?>
            /*Link color*/
            .posted-on a,
            .cat-links a,
            .tags-links a,
            .author a,
            .comments-link a,
            .edit-link a,
            .nav-links .nav-previous a,
            .nav-links .nav-next a {
              color: <?php echo esc_attr( $moment_link_color_option );?>;
            }
        <?php
        } 
        if( !empty($moment_primary_hover_color_option) ){
        ?>
            /*Hover*/
            /*----------------------------------*/

            /*Primary hover*/
            a:hover,
              a:focus,
              a:active,
              h1 a:hover,
              h1 a:focus,
              h1 a:active,
              h2 a:hover,
              h2 a:focus,
              h2 a:active,
              h3 a:hover,
              h3 a:focus,
              h3 a:active,
              h4 a:hover,
              h4 a:focus,
              h4 a:active,
              h5 a:hover,
              h5 a:focus,
              h5 a:active,
              h6 a:hover,
              h6 a:focus,
              h6 a:active,
              .contact-widget ul li a:hover,
              .contact-widget ul li a:focus,
              .contact-widget ul li a:active,
              .contact-widget ul li a:hover i,
              .contact-widget ul li a:focus i,
              .contact-widget ul li a:active i,
              .site-title a:hover,
              .site-title a:focus,
              .site-title a:active,
              .main-navigation li:hover > a,
              .main-navigation li:focus > a,
              .main-navigation li:active > a,
              .main-navigation ul ul a:hover,
              .main-navigation ul ul a:focus,
              .main-navigation ul ul a:active,
              .wrapper-slider .slide-item .slider-title a:hover,
              .wrapper-slider .slide-item .slider-title a:focus,
              .wrapper-slider .slide-item .slider-title a:active,
              .latestpost-content h3 a:hover,
              .latestpost-content h3 a:focus,
              .latestpost-content h3 a:active,
              .latestpost-footer a:hover,
              .latestpost-footer a:focus,
              .latestpost-footer a:active,
              .latestpost-footer a:hover i,
              .latestpost-footer a:focus i,
              .latestpost-footer a:active i,
              .posted-on a:hover,
              .posted-on a:focus,
              .posted-on a:active,
              .cat-links a:hover,
              .cat-links a:focus,
              .cat-links a:active,
              .tags-links a:hover,
              .tags-links a:focus,
              .tags-links a:active,
              .author a:hover,
              .author a:focus,
              .author a:active,
              .comments-link a:hover,
              .comments-link a:focus,
              .comments-link a,
              .edit-link a:hover,
              .edit-link a:focus,
              .edit-link a:active,
              .nav-links .nav-previous a:hover,
              .nav-links .nav-previous a:focus,
              .nav-links .nav-previous a:active,
              .nav-links .nav-next a:hover,
              .nav-links .nav-next a:focus,
              .nav-links .nav-next a:active,
              .search-form .search-submit:hover,
              .search-form .search-submit:focus,
              .search-form .search-submit:active,
              .widget li a:hover,
              .widget li a:focus,
              .widget li a:active,
              .button.is-checked, 
              .button:hover,
              .site-info a:hover, 
              .site-info a:focus,
              .box .post-title > a:hover{
              color: <?php echo esc_attr( $moment_primary_hover_color_option );?>; /*#DFB200*/
            }

            .wrapper-slider .controls .slide-prev i:hover,
            .wrapper-slider .controls .slide-prev i:focus,
            .wrapper-slider .controls .slide-prev i:active,
            .wrapper-slider .controls .slide-next i:hover,
            .wrapper-slider .controls .slide-next i:focus,
            .wrapper-slider .controls .slide-next i:active,
            .search-section button.catselect:hover,
            .search-section button.catselect:focus,
            .search-section button.catselect:active,
            .search-section button.pageselect:hover,
            .search-section button.pageselect:focus,
            .search-section button.pageselect:active,
            .wrapper-slider .slide-pager span:hover,
            .wrapper-slider .slide-pager span:focus,
            .wrapper-slider .slide-pager span:active,
            .latestpost-footer .moredetail a:hover,
            .latestpost-footer .moredetail a:focus,
            .latestpost-footer .moredetail a:active,
            .latestpost:hover:after,
            .latestpost:focus:after,
            .latestpost:active:after,
            #gmaptoggle:hover,
            #gmaptoggle:focus,
            #gmaptoggle:active,
            .widget_calendar tbody a:hover,
            .widget_calendar tbody a:focus,
            .widget_calendar tbody a:active,
            .wrapper-slider .slider-button:hover,
            .about-button:hover, 
            .showcase-button:hover, 
            .btn:hover,
            .tagcloud a:hover, 
            .tagcloud a:active, 
            .tagcloud a:focus, 
            .tagcloud a.active, 
            .tagcloud .active{
              background-color: <?php echo esc_attr( $moment_primary_hover_color_option );?>; /*#DFB200*/
            }

            .wrapper-slider .controls .slide-prev i:hover,
            .wrapper-slider .controls .slide-prev i:focus,
            .wrapper-slider .controls .slide-prev i:active,
            .wrapper-slider .controls .slide-next i:hover,
            .wrapper-slider .controls .slide-next i:focus,
            .wrapper-slider .controls .slide-next i:active,
            .nav-links .nav-previous a:hover,
            .nav-links .nav-previous a:focus,
            .nav-links .nav-previous a:active,
            .nav-links .nav-next a:hover,
            .nav-links .nav-next a:focus,
            .nav-links .nav-next a:active{
              border-color: <?php echo esc_attr( $moment_primary_hover_color_option );?>;
            }

            /*Button standard*/
            button:hover,
            a.btn:hover,
            a.line-btn:hover,
            input[type="button"]:hover,
            input[type="reset"]:hover,
            input[type="submit"]:hover,
            button:focus,
            a.btn:focus,
            a.line-btn:focus,
            input[type="button"]:focus,
            input[type="reset"]:focus,
            input[type="submit"]:focus,
            button:active,
            a.btn:active,
            a.line-btn:active,
            input[type="button"]:active,
            input[type="reset"]:active,
            input[type="submit"]:active {
              background-color: <?php echo esc_attr( $moment_primary_hover_color_option );?>;
            }

            a.line-btn:hover,
            a.line-btn:focus,
            a.line-btn:active{
              border-color: <?php echo esc_attr( $moment_primary_hover_color_option );?>;
            }
        <?php
        } 
 
        if( !empty($moment_bg_breadcrumb_color_option) ){
        ?> 
              .wrap-breadcrumb{
                background-color: <?php echo esc_attr( $moment_bg_breadcrumb_color_option );?>; /*#1D3A5B*/
              }
        <?php
        }
        if( !empty($moment_bg_letest_post_color_option) ){
        ?> 
              /*blog*/
              .wrap-latestpost{
                background-color: <?php echo esc_attr( $moment_bg_letest_post_color_option );?>; /*#f1f1f1*/
              }
        <?php
        } 
        if( !empty($moment_bg_footer_color_option) ){
        ?> 
          /*footer*/
          .site-footer{
            background-color: <?php echo esc_attr( $moment_bg_footer_color_option );?>; /*#636B6B*/
          }

        <?php
        } 
        if( !empty($moment_font_family_primary_option) ){
        /*=====FONT FAMILY OPTION=====*/
        ?> 
        /*Primary*/
          html, body, p, button, input, select, textarea, pre, code, kbd, tt, var, samp , .main-navigation a, search-input-holder .search-field{
          font-family: '<?php echo esc_attr( $moment_font_family_primary_option ); ?>'; /*Lato*/
          }
        <?php
        } 

        if( !empty($moment_font_family_site_identity_option) ){
        ?> 
          /*Site identity / logo & tagline*/
          .site-title a, .site-description {
          font-family: '<?php echo esc_attr( $moment_font_family_site_identity_option ); ?>'; /*Lato*/
          }
        <?php
        } 
        if( !empty($moment_font_family_title_option) ){
        ?> 
          /*Title*/
          h1, h1 a,
          h2, h2 a,
          h3, h3 a,
          h4, h4 a,
          h5, h5 a,
          h6, h6 a{
            font-family: '<?php echo esc_attr( $moment_font_family_title_option ); ?>'; /*Lato*/
          }
        <?php
        } 
          if( !empty($moment_font_family_subtitle_option) ){
          ?>
          /*Subtitle*/
          .title-section h3 {
            font-family: Open+Sans:400,400italic,600,700; /*Cookie*/
          }
        <?php
        }
        /* about bg */
        if( !empty( $moment_home_about_bg) ){
        ?>
        .sub-wrapper {
            background-image: url(<?php echo esc_url($moment_home_about_bg[0]);?>);
        }
        .sub-wrapper.about-only{
          background-size: 100%;
        }

        .sub-wrapper.testimonial-only{
          background-image: none;
        }
        <?php
        }
        // Bail if not WP 4.7.
        if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
          $moment_custom_css = $moment_customizer_all_values['moment-custom-css']; 
          $moment_custom_css_output = ''; 
          if ( ! empty( $moment_custom_css ) ) { 
              $moment_custom_css_output .= esc_textarea( $moment_custom_css ) ; 
          } 
         echo $moment_custom_css_output;/*escaping done above*/ 
        } else {
            $moment_customizer_saved_values = moment_get_all_options();
            $moment_custom_css = $moment_customizer_all_values['moment-custom-css'];
            // Bail if there is no Custom CSS.
                if (!empty($moment_custom_css)) {
                    $core_css = wp_get_custom_css();
                    $return = wp_update_custom_css_post( $core_css . $moment_custom_css );
                    if ( ! is_wp_error( $return ) ) {
                    // Remove from theme.
                    $options = esc_textarea($moment_customizer_all_values['moment-custom-css']);
                    echo $options;
                    }
                }
            $moment_custom_css = '';
            $moment_customizer_saved_values['moment-custom-css'] = !empty ($moment_customizer_defaults['moment-custom-css']) ? $moment_customizer_defaults['moment-custom-css'] : '' ;
            /*resetting fields*/
            moment_reset_options( $moment_customizer_saved_values );
        }
        ?>

        </style>
    <?php
    }
endif;
add_action( 'wp_head', 'moment_wp_head' );