2025-09-05 15:36:29 +01:00
|
|
|
import { useState, useEffect } from 'react';
|
2025-09-05 16:09:49 +01:00
|
|
|
import classes from './bulkSelectionPanel/BulkSelectionPanel.module.css';
|
2025-09-05 15:36:29 +01:00
|
|
|
import { parseSelectionWithDiagnostics } from '../../utils/bulkselection/parseSelection';
|
2025-09-05 16:09:49 +01:00
|
|
|
import PageSelectionInput from './bulkSelectionPanel/PageSelectionInput';
|
|
|
|
import SelectedPagesDisplay from './bulkSelectionPanel/SelectedPagesDisplay';
|
|
|
|
import AdvancedSelectionPanel from './bulkSelectionPanel/AdvancedSelectionPanel';
|
2025-06-20 17:51:24 +01:00
|
|
|
|
|
|
|
interface BulkSelectionPanelProps {
|
|
|
|
csvInput: string;
|
|
|
|
setCsvInput: (value: string) => void;
|
2025-08-26 17:26:30 +01:00
|
|
|
selectedPageIds: string[];
|
|
|
|
displayDocument?: { pages: { id: string; pageNumber: number }[] };
|
2025-09-05 00:54:21 +01:00
|
|
|
onUpdatePagesFromCSV: (override?: string) => void;
|
2025-06-20 17:51:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const BulkSelectionPanel = ({
|
|
|
|
csvInput,
|
|
|
|
setCsvInput,
|
2025-08-26 17:26:30 +01:00
|
|
|
selectedPageIds,
|
|
|
|
displayDocument,
|
2025-06-20 17:51:24 +01:00
|
|
|
onUpdatePagesFromCSV,
|
|
|
|
}: BulkSelectionPanelProps) => {
|
2025-09-05 15:36:29 +01:00
|
|
|
const [syntaxError, setSyntaxError] = useState<string | null>(null);
|
2025-09-05 00:54:21 +01:00
|
|
|
const maxPages = displayDocument?.pages?.length ?? 0;
|
|
|
|
|
|
|
|
|
2025-09-05 15:36:29 +01:00
|
|
|
// Validate input syntax and show lightweight feedback
|
|
|
|
useEffect(() => {
|
|
|
|
const text = (csvInput || '').trim();
|
|
|
|
if (!text) {
|
|
|
|
setSyntaxError(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const { warning } = parseSelectionWithDiagnostics(text, maxPages);
|
|
|
|
setSyntaxError(warning ? 'There is a syntax issue. See Page Selection tips for help.' : null);
|
|
|
|
} catch {
|
|
|
|
setSyntaxError('There is a syntax issue. See Page Selection tips for help.');
|
|
|
|
}
|
|
|
|
}, [csvInput, maxPages]);
|
|
|
|
|
2025-09-05 16:09:49 +01:00
|
|
|
const handleClear = () => {
|
2025-09-05 00:54:21 +01:00
|
|
|
setCsvInput('');
|
2025-09-05 16:37:10 +01:00
|
|
|
onUpdatePagesFromCSV('');
|
2025-09-05 00:54:21 +01:00
|
|
|
};
|
|
|
|
|
2025-06-20 17:51:24 +01:00
|
|
|
return (
|
2025-09-05 15:36:29 +01:00
|
|
|
<div className={classes.panelContainer}>
|
2025-09-05 16:09:49 +01:00
|
|
|
<PageSelectionInput
|
|
|
|
csvInput={csvInput}
|
|
|
|
setCsvInput={setCsvInput}
|
|
|
|
onUpdatePagesFromCSV={onUpdatePagesFromCSV}
|
|
|
|
onClear={handleClear}
|
|
|
|
/>
|
2025-09-05 00:54:21 +01:00
|
|
|
|
2025-09-05 16:09:49 +01:00
|
|
|
<SelectedPagesDisplay
|
|
|
|
selectedPageIds={selectedPageIds}
|
|
|
|
displayDocument={displayDocument}
|
|
|
|
syntaxError={syntaxError}
|
|
|
|
/>
|
2025-09-05 00:54:21 +01:00
|
|
|
|
2025-09-05 16:09:49 +01:00
|
|
|
<AdvancedSelectionPanel
|
|
|
|
csvInput={csvInput}
|
|
|
|
setCsvInput={setCsvInput}
|
|
|
|
onUpdatePagesFromCSV={onUpdatePagesFromCSV}
|
|
|
|
maxPages={maxPages}
|
|
|
|
/>
|
|
|
|
</div>
|
2025-06-20 17:51:24 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default BulkSelectionPanel;
|