/**
 * PageSpeed Insights module initialization.
 *
 * Site Kit by Google, Copyright 2021 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 { __ } from '@wordpress/i18n';

/**
 * Internal dependencies
 */
import {
	AREA_DASHBOARD_SPEED,
	AREA_ENTITY_DASHBOARD_SPEED_PRIMARY,
	AREA_MAIN_DASHBOARD_SPEED_PRIMARY,
	AREA_PAGE_DASHBOARD_SPEED,
} from '../../googlesitekit/widgets/default-areas';
import { SettingsView } from './components/settings';
import DashboardPageSpeedWidget from './components/dashboard/DashboardPageSpeedWidget';
import PageSpeedInsightsIcon from '../../../svg/graphics/pagespeed-insights.svg';
import { MODULES_PAGESPEED_INSIGHTS } from './datastore/constants';
import { isFeatureEnabled } from '../../features';

export { registerStore } from './datastore';

export const registerModule = ( modules ) => {
	modules.registerModule( 'pagespeed-insights', {
		storeName: MODULES_PAGESPEED_INSIGHTS,
		SettingsViewComponent: SettingsView,
		Icon: PageSpeedInsightsIcon,
		features: [
			__(
				'Website performance reports for mobile and desktop',
				'google-site-kit'
			),
		],
	} );
};

export const registerWidgets = ( widgets ) => {
	if ( ! isFeatureEnabled( 'unifiedDashboard' ) ) {
		widgets.registerWidget(
			'pagespeedInsightsWebVitals',
			{
				Component: DashboardPageSpeedWidget,
				width: widgets.WIDGET_WIDTHS.FULL,
				wrapWidget: false,
			},
			[ AREA_DASHBOARD_SPEED, AREA_PAGE_DASHBOARD_SPEED ]
		);
	}

	if ( isFeatureEnabled( 'unifiedDashboard' ) ) {
		widgets.registerWidget(
			'pagespeedInsightsWebVitals',
			{
				Component: DashboardPageSpeedWidget,
				width: widgets.WIDGET_WIDTHS.FULL,
				wrapWidget: false,
			},
			[
				AREA_MAIN_DASHBOARD_SPEED_PRIMARY,
				AREA_ENTITY_DASHBOARD_SPEED_PRIMARY,
			]
		);
	}
};

@@ -1927,32 +1927,71 @@
 pWidget: false,%0A
+%09%09%09%09modules: %5B 'pagespeed-insights' %5D,%0A
 %09%09%09%7D,%0A%09%09%09%5B AREA_
@@ -2260,16 +2260,55 @@
  false,%0A
+%09%09%09%09modules: %5B 'pagespeed-insights' %5D,%0A
 %09%09%09%7D,%0A%09%09

Declare associated modules for 'pagespeed-insights'.