/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
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 { isBlockCardRovoActionExperimentEnabled } from '../../../../../../state/hooks/use-block-card-rovo-action-experiment';
import { Provider } from '../../../elements';
import ActionGroup from '../../action-group';
import Block from '../../block';
import ElementGroup from '../../element-group';
import { filterActionItems } from '../../utils';
const actionGroupStyles = null;
const safariStyles = null;
const providerStyles = null;
const rovoActionStyles = null;
const FooterBlockResolvedView = props => {
  var _context$actions;
  const {
    actions,
    testId,
    onActionMenuOpenChange,
    size = SmartLinkSize.Medium,
    hideProvider,
    isPreviewBlockErrored
  } = props;
  const context = useFlexibleUiContext();
  const rovoChatAction = context === null || context === void 0 ? void 0 : (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions[ActionName.RovoChatAction];
  const is3PBlockExperimentEnabled = isBlockCardRovoActionExperimentEnabled(rovoChatAction === null || rovoChatAction === void 0 ? void 0 : rovoChatAction.product);
  const hasPreview = !!rovoChatAction && is3PBlockExperimentEnabled && !!(context !== null && context !== void 0 && context.preview) && !isPreviewBlockErrored;
  const hasActions = useMemo(() => {
    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
  const {
    safari = false
  } = useMemo(() => browser(), []);
  const onDropdownOpenChange = useCallback(isOpen => {
    if (onActionMenuOpenChange) {
      onActionMenuOpenChange({
        isOpen
      });
    }
  }, [onActionMenuOpenChange]);

  // WidthObserver fires whenever the footer's available width changes.
  const [containerWidth, setContainerWidth] = useState(undefined);
  return /*#__PURE__*/React.createElement(Block, _extends({}, props, {
    testId: `${testId}-resolved-view`
  }), !hideProvider && /*#__PURE__*/React.createElement(Provider, {
    appearance: "subtle",
    testId: `${testId}-provider`,
    hideLabel: hasPreview,
    className: ax([!!rovoChatAction && is3PBlockExperimentEnabled && "_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", !!rovoChatAction && is3PBlockExperimentEnabled && "_kqswh2mm"])
  }, !!rovoChatAction && is3PBlockExperimentEnabled && /*#__PURE__*/React.createElement(WidthObserver, {
    setWidth: setContainerWidth,
    offscreen: true
  }), /*#__PURE__*/React.createElement(ActionGroup, {
    onDropdownOpenChange: onDropdownOpenChange,
    items: actions,
    appearance: !!rovoChatAction && is3PBlockExperimentEnabled ? 'subtle' : 'default',
    size: !!rovoChatAction && is3PBlockExperimentEnabled ? SmartLinkSize.Small : size,
    containerWidth: !!rovoChatAction && is3PBlockExperimentEnabled ? containerWidth : undefined
  })) : null);
};
export default FooterBlockResolvedView;