/**
 * [getLocalStorageData description]
 * @return {[type]} [description]
 */
export function getLocalStorageData( _key = false, _default = false ) {
    try {
        let diviViewsWizardData = JSON.parse( window.localStorage.getItem( 'diviViewsWizardData' ) );

        if ( _key ) {

            if ( diviViewsWizardData.hasOwnProperty( _key ) ) {
                return diviViewsWizardData[ _key ];
            } else {
                return _default;
            }
        }

        return diviViewsWizardData;
    } catch ( e ) {
        return _default;
    }
}

/**
 * Set localStorage data.
 *
 * @return {object|boolean}
 */
export function setLocalStorageData( key, data ) {
    let diviViewsWizardData = getLocalStorageData() || {};

    diviViewsWizardData[ key ] = data;

    window.localStorage.setItem( 'diviViewsWizardData', JSON.stringify( diviViewsWizardData ) );
}

/**
 *
 * @param currentStep
 */
export function updateUrlStep( currentStep ) {
    const url = new URL( window.location.href );

    url.searchParams.set('current-step', currentStep);
    window.history.replaceState({}, '', url);
}
