import React from 'react' import { createInterpolateElement } from '@wordpress/element' import { __, sprintf } from '@wordpress/i18n' import { Notice } from '../../common/Notice' import { ImportCard } from '../common/ImportCard' import { ImporterSelector } from './ImporterSelector' import { ImportOptions } from './ImportOptions' import { SimpleSnippetTable } from './SimpleSnippetTable' import { MigrationStep, WithMigrationData, useMigrationData } from './WithMigrationData' import { WithMigrationOptions, useMigrationOptions } from './WithMigrationOptions' import type { ReactNode } from 'react' interface StatusDisplayProps { type: 'error' | 'success' title: ReactNode children: ReactNode } const StatusDisplay: React.FC = ({ type, title, children }) =>

{title}

{children}

const StatusMessages: React.FC = () => { const { selectedImporter } = useMigrationOptions() const { error, isWorking, snippetSelection, importedIds } = useMigrationData() return ( <> {error?.step === MigrationStep.FetchSnippets && ( {error.message} )} {error?.step === MigrationStep.MigrateSnippets && ( {error.message} )} {0 < importedIds.length && ( // translators: %d: number of imported snippets. {createInterpolateElement( __('Selected snippets have been successfully imported to your Code Snippets library.', 'code-snippets'), { // eslint-disable-next-line jsx-a11y/anchor-has-content, jsx-a11y/control-has-associated-label a: } )} )} {selectedImporter && isWorking !== MigrationStep.FetchSnippets && error?.step !== MigrationStep.FetchSnippets && 0 === snippetSelection.availableItems.length && 0 === importedIds.length && (

{__('No snippets found', 'code-snippets')}

{__('No snippets were found for the selected plugin. Make sure the plugin is installed and has snippets configured.', 'code-snippets')}

)} ) } const MigrateFormInner: React.FC = () => { const { selectedImporter } = useMigrationOptions() const { isWorking, error, importers, snippetSelection, importSnippets, changeSelectedImporter } = useMigrationData() if (isWorking === MigrationStep.LoadImporters) { return

{__('Loading importers…', 'code-snippets')}

} if (error?.step === MigrationStep.LoadImporters) { return ( {/* translators: %s: error message. */}

{sprintf(__('Error loading importers: %s', 'code-snippets'), error.message)}

) } return ( <>

{__('If you are using another snippets plugin, you can import those existing snippets to your Code Snippets library.', 'code-snippets')}

changeSelectedImporter(value)} /> {0 < snippetSelection.availableItems.length && ( <> )} ) } export const MigrateForm: React.FC = () =>