/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Icon, wordpress } from '@wordpress/icons';
import { getSetting } from '@woocommerce/wc-admin-settings';
import { useSelect } from '@wordpress/data';
import { useEffect } from 'react';
import classnames from 'classnames';
import { debounce } from 'lodash';
/**
* Internal dependencies
*/
import useIsScrolled from '../../../hooks/useIsScrolled';
const Header = () => {
const siteTitle = getSetting( 'siteTitle', '' );
const siteUrl = getSetting( 'siteUrl', '' );
const isScrolled = useIsScrolled();
const navClasses = {
folded: 'is-wc-nav-folded',
expanded: 'is-wc-nav-expanded',
};
const foldNav = () => {
document.body.classList.add( navClasses.folded );
document.body.classList.remove( navClasses.expanded );
};
const expandNav = () => {
document.body.classList.remove( navClasses.folded );
document.body.classList.add( navClasses.expanded );
};
const toggleFolded = () => {
if ( document.body.classList.contains( navClasses.folded ) ) {
expandNav();
} else {
foldNav();
}
};
const foldOnMobile = ( screenWidth = document.body.clientWidth ) => {
if ( screenWidth <= 960 ) {
foldNav();
} else {
expandNav();
}
};
useEffect( () => {
foldOnMobile();
const foldEvents = [
{
eventName: 'orientationchange',
handler: ( e ) => foldOnMobile( e.target.screen.availWidth ),
},
{
eventName: 'resize',
handler: debounce( () => foldOnMobile(), 200 ),
},
];
for ( const { eventName, handler } of foldEvents ) {
window.addEventListener( eventName, handler, false );
}
}, [] );
let buttonIcon =