/* main.tsx generated by @compiled/babel-plugin v0.38.1 */
import "./main.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
import { ButtonItem } from '@atlaskit/menu';
import { Box, Stack } from '@atlaskit/primitives/compiled';
import Spinner from '@atlaskit/spinner';
import { useAutomationMenu } from '../../menu-context';
var styles = {
  ruleButtonStyle: "_2rko12b0 _1h6d1l7x _1dqonqa1 _189ee4h9",
  selectedRuleButtonStyle: "_2rko12b0 _1h6d1w55 _1dqonqa1 _189e1dm9",
  ruleNameStyle: "_4t3i1f4h"
};
export var AutomationModalRule = function AutomationModalRule(_ref) {
  var rule = _ref.rule,
    selectedRule = _ref.selectedRule,
    setSelectedRule = _ref.setSelectedRule;
  var _useAnalyticsEvents = useAnalyticsEvents(),
    createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
  var _useAutomationMenu = useAutomationMenu(),
    analyticsSource = _useAutomationMenu.analyticsSource,
    invokingRuleId = _useAutomationMenu.invokingRuleId;
  var isSelectedRule = (selectedRule === null || selectedRule === void 0 ? void 0 : selectedRule.id) === rule.id;
  var isExecuting = rule.id === invokingRuleId;
  var ruleOnClick = function ruleOnClick() {
    createAnalyticsEvent({
      type: 'sendUIEvent',
      data: {
        action: 'clicked',
        actionSubject: 'button',
        actionSubjectId: 'selectManualTriggerAutomation',
        source: analyticsSource,
        attributes: {
          ruleId: rule.id.toString()
        }
      }
    }).fire();
    setSelectedRule(rule);
  };
  return /*#__PURE__*/React.createElement(Box, {
    xcss: isSelectedRule ? styles.selectedRuleButtonStyle : styles.ruleButtonStyle,
    backgroundColor: isSelectedRule ? 'color.background.accent.blue.subtlest' : undefined
  }, /*#__PURE__*/React.createElement(ButtonItem, {
    isDisabled: !!invokingRuleId,
    iconBefore: isExecuting ? /*#__PURE__*/React.createElement(Spinner, {
      size: "small"
    }) : null,
    onClick: ruleOnClick
  }, /*#__PURE__*/React.createElement(Stack, {
    xcss: styles.ruleNameStyle,
    alignBlock: "center"
  }, rule.name)));
};