import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/** @jsx jsx */
import { Component } from 'react';
import { jsx } from '@emotion/react';
import { getExtensionLozengeData } from '../../../utils';
import { styledImage } from '../styles';
import { LozengeComponent } from './LozengeComponent';
export default class ExtensionLozenge extends Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "renderImage", lozengeData => {
      const {
        extensionKey
      } = this.props.node.attrs;
      const {
        url,
        ...rest
      } = lozengeData;
      return jsx("img", _extends({
        css: styledImage,
        src: url
      }, rest, {
        alt: extensionKey
      }));
    });
    _defineProperty(this, "renderFallback", lozengeData => {
      const {
        showMacroInteractionDesignUpdates,
        isNodeSelected,
        isNodeHovered,
        customContainerStyles
      } = this.props;
      const {
        parameters,
        extensionKey
      } = this.props.node.attrs;
      const {
        name
      } = this.props.node.type;
      const params = parameters && parameters.macroParams;
      const title = parameters && parameters.extensionTitle || parameters && parameters.macroMetadata && parameters.macroMetadata.title || extensionKey;
      return jsx(LozengeComponent, {
        isNodeHovered: isNodeHovered,
        isNodeSelected: isNodeSelected,
        showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates,
        extensionName: name,
        lozengeData: lozengeData,
        params: params,
        title: title,
        renderImage: this.renderImage,
        customContainerStyles: customContainerStyles
      });
    });
  }
  render() {
    const {
      node,
      showMacroInteractionDesignUpdates
    } = this.props;
    const imageData = getExtensionLozengeData({
      node,
      type: 'image'
    });
    if (!showMacroInteractionDesignUpdates && imageData && node.type.name !== 'extension') {
      return this.renderImage(imageData);
    }
    const iconData = getExtensionLozengeData({
      node,
      type: 'icon'
    });
    return this.renderFallback(iconData);
  }
}