'use client'; import React, { useEffect, useState } from 'react'; import { Button, Checkbox, CheckboxGroup, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, Textarea } from '@nextui-org/react'; import { toast } from 'react-toastify'; import { HiOutlineDownload, HiOutlineDuplicate } from 'react-icons/hi'; const workflows = new Map string>([ [ 'minify', (json) => { try { const value = JSON.parse(json); return JSON.stringify(value); } catch (e) { toast.error(`Operation Failed: ${ e }`, { autoClose: 5000 }); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-expect-error return e.toString(); } } ] ]); type Props = { isOpen: boolean, onOpenChange: () => void, value: string }; const ExportModal = ({ isOpen, onOpenChange, value }: Props) => { const [ workflow, setWorkflow ] = useState([]); const [ editorValue, setEditorValue ] = useState(value); useEffect(() => { setEditorValue(value); }, [ value ]); const [ exportValue, setExportValue ] = useState(editorValue); useEffect(() => { let value = editorValue; for (const fn of workflow) { const func = workflows.get(fn); value = func ? func(value) : value; } setExportValue(value); }, [ workflow, editorValue ]); return ( { (onClose) => ( <> Export Minify