/**
 * PageSpeed Insights module initialization.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * WordPress dependencies
 */
import { addFilter } from '@wordpress/hooks';
import domReady from '@wordpress/dom-ready';

/**
 * Internal dependencies
 */
import './datastore';
import { getModulesData, fillFilterWithComponent, createAddToFilter } from '../../util';
import { WIDGET_WIDTHS } from '../../googlesitekit/widgets/datastore/constants';
import { AREA_DASHBOARD_SPEED, AREA_PAGE_DASHBOARD_SPEED } from '../../googlesitekit/widgets/default-areas';
import { SettingsMain as PageSpeedInsightsSettings } from './settings';
import DashboardSpeed from './dashboard/dashboard-widget-speed';
import DashboardPageSpeedWidget from './components/DashboardPageSpeedWidget';

/**
 * Add components to the settings page.
 */
addFilter(
	'googlesitekit.ModuleSettingsDetails-pagespeed-insights',
	'googlesitekit.PageSpeedInsightsModuleSettingsDetails',
	fillFilterWithComponent( PageSpeedInsightsSettings )
);

const {
	active,
	setupComplete,
} = getModulesData()[ 'pagespeed-insights' ];

if ( active && setupComplete ) {
	// Add to main dashboard.
	addFilter(
		'googlesitekit.DashboardModule',
		'googlesitekit.PageSpeedInsights',
		createAddToFilter( <DashboardSpeed /> ),
		45
	);
	// Add to dashboard-details view.
	addFilter(
		'googlesitekit.DashboardDetailsModule',
		'googlesitekit.PageSpeedInsights',
		createAddToFilter( <DashboardSpeed /> ),
		45
	);
}

domReady( () => {
	global.googlesitekit.widgets.registerWidget( 'pagespeedInsightsWebVitals', {
		component: DashboardPageSpeedWidget,
		width: WIDGET_WIDTHS.FULL,
		wrapWidget: false,
	}, [ AREA_DASHBOARD_SPEED, AREA_PAGE_DASHBOARD_SPEED ] );
} );

@@ -851,24 +851,8 @@
 rt %7B
- getModulesData,
  fil
@@ -875,27 +875,8 @@
 nent
-, createAddToFilter
  %7D f
@@ -1159,73 +1159,8 @@
 s';%0A
-import DashboardSpeed from './dashboard/dashboard-widget-speed';%0A
 impo
@@ -1467,469 +1467,12 @@
 s )%0A
+
 );%0A%0A
-const %7B%0A%09active,%0A%09setupComplete,%0A%7D = getModulesData()%5B 'pagespeed-insights' %5D;%0A%0Aif ( active && setupComplete ) %7B%0A%09// Add to main dashboard.%0A%09addFilter(%0A%09%09'googlesitekit.DashboardModule',%0A%09%09'googlesitekit.PageSpeedInsights',%0A%09%09createAddToFilter( %3CDashboardSpeed /%3E ),%0A%09%0945%0A%09);%0A%09// Add to dashboard-details view.%0A%09addFilter(%0A%09%09'googlesitekit.DashboardDetailsModule',%0A%09%09'googlesitekit.PageSpeedInsights',%0A%09%09createAddToFilter( %3CDashboardSpeed /%3E ),%0A%09%0945%0A%09);%0A%7D%0A%0A
 domR

Remove legacy filters.