/**
 * Scripts within the customizer controls window.
 *
 * Contextually shows the navbar type setting and informs the preview
 * when users open or close the front page sections section.
 */
 



 ( function () {
	wp.customize.bind( 'ready', function () {		
		wp.customize( 'digital_newsticker_style', function ( setting ) {			
			//style one
		  function setupControl(controlName) {
                wp.customize.control(controlName, function (control) {
                    const visibility = function () {
                        if ('styleone' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }

            // List of controls to be handled
            const controls = [
                'digital_tickerbg',
                'digital_tickerlabelfont',
                'digital_tickerpostbg',
                'digital_tickerpostlink'
            ];

            // Setup each control
            controls.forEach(function (controlName) {
                setupControl(controlName);
            });
			
			
			
			 function setupControlTwo(controlNameTwo) {
                wp.customize.control(controlNameTwo, function (control) {
                    const visibility = function () {
                        if ('styletwo' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlstwo = [
                'digital_tickerbg_two',
                'digital_tickerlabelfont_two',
                'digital_tickerpostbg_two',
                'digital_tickerpostlink_two'
            ];

            // Setup each control
            controlstwo.forEach(function (controlNameTwo) {
                setupControlTwo(controlNameTwo);
            });
			//style two
			
			 function setupControlThree(controlNameThree) {
                wp.customize.control(controlNameThree, function (control) {
                    const visibility = function () {
                        if ('stylethree' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlsthree = [
                'digital_tickerbg_three',
                'digital_tickerlabelfont_three',
                'digital_tickerpostbg_three',
                'digital_tickerspeed_three',
                'digital_tickerpostlink_three'
            ];

            // Setup each control
            controlsthree.forEach(function (controlNameThree) {
                setupControlThree(controlNameThree);
            });
			//style three
		
					
		});			
		wp.customize('digital_posts_layout', function (setting) {
    function setupControlPoster(controlNamePoster) {
        wp.customize.control(controlNamePoster, function (control) {
            const visibility = function () {
                if ('poststylethree' === setting.get()) {
                    control.container.slideDown(180);
                } else {
                    control.container.slideUp(180);
                }
            };
            visibility();
            setting.bind(visibility);
        });
    }

    const controlsposter = [
        'digital_poststylethree_heading',
        'topcateid_hide',
        'topcateid',
        'cat_contlr_top',
        'cat_contlr_left',
        'cat_contlr_right',
        'leftcateid_hide',
        'leftcateid',
        'rightcateid_hide',
        'rightcateid',
    ];

    controlsposter.forEach(function (controlNamePoster) {
        setupControlPoster(controlNamePoster);
    });
});
       
		wp.customize( 'digital_header_style', function ( setting ) {			
			//style one
		  function setupControl(controlName) {
                wp.customize.control(controlName, function (control) {
                    const visibility = function () {
                        if ('styleone' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }

            // List of controls to be handled
            const controls = [
                'digital_topnavbgcolor',
                'digital_topnavhover',
                'digital_topnavtext',
                'digital_primarymenubg',
                'digital_primarymenubgs',
                'digital_primarymenutext',
                'digital_primarymenuhover',
                'digital_primarymenuhovertext'
            ];

            // Setup each control
            controls.forEach(function (controlName) {
                setupControl(controlName);
            });
			
			
			
			
			//style two
			  function setupControlTwo(controlNameTwo) {
                wp.customize.control(controlNameTwo, function (control) {
                    const visibility = function () {
                        if ('styletwo' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlstwo = [
                'digital_heroarea_links',
                'digital_heroarea_links_hover',
                'digital_heroarea',
                'digital_stickymenu',
            ];

            // Setup each control
            controlstwo.forEach(function (controlNameTwo) {
                setupControlTwo(controlNameTwo);
            });
			
			//style Three
			  function setupControlThree(controlNameThree) {
                wp.customize.control(controlNameThree, function (control) {
                    const visibility = function () {
                        if ('stylethree' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlsthree = [
                'digital_primarymenutext_three',
                'digital_topnavi_leftthree',
                'digital_topnavi_rightthree',
                'digital_primarymenutexthover_three',
                'digital_topnavibg_three',
                'digital_topnavi_enablethree',
                'digital_primarymenubg_three',
                'digital_topnavitext_three',
            ];

            // Setup each control
            controlsthree.forEach(function (controlNameThree) {
                setupControlThree(controlNameThree);
            });		


            	//style SIx
			  function setupControlSix(controlNameSix) {
                wp.customize.control(controlNameSix, function (control) {
                    const visibility = function () {
                        if ('stylesix' === setting.get()) {
                            control.container.slideDown(180);
                        } else {
                            control.container.slideUp(180);
                        }
                    };
                    visibility();
                    setting.bind(visibility);
                });
            }
			 // List of controls to be handled
            const controlssix = [
                'digital_primarymenubg_six',
                'digital_primarymenubghover_six',
                'digital_primarysubbghover_six',
                'digital_primarymenutext_six',
                'digital_topnavitext_six',
                'digital_topnavibg_six'
            ];

            // Setup each control
            controlssix.forEach(function (controlNameSix) {
                setupControlSix(controlNameSix);
            });	
					
		});			
	} );

    wp.customize( 'digital_carttotal', function( value ) {
        value.bind( function( newVal ) {
            if ( newVal === true ) {                   
                jQuery( '.woocommerce-Price-amount' ).css( 'display', 'inline' );
            } else {
                jQuery( '.woocommerce-Price-amount' ).css( 'display', 'none' );
            }
        });
    });

    wp.customize("digital_scroll_top_position", function(value) {
        value.bind(function(newVal) {
            if ( newVal === "left" ) {
                jQuery( "a.scrollup" ).css( { "right": "auto", "left": "0" } );
            } else if ( newVal === "right" ) {
                jQuery( "a.scrollup" ).css( { "left": "auto", "right": "0" } );
            }
        });
    });
    wp.customize( 'digital_footerbg', function( value ) {
		value.bind( function( footerWigbg ) {
			jQuery('#wrapper-footer-full').css('background-color', footerWigbg );
			jQuery('#wrapper-static-hero').css('background-color', footerWigbg );
		} );
	} );
    wp.customize( 'digital_footer_copy', function( value ) {
		value.bind( function( footerCopybg ) {
			jQuery('#wrapper-footer').css('background', footerCopybg );
		} );
	} );
    wp.customize( 'digital_pagenavi_current', function( value ) {
		value.bind( function( pagenavic ) {
			jQuery('span.page-link.current').css('background-color', pagenavic );
		} );
	} );  
	wp.customize( 'digital_pagenavi_bg', function( value ) {
		value.bind( function( pagenavibg ) {
			jQuery('a.page-link').css('background-color', pagenavibg );
		} );
	} );    
	wp.customize( 'digital_pagenavia_textcurrent', function( value ) {
		value.bind( function( pagenavitextc) {
			jQuery('span.page-link.current').css('color', pagenavitextc );
		} );
	} );    
	wp.customize( 'digital_pagenavia_text', function( value ) {
		value.bind( function( pagenavitext) {
			jQuery('a.page-link').css('color', pagenavitext );
		} );
	} );  
	wp.customize( 'digital_pagenavia_hover', function( value ) {
    value.bind( function( pagenavihover ) {
        jQuery('a.page-link').hover(function(){
            jQuery(this).css('background-color', pagenavihover);
        }, function(){
            var pagenavibg = wp.customize.value('digital_pagenav_bg')();
            jQuery(this).css('background-color', pagenavibg);
			});
		} );
	} );
    wp.customize( 'digital_scrolltop_radius ', function( value ) {
		value.bind( function( borderRadius ) {
			jQuery('a.scrollup.backtoup').css('border-radius', borderRadius + 'px');
		} );
	} );
    

} )( jQuery );