import { DialogBody, Tab, Tabs } from '@blueprintjs/core';
import { yupResolver } from '@hookform/resolvers/yup';
import type { CSSProperties } from 'react';
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import * as Yup from 'yup';
import getAtomsFromMF from '../../../data/utilities/getAtomsFromMF.js';
import { useChartData } from '../../context/ChartContext.js';
import { useDispatch } from '../../context/DispatchContext.js';
import Button from '../../elements/Button.js';
import { Input2Controller } from '../../elements/Input2Controller.js';
import MoleculeSelection from '../../elements/MoleculeSelection.js';
import { StandardDialog } from '../../elements/StandardDialog.tsx';
function isValidMf(value: string): boolean {
try {
getAtomsFromMF(value);
return true;
} catch {
return false;
}
}
const validationSchema = Yup.object({
mf: Yup.string()
.required()
.test('valid-mf', 'Enter a valid molecular formula', (value) =>
isValidMf(value),
),
});
const styles: Record<'container' | 'input' | 'error' | 'title', CSSProperties> =
{
input: {
padding: '0.5rem',
},
container: {
padding: '0.5rem',
},
error: {
textAlign: 'center',
color: 'red',
fontSize: '0.9em',
},
title: {
textAlign: 'center',
},
};
interface InnerMolecularFormulaModalProps {
onClose: () => void;
}
interface MolecularFormulaModalProps extends InnerMolecularFormulaModalProps {
isOpen: boolean;
}
export function SetMolecularFormulaModal(props: MolecularFormulaModalProps) {
const { isOpen, ...otherProps } = props;
if (!isOpen) {
return;
}
return
Please type in a molecular formula!
You have to Select a spectrum and Add a molecule from the Structure panel to select as a reference!
); } return (Select a molecule as reference!