import { Steps } from '@incode/ui';
import { emptyFunc, useSteps } from '@incode/utils';

import DocumentSelector from '@incodetech/welcome/documentSelector/DocumentSelector';
import FrontId from '@incodetech/welcome/camera/CaptureFrontId';
import BackId from '@incodetech/welcome/camera/CaptureBackId';
import { NotificationProvider } from '@incodetech/welcome/camera/Notification';
import type { WorkflowNode } from './types';

type IDCaptureProps = {
  config: WorkflowNode['moduleConfiguration'];
  token: string;
  onNext: () => void;
};
const IDCapture = ({ config, token, onNext }: IDCaptureProps) => {
  const { nextStep, currentStep, setStep } = useSteps();

  return (
    <NotificationProvider initialValue={{ isOpen: false }}>
      <Steps currentStep={currentStep}>
        <DocumentSelector goNext={nextStep} onSourceChange={() => setStep(3)} />
        <FrontId
          onLog={emptyFunc}
          showTutorial={config.showTutorial}
          numberOfTries={config.captureAttempts}
          token={{ token }}
          onError={onNext}
          onSuccess={nextStep}
        />
        <BackId
          onLog={emptyFunc}
          showTutorial={config.showTutorial}
          numberOfTries={config.captureAttempts}
          token={{ token }}
          onError={onNext}
          onSuccess={onNext}
        />
        <FrontId
          onLog={emptyFunc}
          showTutorial={config.showTutorial}
          numberOfTries={config.captureAttempts}
          token={{ token }}
          onError={onNext}
          type="passport"
          onSuccess={onNext}
        />
      </Steps>
    </NotificationProvider>
  );
};

export default IDCapture;
