import React, { forwardRef } from 'react';
import { CardMediaProps, CardMediaType } from './card.types';

export const CardMedia = forwardRef<CardMediaType, CardMediaProps>(
    (
        { rounded = true, preview = true, type, className = '', ...props },
        ref,
    ) => {
        const classes =
            `m3 m3-card-media${rounded ? ' m3-rounded' : ''}${preview ? ' m3-preview' : ''} ${className}`.trimEnd();
        return React.createElement(type, {
            ...props,
            className: classes,
            ref: ref,
        });
    },
);
