import ImageBase from 'next/future/image';
import { FC } from 'react';

type Props = Record<'src' | 'alt', string>;

const IMAGE_CDN = 'http://localhost:8000';

const localizeSrc = (src: string) => {
  if (process.env.NODE_ENV === 'production' || src.startsWith('http')) return src;
  return IMAGE_CDN + src;
}

const Image: FC<Props> = ({ src, ...props }) => {
  const source = localizeSrc(src);

  return (
    <ImageBase src={source} {...props} />
  )
}

export default Image;
