import { triggerSegmentationDataModified } from '../../../../stateManagement/segmentation/triggerSegmentationEvents';
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
import IslandRemoval from '../../../../utilities/segmentation/islandRemoval';
export default {
    [StrategyCallbacks.OnInteractionEnd]: (operationData) => {
        const { previewSegmentIndex, segmentIndex, viewport, previewVoxelManager, segmentationVoxelManager, activeStrategy, } = operationData;
        if (activeStrategy !== 'THRESHOLD_INSIDE_SPHERE_WITH_ISLAND_REMOVAL' ||
            segmentIndex === null) {
            return;
        }
        const islandRemoval = new IslandRemoval();
        const voxelManager = previewVoxelManager ?? segmentationVoxelManager;
        if (!islandRemoval.initialize(viewport, voxelManager, {
            previewSegmentIndex,
            segmentIndex,
        })) {
            return;
        }
        islandRemoval.floodFillSegmentIsland();
        islandRemoval.removeExternalIslands();
        islandRemoval.removeInternalIslands();
        const arrayOfSlices = voxelManager.getArrayOfModifiedSlices();
        if (!arrayOfSlices) {
            return;
        }
        triggerSegmentationDataModified(operationData.segmentationId, arrayOfSlices, previewSegmentIndex);
    },
};
