/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useCallback, useMemo, useState } from 'react';
import { browser } from '@atlaskit/linking-common/user-agent';
import { WidthObserver } from '@atlaskit/width-detector';
import { ActionName, SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkWidth } from '../../../../../../constants';
import { useFlexibleUiContext } from '../../../../../../state/flexible-ui-context';
import { Provider } from '../../../elements';
import ActionGroup from '../../action-group';
import Block from '../../block';
import ElementGroup from '../../element-group';
import { filterActionItems } from '../../utils';
var actionGroupStyles = null;
var safariStyles = null;
var providerStyles = null;
var rovoActionStyles = null;
var FooterBlockResolvedView = function FooterBlockResolvedView(props) {
  var _context$actions;
  var actions = props.actions,
    testId = props.testId,
    onActionMenuOpenChange = props.onActionMenuOpenChange,
    _props$size = props.size,
    size = _props$size === void 0 ? SmartLinkSize.Medium : _props$size,
    hideProvider = props.hideProvider,
    isPreviewBlockErrored = props.isPreviewBlockErrored;
  var context = useFlexibleUiContext();
  var rovoChatAction = context === null || context === void 0 || (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions[ActionName.RovoChatAction];
  var isRovoActionsEnabled = useMemo(function () {
    return !!rovoChatAction && rovoChatAction.product === 'CONFLUENCE' && (actions === null || actions === void 0 ? void 0 : actions.some(function (action) {
      return action.name === 'RovoChatAction';
    }));
  }, [rovoChatAction, actions]);
  var hasPreview = isRovoActionsEnabled && !!(context !== null && context !== void 0 && context.preview) && !isPreviewBlockErrored;
  var hasActions = useMemo(function () {
    var _filterActionItems;
    return ((_filterActionItems = filterActionItems(actions, context)) === null || _filterActionItems === void 0 ? void 0 : _filterActionItems.length) > 0;
  }, [actions, context]);

  // eslint-disable-next-line react-hooks/rules-of-hooks
  var _useMemo = useMemo(function () {
      return browser();
    }, []),
    _useMemo$safari = _useMemo.safari,
    safari = _useMemo$safari === void 0 ? false : _useMemo$safari;
  var onDropdownOpenChange = useCallback(function (isOpen) {
    if (onActionMenuOpenChange) {
      onActionMenuOpenChange({
        isOpen: isOpen
      });
    }
  }, [onActionMenuOpenChange]);

  // WidthObserver fires whenever the footer's available width changes.
  var _useState = useState(undefined),
    _useState2 = _slicedToArray(_useState, 2),
    containerWidth = _useState2[0],
    setContainerWidth = _useState2[1];
  return /*#__PURE__*/React.createElement(Block, _extends({}, props, {
    testId: "".concat(testId, "-resolved-view")
  }), !hideProvider && /*#__PURE__*/React.createElement(Provider, {
    appearance: "subtle",
    testId: "".concat(testId, "-provider"),
    hideLabel: hasPreview,
    className: ax([isRovoActionsEnabled && "_1wpz1h6o"])
  }), actions && hasActions ? /*#__PURE__*/React.createElement(ElementGroup, {
    testId: "smart-element-group-actions",
    align: SmartLinkAlignment.Right,
    direction: SmartLinkDirection.Horizontal,
    width: SmartLinkWidth.Flexible,
    className: ax([size === SmartLinkSize.XLarge && "_c71lxy5q", safari && "_4t3i1osq", isRovoActionsEnabled && "_kqswh2mm"])
  }, !!rovoChatAction && (rovoChatAction === null || rovoChatAction === void 0 ? void 0 : rovoChatAction.product) === 'CONFLUENCE' && /*#__PURE__*/React.createElement(WidthObserver, {
    setWidth: setContainerWidth,
    offscreen: true
  }), /*#__PURE__*/React.createElement(ActionGroup, {
    onDropdownOpenChange: onDropdownOpenChange,
    items: actions,
    appearance: isRovoActionsEnabled ? 'subtle' : 'default',
    size: isRovoActionsEnabled ? SmartLinkSize.Small : size,
    containerWidth: isRovoActionsEnabled ? containerWidth : undefined
  })) : null);
};
export default FooterBlockResolvedView;