import {
  alprFetchSuccess, alprFetchStart,
} from '@slice/RecognitionSlice';

const API_BASE_PATH = process.env.NODE_ENV === 'production'
  ? process.env.API_BASE_PATH
  : 'http://localhost:4000';

export const getPlateRecognized = (image) => async (dispatch) => {
  console.log(image);
  dispatch(alprFetchStart());
  const body = new FormData();
  body.append('upload', image);
  try {
    const response = await fetch(`${API_BASE_PATH}/alpr`, {
      method: 'POST',
      body,
    });
    console.log(response);
    const data = await response.json();
    dispatch(alprFetchSuccess(data));
    console.log(data);
  } catch (e) {
    console.log(e);
  }
};

export const getPlateData = (plate) => null;
