import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { Alert } from 'react-bootstrap';
import { scrollEelementIntoView } from '../../utils/functions';
import { DangerousHTML } from '../DangerousHTML';
import { Block } from '../Block';
import { Button } from '../Button';
import { Spinner } from '../Spinner';
import { FlexBlock } from '../flexBlock';
import { CatalogSimplePrice } from './CatalogSimplePrice';
export var CatalogListDetails =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(CatalogListDetails, _React$PureComponent);

  function CatalogListDetails() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;

    _defineProperty(_assertThisInitialized(_this), "ref", React.createRef());

    return _this;
  }

  var _proto = CatalogListDetails.prototype;

  _proto.componentDidMount = function componentDidMount() {
    var shouldScrollIntoView = this.props.shouldScrollIntoView;

    if (shouldScrollIntoView) {
      scrollEelementIntoView(this.ref.current);
    }
  };

  _proto.renderAlert = function renderAlert() {
    var alertMessage = this.props.alertMessage;

    if (!alertMessage) {
      return null;
    }

    return React.createElement(Block, {
      addTopOffset: true,
      addHorizontalOffset: true,
      cancelBottomOffset: true
    }, React.createElement(Alert, {
      bsStyle: "warning",
      "data-test-automation-id": "alertMessage"
    }, React.createElement(DangerousHTML, null, alertMessage)));
  };

  _proto.renderPrice = function renderPrice() {
    var price = this.props.price;

    if (!price) {
      return null;
    }

    var pricePurchase = price.pricePurchase,
        priceAnnual = price.priceAnnual,
        priceMonthly = price.priceMonthly,
        isPriceFrom = price.isPriceFrom;
    return React.createElement("div", {
      className: "rc-catalog-list-details__price-container"
    }, React.createElement(CatalogSimplePrice, {
      shouldPreserveFromPadding: true,
      pricePurchase: pricePurchase,
      priceAnnual: priceAnnual,
      priceMonthly: priceMonthly,
      isPriceFrom: isPriceFrom
    }));
  };

  _proto.renderActionButton = function renderActionButton() {
    var _this$props = this.props,
        action = _this$props.action,
        textPurchase = _this$props.textPurchase,
        isLoading = _this$props.isLoading,
        isActionDisabled = _this$props.isActionDisabled;
    var isDisabled = isLoading || isActionDisabled || typeof action !== 'function';
    var loadingSpinner = isLoading ? React.createElement(Spinner, {
      size: 18
    }) : null;
    return React.createElement(FlexBlock, {
      align: FlexBlock.CENTER,
      justify: FlexBlock.END,
      gutterWidth: 10
    }, loadingSpinner, React.createElement(Button, {
      bsStyle: "primary",
      onClick: action,
      testAutomationId: "catalogListDetailsButton",
      disabled: isDisabled
    }, textPurchase));
  };

  _proto.render = function render() {
    var _this$props2 = this.props,
        description = _this$props2.description,
        testAutomationId = _this$props2.testAutomationId,
        textDetails = _this$props2.textDetails;
    return React.createElement("section", {
      ref: this.ref,
      className: "rc-catalog-list-details",
      "data-test-automation-id": testAutomationId
    }, React.createElement("div", {
      className: "rc-catalog-list-details__content"
    }, React.createElement("div", {
      className: "rc-catalog-list-details__description-container"
    }, React.createElement("div", {
      className: "rc-catalog-list-details__description-heading"
    }, textDetails), React.createElement("div", {
      className: "rc-catalog-list-details__description",
      "data-test-automation-id": "catalogListDetailsDescription"
    }, React.createElement(DangerousHTML, null, description))), React.createElement("div", {
      className: "rc-catalog-list-details__right"
    }, this.renderPrice(), this.renderAlert())), React.createElement("div", {
      className: "rc-catalog-list-details__actions text-right"
    }, this.renderActionButton()));
  };

  return CatalogListDetails;
}(React.PureComponent);

_defineProperty(CatalogListDetails, "propTypes", {
  description: PropTypes.string.isRequired,
  action: PropTypes.func,
  testAutomationId: PropTypes.string,
  textDetails: PropTypes.string,
  textPurchase: PropTypes.string,
  price: PropTypes.shape({
    pricePurchase: PropTypes.object,
    priceAnnual: PropTypes.object,
    priceMonthly: PropTypes.object,
    isPriceFrom: PropTypes.bool
  }).isRequired,
  shouldScrollIntoView: PropTypes.bool,
  alertMessage: PropTypes.string,
  isActionDisabled: PropTypes.bool,
  isLoading: PropTypes.bool
});

_defineProperty(CatalogListDetails, "defaultProps", {
  testAutomationId: 'catalogListDetails',
  action: null,
  textDetails: 'Details',
  textPurchase: 'Purchase',
  shouldScrollIntoView: false,
  alertMessage: null,
  isActionDisabled: false,
  isLoading: false,
  isDisabled: false
});