import React, { useRef, useState } from 'react' import { Title, Text, Button, Anchor, Slider, Switch, Divider, Stack, Box, Loader, Select, NumberInput, Badge, Alert, Group, } from '@mantine/core' import { IconCloudUpload, IconChartBar, IconAlertCircle } from '@tabler/icons-react' import { useXRD } from '../context/XRDContext' import ExampleDataPanel from './ExampleDataPanel' const Controls = () => { const { rawData, isLoading, detectedWavelength, userWavelength, setUserWavelength, wavelengthSource, dataWarnings, baselineCorrection, setBaselineCorrection, interpolationEnabled, setInterpolationEnabled, scalingEnabled, setScalingEnabled, interpolationStrategy, setInterpolationStrategy, handleFileUpload, runInference, MODEL_WAVELENGTH, MODEL_MIN_2THETA, MODEL_MAX_2THETA, } = useXRD() const fileInputRef = useRef(null) const [showExamples, setShowExamples] = useState(true) const handleFileChange = async (event) => { const file = event.target.files?.[0] if (file) { const success = await handleFileUpload(file) if (success) setShowExamples(false) // Reset file input so the same file can be uploaded again if (fileInputRef.current) { fileInputRef.current.value = '' } } } const handleUploadClick = () => { fileInputRef.current?.click() } return ( {/* File Upload */} Formats: .xy, .cif, .dif setShowExamples((v) => !v)} > {showExamples ? 'Hide samples' : 'Try samples'} {showExamples && setShowExamples(false)} />} {rawData && ( <> {/* Data Info */} Data Points: {rawData.x.length} Range: {Math.min(...rawData.x).toFixed(2)}° - {Math.max(...rawData.x).toFixed(2)}° {/* Warnings */} {dataWarnings.length > 0 && ( } color="yellow" variant="light"> {dataWarnings.map((warning, idx) => ( {warning} ))} )} {/* Wavelength Configuration */} Wavelength {detectedWavelength && ( Detected: {detectedWavelength.toFixed(4)} Å )} setUserWavelength(value || MODEL_WAVELENGTH)} min={0.1} max={3.0} step={0.0001} precision={4} size="sm" decimalScale={4} /> Training Data Specs: • λ: {MODEL_WAVELENGTH} Å (20 keV)
• 2θ: {MODEL_MIN_2THETA}°-{MODEL_MAX_2THETA}° (8192 pts)
• Intensity: 0-100 scaled
{/* Preprocessing Controls */} Preprocessing setBaselineCorrection(event.currentTarget.checked)} /> setScalingEnabled(event.currentTarget.checked)} />