import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["url"];
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/** @jsx jsx */
import { Component } from 'react';
import { jsx } from '@emotion/react';
import { getExtensionLozengeData } from '../../../utils';
import { styledImage } from '../styles';
import { LozengeComponent } from './LozengeComponent';
var ExtensionLozenge = /*#__PURE__*/function (_Component) {
  _inherits(ExtensionLozenge, _Component);
  var _super = _createSuper(ExtensionLozenge);
  function ExtensionLozenge() {
    var _this;
    _classCallCheck(this, ExtensionLozenge);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    _defineProperty(_assertThisInitialized(_this), "renderImage", function (lozengeData) {
      var extensionKey = _this.props.node.attrs.extensionKey;
      var url = lozengeData.url,
        rest = _objectWithoutProperties(lozengeData, _excluded);
      return jsx("img", _extends({
        css: styledImage,
        src: url
      }, rest, {
        alt: extensionKey
      }));
    });
    _defineProperty(_assertThisInitialized(_this), "renderFallback", function (lozengeData) {
      var _this$props = _this.props,
        showMacroInteractionDesignUpdates = _this$props.showMacroInteractionDesignUpdates,
        isNodeSelected = _this$props.isNodeSelected,
        isNodeHovered = _this$props.isNodeHovered,
        isNodeNested = _this$props.isNodeNested,
        customContainerStyles = _this$props.customContainerStyles,
        setIsNodeHovered = _this$props.setIsNodeHovered,
        isBodiedMacro = _this$props.isBodiedMacro;
      var _this$props$node$attr = _this.props.node.attrs,
        parameters = _this$props$node$attr.parameters,
        extensionKey = _this$props$node$attr.extensionKey;
      var name = _this.props.node.type.name;
      var params = parameters && parameters.macroParams;
      var title = parameters && parameters.extensionTitle || parameters && parameters.macroMetadata && parameters.macroMetadata.title || extensionKey;
      return jsx(LozengeComponent, {
        isNodeHovered: isNodeHovered,
        isNodeSelected: isNodeSelected,
        isNodeNested: isNodeNested,
        showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates,
        extensionName: name,
        lozengeData: lozengeData,
        params: params,
        title: title,
        renderImage: _this.renderImage,
        customContainerStyles: customContainerStyles,
        setIsNodeHovered: setIsNodeHovered,
        isBodiedMacro: isBodiedMacro
      });
    });
    return _this;
  }
  _createClass(ExtensionLozenge, [{
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
        node = _this$props2.node,
        showMacroInteractionDesignUpdates = _this$props2.showMacroInteractionDesignUpdates;
      var imageData = getExtensionLozengeData({
        node: node,
        type: 'image'
      });
      if (!showMacroInteractionDesignUpdates && imageData && node.type.name !== 'extension') {
        return this.renderImage(imageData);
      }
      var iconData = getExtensionLozengeData({
        node: node,
        type: 'icon'
      });
      return this.renderFallback(iconData);
    }
  }]);
  return ExtensionLozenge;
}(Component);
export { ExtensionLozenge as default };