import React, { useState, useEffect } from 'react' function ModalData({ modalData, onClose, onSave }) { const [inputValue, setInputValue] = useState('') const [fromType, setFromType] = useState('INT') const [toType, setToType] = useState('REAL') useEffect(() => { setInputValue('') setFromType('INT') setToType('REAL') }, [modalData]) if (!modalData) return null function getTypeValue() { const value = inputValue.toLowerCase().trim() const timeRegex = /^(t|time)#(-)?\d+(d|h|m|s|ms)(\d+(d|h|m|s|ms))*/ const realRegex = /^-?\d+\.\d+$/ const intRegex = /^-?\d+$/ if (value === 'true' || value === 'false') return 'BOOL' if (timeRegex.test(value)) return 'TIME' if (value.startsWith("'") && value.endsWith("'")) return 'STRING' if (realRegex.test(value)) return 'REAL' if (intRegex.test(value)) { const num = Number(value) if (num >= -32768 && num <= 32767) return 'INT' if (num >= -2147483648 && num <= 2147483647) return 'DINT' } return null } function handleConfirm() { const trimmed = inputValue.trim() if (modalData.type === 'const') { if (trimmed === '') { alert('Переменная пуста') return } } else if (trimmed === '' && (modalData.type === 'input' || modalData.type === 'output')) { alert('Не заданно имя переменной') return } if (modalData.type === 'const') { const getedType = getTypeValue() if (!getedType) { alert('Не удалось получить тип переменной (не корректный ввод)') return } onSave({ value: trimmed, fromType: getedType, toType: getedType }) return } onSave({ value: trimmed, fromType, toType }) } function getWindowWithType() { const types = ["BOOL", "INT", "DINT", "REAL", "STRING", "TIME"] switch(modalData.type) { case 'switch_type': return(