import { Image, ImageProps } from '@tarojs/components';
import { PropsWithChildren } from 'react';
import './index.scss'

interface INetWorkImageProps extends ImageProps {
    src: string;
    size?: string | [string, string];
}

const InternalNetWorkImage = (props: PropsWithChildren<INetWorkImageProps>) => {
    const { size, style = {}, ...imageProps } = props;

    const _style: React.CSSProperties = { ...(style as React.CSSProperties) };
    if (size) {
        if (Array.isArray(size)) {
            _style.width = size[0];
            _style.height = size[1];
        }
        else {
            _style.width = size;
            _style.height = size;
        }
    }


    return (
        <Image {...imageProps} src={`http://bet-assets.oss-cn-shanghai.aliyuncs.com/project-imgs/${props.src}`} style={_style} />
    )
}


type InternalNetWorkImageType = typeof InternalNetWorkImage;

interface NetWorkImageInterface extends InternalNetWorkImageType {

}

const NetWorkImage = InternalNetWorkImage as NetWorkImageInterface;

export default NetWorkImage;