import React, { useEffect } from 'react';
import { BluetoothState, BluetoothContextType } from '@widergy/sfp-mobile-toolbox';
import GeneralStep from '../GeneralStep';

interface Props {
  sourceImage?: any;
  title: string;
  description?: string;
  bluetoothContext: BluetoothContextType;
  instantNextStep?: Function;
  children?: any;
  buttons?: Array<object>;
}

const StepProbeLinkage = ({
  sourceImage,
  title,
  description,
  bluetoothContext,
  instantNextStep,
  children,
  buttons,
}: Props) => {
  useEffect(() => {
    if (bluetoothContext?.bluetoothState === BluetoothState.IDLE && !bluetoothContext.scanError) {
      instantNextStep && instantNextStep();
    }
  }, [
    bluetoothContext?.bluetoothState,
    bluetoothContext.scanError,
    bluetoothContext.scannedDevices,
    instantNextStep,
  ]);
  return (
    <GeneralStep
      title={title}
      description={description}
      sourceImage={sourceImage}
      buttons={buttons}
      children={children}
    />
  );
};
export default StepProbeLinkage;
