import type { BaselineCorrectionZone } from '@zakodium/nmr-types';
import { useChartData } from '../../context/ChartContext.js';
import { useDispatch } from '../../context/DispatchContext.js';
import { useScaleChecked } from '../../context/ScaleContext.js';
import { ResizerWithScale } from '../../elements/ResizerWithScale.js';
import type { Position } from '../../elements/resizer/SVGResizer.js';
import { useHighlight } from '../../highlight/index.js';
import { useResizerStatus } from '../../hooks/useResizerStatus.js';
import { useIsInset } from '../inset/InsetProvider.js';
function BaseLineZones() {
const {
toolOptions: {
selectedTool,
data: { baselineCorrection },
},
} = useChartData();
const isInset = useIsInset();
if (isInset) return null;
const baseLineZones = baselineCorrection.zones;
if (selectedTool !== 'baselineCorrection' || baseLineZones.length === 0) {
return null;
}
return (
{baselineCorrection.zones.map((zone) => (
))}
);
}
function BaseLineZone(props: BaselineCorrectionZone) {
const { from, to, id } = props;
const {
onHover,
isActive,
defaultActiveStyle: { backgroundColor: activeFill },
} = useHighlight([id], { type: 'BASELINE_ZONE', extra: { id } });
const { scaleX } = useScaleChecked();
const dispatch = useDispatch();
function handleOnStopResizing(position: Position) {
dispatch({
type: 'RESIZE_BASE_LINE_ZONE',
payload: {
id,
from: scaleX().invert(position.x2),
to: scaleX().invert(position.x1),
},
});
}
const isResizingActive = useResizerStatus('baselineCorrection');
return (
{({ x1, x2 }, isResizeActive) => {
return (
);
}}
);
}
export default BaseLineZones;