/**
* WordPress dependencies.
*/
import { Button, Flex, FlexItem, Notice, Panel, PanelBody, TabPanel } from '@wordpress/components';
import { useMemo, useState, WPElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies.
*/
import { useSettingsScreen } from '../../settings-screen';
import { syncUrl } from '../config';
import { useFeatureSettings } from '../provider';
import Feature from '../components/feature';
import Tab from '../components/tab';
/**
* Styles.
*/
import '../style.css';
/**
* Feature settings dashboard app.
*
* @returns {WPElement} Reports component.
*/
export default () => {
const { createNotice } = useSettingsScreen();
const {
features,
isBusy,
isModified,
isSyncing,
isSyncRequired,
resetSettings,
saveSettings,
setIsSyncing,
} = useFeatureSettings();
/**
* URL to start a sync.
*/
const syncNowUrl = useMemo(() => {
const url = new URL(syncUrl);
url.searchParams.append('do_sync', 'features');
return url.toString();
}, []);
/**
* Generic error notice.
*/
const errorNotice = __('Could not save feature settings. Please try again.', 'elasticpress');
/**
* Action when a sync is in progress
*/
const isSyncingActions = [
{
url: syncUrl,
label: __('View sync status', 'elasticpress'),
},
];
/**
* Notice when a sync is in progress.
*/
const isSyncingNotice = __('Cannot save settings while a sync is in progress.', 'elasticpress');
/**
* Reset notice.
*/
const resetNotice = __('Changes to feature settings discarded.', 'elasticpress');
/**
* Action when syncing later.
*/
const syncLaterActions = [
{
url: syncNowUrl,
label: __('Sync', 'elasticpress'),
},
];
/**
* Prompt when syncing later.
*/
const syncLaterConfirm = __(
'If you choose to sync later some settings changes may not take effect until the sync is performed. Save and sync later?',
'elasticpress',
);
/**
* Prompt when syncing now.
*/
const syncNowConfirm = __(
'Saving these settings will begin re-syncing your content. Save and sync now?',
'elasticpress',
);
/**
* Notice when syncing now.
*/
const syncNowNotice = __('Feature settings saved. Starting sync…', 'elasticpress');
/**
* Success notice.
*/
const successNotice = __('Feature settings saved.', 'elasticpress');
/**
* Whether the user has chosen to sync later when saving. Used to show the
* busy state on the correct button.
*/
const [willSyncLater, setWillSyncLater] = useState(false);
/**
* Feature settings tabs.
*/
const tabs = features
.filter((f) => f.isVisible)
.map((f) => {
return {
name: f.slug,
title: