import { jsx, jsxs } from 'react/jsx-runtime'; import * as React from 'react'; import { Modal, Field, Textarea, Button } from '@strapi/design-system'; import { useIntl } from 'react-intl'; import { validateUrls } from '../../../utils/files.mjs'; import { getTranslationKey } from '../../../utils/translations.mjs'; const ImportFromUrlDialog = ({ open, onClose, onUpload })=>{ const { formatMessage } = useIntl(); const [urls, setUrls] = React.useState(''); const [error, setError] = React.useState(null); const handleClose = ()=>{ setUrls(''); setError(null); onClose(); }; const handleSubmit = async (e)=>{ e.preventDefault(); // Validate URLs const { urls: validUrls, error: validationError } = validateUrls(urls); if (validationError) { setError(validationError); return; } setError(null); // Close dialog and let the mutation handle fetching and uploading handleClose(); // Pass URLs to mutation which handles fetching and upload progress await onUpload(validUrls); }; return /*#__PURE__*/ jsx(Modal.Root, { open: open, onOpenChange: (isOpen)=>!isOpen && handleClose(), children: /*#__PURE__*/ jsx(Modal.Content, { children: /*#__PURE__*/ jsxs("form", { onSubmit: handleSubmit, children: [ /*#__PURE__*/ jsx(Modal.Header, { children: /*#__PURE__*/ jsx(Modal.Title, { children: formatMessage({ id: getTranslationKey('modal.url.title'), defaultMessage: 'Import from URL' }) }) }), /*#__PURE__*/ jsx(Modal.Body, { children: /*#__PURE__*/ jsxs(Field.Root, { error: error || undefined, hint: formatMessage({ id: getTranslationKey('input.url.description'), defaultMessage: 'Separate your URL links by a carriage return.' }), children: [ /*#__PURE__*/ jsx(Field.Label, { children: formatMessage({ id: getTranslationKey('input.url.label'), defaultMessage: 'URL(s)' }) }), /*#__PURE__*/ jsx(Textarea, { name: "urls", minHeight: "unset", rows: Math.min(urls.split('\n').length, 7), maxHeight: "10.5rem", placeholder: formatMessage({ id: getTranslationKey('input.url.placeholder'), defaultMessage: 'Empty' }), value: urls, onChange: (e)=>{ setUrls(e.target.value); setError(null); } }), /*#__PURE__*/ jsx(Field.Hint, {}), /*#__PURE__*/ jsx(Field.Error, {}) ] }) }), /*#__PURE__*/ jsxs(Modal.Footer, { children: [ /*#__PURE__*/ jsx(Button, { variant: "tertiary", onClick: handleClose, children: formatMessage({ id: 'app.components.Button.cancel', defaultMessage: 'Cancel' }) }), /*#__PURE__*/ jsx(Button, { type: "submit", children: formatMessage({ id: getTranslationKey('modal.url.upload'), defaultMessage: 'Upload' }) }) ] }) ] }) }) }); }; export { ImportFromUrlDialog }; //# sourceMappingURL=ImportFromUrlDialog.mjs.map