"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extractIconFromTask = void 0;
var _react = _interopRequireDefault(require("react"));
var _ = _interopRequireDefault(require("@atlaskit/icon-object/glyph/bug/16"));
var _2 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/changes/16"));
var _3 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/epic/16"));
var _4 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/incident/16"));
var _5 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/issue/16"));
var _6 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/problem/16"));
var _7 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/story/16"));
var _8 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/subtask/16"));
var _9 = _interopRequireDefault(require("@atlaskit/icon-object/glyph/task/16"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _constants = require("../../constants");
var TaskIcon = _9.default;

/**
 * Chooses an icon for a task based on the provided options.
 *
 * Chooses icon based on variety of Jira task types, based on opts.taskType.id
 *
 * @param opts - The options for extracting the icon.
 * @returns The React node representing the extracted icon, or `undefined` if no icon is found.
 */
var extractIconFromTask = exports.extractIconFromTask = function extractIconFromTask(opts) {
  // Render Atlaskit icons for all supported Jira issue types.
  var taskType = opts.taskType,
    provider = opts.provider;
  var legacyTaskLabel = opts.title || 'task';
  var getLabel = function getLabel(semantic) {
    return (0, _platformFeatureFlags.fg)('platform_navx_smart_link_icon_label_a11y') ? semantic : legacyTaskLabel;
  };
  var defaultIcon = /*#__PURE__*/_react.default.createElement(TaskIcon, {
    label: getLabel('Task'),
    testId: "default-task-icon"
  });
  if (provider && provider.id === _constants.JIRA_GENERATOR_ID && taskType && taskType.id) {
    var taskTypeId = taskType.id;
    var taskTypeName = taskTypeId.split('#').pop();
    switch (taskTypeName) {
      case _constants.JIRA_TASK:
        return /*#__PURE__*/_react.default.createElement(_9.default, {
          label: getLabel('Task'),
          testId: "jira-task-icon"
        });
      case _constants.JIRA_SUB_TASK:
        return /*#__PURE__*/_react.default.createElement(_8.default, {
          label: getLabel('Sub-task'),
          testId: "jira-subtask-icon"
        });
      case _constants.JIRA_STORY:
        return /*#__PURE__*/_react.default.createElement(_7.default, {
          label: getLabel('Story'),
          testId: "jira-story-icon"
        });
      case _constants.JIRA_BUG:
        return /*#__PURE__*/_react.default.createElement(_.default, {
          label: getLabel('Bug'),
          testId: "jira-bug-icon"
        });
      case _constants.JIRA_EPIC:
        return /*#__PURE__*/_react.default.createElement(_3.default, {
          label: getLabel('Epic'),
          testId: "jira-epic-icon"
        });
      case _constants.JIRA_INCIDENT:
        return /*#__PURE__*/_react.default.createElement(_4.default, {
          label: getLabel('Incident'),
          testId: "jira-incident-icon"
        });
      case _constants.JIRA_SERVICE_REQUEST:
        return /*#__PURE__*/_react.default.createElement(_5.default, {
          label: getLabel('Service request'),
          testId: "jira-service-request-icon"
        });
      case _constants.JIRA_CHANGE:
        return /*#__PURE__*/_react.default.createElement(_2.default, {
          label: getLabel('Change'),
          testId: "jira-change-icon"
        });
      case _constants.JIRA_PROBLEM:
        return /*#__PURE__*/_react.default.createElement(_6.default, {
          label: getLabel('Problem'),
          testId: "jira-problem-icon"
        });
      case _constants.JIRA_CUSTOM_TASK_TYPE:
        return taskType.icon || opts.icon || provider.icon || defaultIcon;
    }
  }
  return defaultIcon;
};