"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.RovoSummaryBlock = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _constants = require("../../../../../constants");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _resolved = _interopRequireWildcard(require("./resolved"));
var _excluded = ["testId"],
  _excluded2 = ["testId", "url"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
 * Represents an AISummaryBlock, designed to summarising link resource
 * content using AI.
 * @public
 * @param {AISummaryBlockProps} AISummaryBlock
 * @see Block
 */
var AISummaryBlock = function AISummaryBlock(_ref) {
  var _context$actions, _props$size, _cardContext$ui;
  var _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-ai-summary-block' : _ref$testId,
    props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var cardContext = (0, _flexibleUiContext.useFlexibleCardContext)();
  var context = (0, _flexibleUiContext.useFlexibleUiContext)();
  var actionData = context === null || context === void 0 || (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions[_constants.InternalActionName.AISummaryAction];
  if ((cardContext === null || cardContext === void 0 ? void 0 : cardContext.status) !== _constants.SmartLinkStatus.Resolved) {
    return null;
  }
  if (!(actionData !== null && actionData !== void 0 && actionData.url)) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_resolved.default, (0, _extends2.default)({}, props, {
    size: (_props$size = props.size) !== null && _props$size !== void 0 ? _props$size : cardContext === null || cardContext === void 0 || (_cardContext$ui = cardContext.ui) === null || _cardContext$ui === void 0 ? void 0 : _cardContext$ui.size,
    testId: testId,
    url: actionData.url
  }));
};

/**
 * Represents an AISummaryBlock, designed to summarising link resource
 * content using AI.
 * @public
 * @param {RovoSummaryBlockProps} RovoSummaryBlock
 * @see Block
 */
var RovoSummaryBlock = exports.RovoSummaryBlock = function RovoSummaryBlock(_ref2) {
  var _props$size2, _cardContext$ui2;
  var _ref2$testId = _ref2.testId,
    testId = _ref2$testId === void 0 ? 'smart-ai-summary-block' : _ref2$testId,
    url = _ref2.url,
    props = (0, _objectWithoutProperties2.default)(_ref2, _excluded2);
  var cardContext = (0, _flexibleUiContext.useFlexibleCardContext)();
  if ((cardContext === null || cardContext === void 0 ? void 0 : cardContext.status) !== _constants.SmartLinkStatus.Resolved) {
    return null;
  }
  if (!url) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_resolved.RovoSummaryBlockResolvedView, (0, _extends2.default)({}, props, {
    size: (_props$size2 = props.size) !== null && _props$size2 !== void 0 ? _props$size2 : cardContext === null || cardContext === void 0 || (_cardContext$ui2 = cardContext.ui) === null || _cardContext$ui2 === void 0 ? void 0 : _cardContext$ui2.size,
    testId: testId,
    url: url
  }));
};
var _default = exports.default = AISummaryBlock;