import { useAppSelector } from '@/app/hooks' import { extractEventBaseUuid } from '@/utils/extractEventBaseUuid' import { Box, Button, FormControl, InputLabel, MenuItem, Select, TextField, Typography } from '@linagora/twake-mui' import { useEffect, useState } from 'react' import { useI18n } from 'twake-i18n' import { CalendarItemList } from './CalendarItemList' import { SettingsTab } from './SettingsTab' export function ImportTab({ userId, importTarget, setImportTarget, setImportedContent, newCalParams }: { userId: string importTarget: string setImportTarget: (target: string) => void setImportedContent: (content: File | null) => void newCalParams: { name: string setName: (name: string) => void description: string setDescription: (d: string) => void color: Record setColor: (color: Record) => void visibility: 'public' | 'private' setVisibility: (visibility: 'public' | 'private') => void } }) { const { t } = useI18n() const [importMode] = useState<'file' | 'url'>('file') const [importFile, setImportFile] = useState(null) const [importUrl, setImportUrl] = useState('') const calendars = useAppSelector(state => state.calendars.list) const personalCalendars = Object.values(calendars).filter( cal => extractEventBaseUuid(cal.id) === userId ) useEffect(() => { setImportedContent(importMode === 'file' ? importFile : null) }, [importFile, importUrl, importMode, setImportedContent]) return ( <> {/* Form group 1: Select file button - first group, margin top 0 */} {importMode === 'file' && ( {importFile && ( {importFile.name} )} {t('calendar.import_file_description')} )} {/* Form group 2: URL field */} {importMode === 'url' && ( setImportUrl(e.target.value)} size="small" margin="dense" sx={{ '&.MuiFormControl-root.MuiFormControl-marginDense': { marginTop: '6px', marginBottom: 0 } }} /> )} {/* Form group 3: Import to */} {t('calendar.import_to')} {/* Form group 4: SettingsTab (when importing to new calendar) */} {importTarget === 'new' && ( )} ) }