import React, { useState } from 'react' import { __ } from '@wordpress/i18n' import { ImporterSelector, ImportOptions, SimpleSnippetTable, StatusDisplay } from './components' import { ImportCard } from '../shared' import { useImporterSelection, useSnippetImport, useImportSnippetSelection } from './hooks' export const ImportForm: React.FC = () => { const [autoAddTags, setAutoAddTags] = useState(false) const importerSelection = useImporterSelection() const snippetImport = useSnippetImport() const snippetSelection = useImportSnippetSelection(snippetImport.snippets) const handleImporterChange = async (newImporter: string) => { importerSelection.handleImporterChange(newImporter) snippetSelection.clearSelection() snippetImport.resetAll() if (newImporter) { await snippetImport.loadSnippets(newImporter) } } const handleImport = async () => { const selectedIds = Array.from(snippetSelection.selectedSnippets) const success = await snippetImport.importSnippets( importerSelection.selectedImporter, selectedIds, autoAddTags, importerSelection.tagValue ) if (success) { snippetSelection.clearSelection() } } if (importerSelection.isLoading) { return (

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

) } if (importerSelection.error) { return (

{__('Error loading importers:', 'code-snippets')} {importerSelection.error}

) } return (

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

{snippetImport.snippetsError && ( )} {snippetImport.importError && ( )} {snippetImport.importSuccess.length > 0 && ( )} {importerSelection.selectedImporter && !snippetImport.isLoadingSnippets && !snippetImport.snippetsError && snippetImport.snippets.length === 0 && snippetImport.importSuccess.length === 0 && (
📭

{__('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')}

)} {snippetImport.snippets.length > 0 && ( <> )}
) }