<commit_before>import PropTypes from 'prop-types'
import React from 'react'
import styles from 'part:@sanity/components/previews/default-style'
import MediaRender from './common/MediaRender.js'
import SvgPlaceholder from './common/SvgPlaceholder'

const PLACEHOLDER = (
  <div className={styles.root}>
    <SvgPlaceholder styles={styles} />
  </div>
)

export default class DefaultPreview extends React.Component {
  static propTypes = {
    item: PropTypes.shape({
      title: PropTypes.string,
      subtitle: PropTypes.string,
      description: PropTypes.string,
      media: PropTypes.node,
      imageUrl: PropTypes.string,
      sanityImage: PropTypes.object
    }),
    assetSize: PropTypes.shape({
      width: PropTypes.number,
      height: PropTypes.number,
      fit: PropTypes.oneOf(['clip', 'crop', 'clamp'])
    }),
    emptyText: PropTypes.string,
    isPlaceholder: PropTypes.bool,
    children: PropTypes.node
  }

  static defaultProps = {
    emptyText: 'Untitled',
    assetSize: {width: 40, height: 40}
  }

  render() {
    const {item, assetSize, emptyText, children, isPlaceholder} = this.props

    const hasMedia = item.media || item.sanityImage || item.imageUrl

    if (!item || isPlaceholder) {
      return (
        <div
          className={`
            ${hasMedia ? styles.hasMedia : ''}
          `}
        >
          {PLACEHOLDER}
        </div>
      )
    }

    return (
      <div
        className={`
          ${styles.root}
          ${item.subtitle ? styles.hasSubtitle : ''}
          ${hasMedia ? styles.hasMedia : ''}
        `}
      >
        {
          hasMedia && (
            <div className={`${styles.media}`}>
              <MediaRender size={assetSize} item={item} />
            </div>
          )
        }
        <div className={styles.heading}>
          <h2 className={styles.title}>
            {item.title || emptyText}
          </h2>
          {
            item.subtitle && <h3 className={styles.subtitle}>
              {item.subtitle}<commit_msg>[components] Fixing preview media bug<commit_after>import PropTypes from 'prop-types'
import React from 'react'
import styles from 'part:@sanity/components/previews/default-style'
import MediaRender from './common/MediaRender.js'
import SvgPlaceholder from './common/SvgPlaceholder'

const PLACEHOLDER = (
  <div className={styles.root}>
    <SvgPlaceholder styles={styles} />
  </div>
)

export default class DefaultPreview extends React.Component {
  static propTypes = {
    item: PropTypes.shape({
      title: PropTypes.string,
      subtitle: PropTypes.string,
      description: PropTypes.string,
      media: PropTypes.node,
      imageUrl: PropTypes.string,
      sanityImage: PropTypes.object
    }),
    assetSize: PropTypes.shape({
      width: PropTypes.number,
      height: PropTypes.number,
      fit: PropTypes.oneOf(['clip', 'crop', 'clamp'])
    }),
    emptyText: PropTypes.string,
    isPlaceholder: PropTypes.bool,
    children: PropTypes.node
  }

  static defaultProps = {
    emptyText: 'Untitled',
    assetSize: {width: 40, height: 40},
    item: {}
  }

  render() {
    const {item, assetSize, emptyText, children, isPlaceholder} = this.props

    if (!item || isPlaceholder) {
      return (
        <div>
          {PLACEHOLDER}
        </div>
      )
    }

    const hasMedia = item.media || item.sanityImage || item.imageUrl

    return (
      <div
        className={`
          ${styles.root}
          ${item.subtitle ? styles.hasSubtitle : ''}
          ${hasMedia ? styles.hasMedia : ''}
        `}
      >
        {
          hasMedia && (
            <div className={`${styles.media}`}>
              <MediaRender size={assetSize} item={item} />
            </div>
          )
        }
        <div className={styles.heading}>
          <h2 className={styles.title}>
            {item.title || emptyText}
          </h2>
          {
            item.subtitle && <h3 className={styles.subtitle}>
              {item.subtitle}
{'fraction_non_alphanumeric': 0.12913741223671013, 'fraction_numerical': 0.003510531594784353, 'mean_word_length': 2.2169354838709676, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7148117', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1180, 'n_words': 247}