import { tinyImage, getCdnUrl } from 't-comm';
import React, { Component } from 'preact';

interface LazyImageProps {
  src: string;
  width?: number;
  height?: number;
  [k: string]: any;
}


class CdnImage extends Component<LazyImageProps, {}> {
  render() {
    const { src, width, height } = this.props;
    const innerSrc = (width || height) ? tinyImage(src, width, height) : getCdnUrl(src);

    return (
      // eslint-disable-next-line light/no-direct-img-src
      <img
        {...this.props}
        src={innerSrc}
      />

    );
  }
}

export default CdnImage;
