'use strict';

import React from 'react';
import PropTypes from 'prop-types';
import BrandedFileLoader from '../utils/BrandedFileLoader';

export class BrandedImage extends React.Component {
    static propTypes = {
        src: PropTypes.string.isRequired, // file path relative to target folder
        folderContext: PropTypes.func.isRequired, // require.context('./target/folder/relative/path/to/current/file')
        alt: PropTypes.string
    };

    static defaultProps = {
        alt: ''
    };

    render() {
        let {src, folderContext, ...props} = this.props;
        let imageLoader = new BrandedFileLoader(folderContext);
        let fileInfo = imageLoader.getFileInfo(src);
        return <img {...props} src={fileInfo.file} data-src={fileInfo.requirePath} />;
    }
}
