"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 _bug = _interopRequireDefault(require("@atlaskit/object/bug"));
var _changes = _interopRequireDefault(require("@atlaskit/object/changes"));
var _epic = _interopRequireDefault(require("@atlaskit/object/epic"));
var _incident = _interopRequireDefault(require("@atlaskit/object/incident"));
var _problem = _interopRequireDefault(require("@atlaskit/object/problem"));
var _story = _interopRequireDefault(require("@atlaskit/object/story"));
var _subtask = _interopRequireDefault(require("@atlaskit/object/subtask"));
var _task = _interopRequireDefault(require("@atlaskit/object/task"));
var _workItem = _interopRequireDefault(require("@atlaskit/object/work-item"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _constants = require("../../constants");
var TaskIcon = _task.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(_task.default, {
          label: getLabel('Task'),
          testId: "jira-task-icon"
        });
      case _constants.JIRA_SUB_TASK:
        return /*#__PURE__*/_react.default.createElement(_subtask.default, {
          label: getLabel('Sub-task'),
          testId: "jira-subtask-icon"
        });
      case _constants.JIRA_STORY:
        return /*#__PURE__*/_react.default.createElement(_story.default, {
          label: getLabel('Story'),
          testId: "jira-story-icon"
        });
      case _constants.JIRA_BUG:
        return /*#__PURE__*/_react.default.createElement(_bug.default, {
          label: getLabel('Bug'),
          testId: "jira-bug-icon"
        });
      case _constants.JIRA_EPIC:
        return /*#__PURE__*/_react.default.createElement(_epic.default, {
          label: getLabel('Epic'),
          testId: "jira-epic-icon"
        });
      case _constants.JIRA_INCIDENT:
        return /*#__PURE__*/_react.default.createElement(_incident.default, {
          label: getLabel('Incident'),
          testId: "jira-incident-icon"
        });
      case _constants.JIRA_SERVICE_REQUEST:
        return /*#__PURE__*/_react.default.createElement(_workItem.default, {
          label: getLabel('Service request'),
          testId: "jira-service-request-icon"
        });
      case _constants.JIRA_CHANGE:
        return /*#__PURE__*/_react.default.createElement(_changes.default, {
          label: getLabel('Change'),
          testId: "jira-change-icon"
        });
      case _constants.JIRA_PROBLEM:
        return /*#__PURE__*/_react.default.createElement(_problem.default, {
          label: getLabel('Problem'),
          testId: "jira-problem-icon"
        });
      case _constants.JIRA_CUSTOM_TASK_TYPE:
        return taskType.icon || opts.icon || provider.icon || defaultIcon;
    }
  }
  return defaultIcon;
};