import * as React from 'react';

import { ScannerBle } from './scanner-ble';
import { ScannerCamera } from './scanner-camera';
import { ScannerHid } from './scanner-hid';
import { ScannerProps } from './scanner.props';

/**
 * Component in charge to detect a Barcode
 * @param onBarcodeDetected Callback executed when the device detects a barcode
 * @param style An optional style override useful for padding & margin.
 * @param mode Do you want to use the device camera, or bluetooth scanner in BLE or HID mode.
 */
export function Scanner(props: ScannerProps) {
  const { onBarcodeDetected, mode, style, ...rest } = props;

  switch (mode) {
    case 'ble':
      return <ScannerBle style={style} onBarcodeDetected={onBarcodeDetected} {...rest} />;
    case 'hid':
      return <ScannerHid style={style} onBarcodeDetected={onBarcodeDetected} {...rest} />;
    default: {
      return <ScannerCamera style={style} onBarcodeDetected={onBarcodeDetected} {...rest} />;
    }
  }
}

Scanner.defaultProps = {
  mode: 'ble',
};
