/* main.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AutomationModalRule = void 0;
require("./main.compiled.css");
var React = _interopRequireWildcard(require("react"));
var _runtime = require("@compiled/react/runtime");
var _analyticsNext = require("@atlaskit/analytics-next");
var _menu = require("@atlaskit/menu");
var _compiled = require("@atlaskit/primitives/compiled");
var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
var _menuContext = require("../../menu-context");
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); }
var styles = {
  ruleButtonStyle: "_2rko12b0 _1h6d1l7x _1dqonqa1 _189ee4h9",
  selectedRuleButtonStyle: "_2rko12b0 _1h6d1w55 _1dqonqa1 _189e1dm9",
  ruleNameStyle: "_4t3i1f4h"
};
var AutomationModalRule = exports.AutomationModalRule = function AutomationModalRule(_ref) {
  var rule = _ref.rule,
    selectedRule = _ref.selectedRule,
    setSelectedRule = _ref.setSelectedRule;
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
    createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
  var _useAutomationMenu = (0, _menuContext.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(_compiled.Box, {
    xcss: isSelectedRule ? styles.selectedRuleButtonStyle : styles.ruleButtonStyle,
    backgroundColor: isSelectedRule ? 'color.background.accent.blue.subtlest' : undefined
  }, /*#__PURE__*/React.createElement(_menu.ButtonItem, {
    isDisabled: !!invokingRuleId,
    iconBefore: isExecuting ? /*#__PURE__*/React.createElement(_spinner.default, {
      size: "small"
    }) : null,
    onClick: ruleOnClick
  }, /*#__PURE__*/React.createElement(_compiled.Stack, {
    xcss: styles.ruleNameStyle,
    alignBlock: "center"
  }, rule.name)));
};