function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React, { Fragment } from 'react';
import { observer } from 'mobx-react-lite';
import { PageWrap, PageTab, Page } from '@choerodon/boot';
import { injectIntl, FormattedMessage } from 'react-intl';
import classNames from 'classnames';
import { useTabActiveKey } from '@choerodon/components';
import map from 'lodash/map';
import { TabCode } from '@choerodon/master';
import { useCodeManagerStore } from "../stores";
import EmptyShown, { EmptyLoading } from "./empty";
import CodeQuality from "./code-quality";
import CodeManagerBranch from "./branch";
import CodeManagerMergeRequest from "./merge-request";
import CodeManagerAppTag from "./app-tag";
import CodeManagerCiPipelineManage from "./ci-pipeline-manage";
import Tips from "../../../components/new-tips";
import "./index.less";
import "./theme4.less";

var _TabCode$get = TabCode.get('/devops/code-management'),
    tabCodes = _TabCode$get.tabCodes;

var MainView = injectIntl(observer(function (props) {
  var formatMessage = props.intl.formatMessage;

  var _useCodeManagerStore = useCodeManagerStore(),
      permissions = _useCodeManagerStore.permissions,
      codeManagerStore = _useCodeManagerStore.codeManagerStore,
      AppState = _useCodeManagerStore.AppState;

  var getLoading = codeManagerStore.getLoading,
      getHasApp = codeManagerStore.getHasApp;

  var _useTabActiveKey = useTabActiveKey(tabCodes[0]),
      _useTabActiveKey2 = _slicedToArray(_useTabActiveKey, 2),
      activeKey = _useTabActiveKey2[0],
      setActiveKey = _useTabActiveKey2[1];

  function getContent() {
    if (getLoading) return /*#__PURE__*/React.createElement(EmptyLoading, {
      formatMessage: formatMessage
    });
    var titleData = ['master', 'feature', 'bugfix', 'release', 'hotfix', 'custom'];
    var popoverContent = map(titleData, function (item) {
      return /*#__PURE__*/React.createElement("div", {
        className: "c7n-branch-block",
        key: item
      }, /*#__PURE__*/React.createElement("span", {
        className: "branch-popover-span span-".concat(item)
      }), /*#__PURE__*/React.createElement("div", {
        className: "branch-popover-content"
      }, /*#__PURE__*/React.createElement("p", {
        className: "branch-popover-p"
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "branch.".concat(item)
      })), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "branch.".concat(item, "Des")
      }))));
    });
    return getHasApp ? /*#__PURE__*/React.createElement(PageWrap, {
      noHeader: [],
      cache: true,
      onChange: function onChange(key) {
        return setActiveKey(key);
      }
    }, /*#__PURE__*/React.createElement(PageTab, {
      title: /*#__PURE__*/React.createElement(Tips, {
        helpText: popoverContent,
        title: formatMessage({
          id: 'code-management.branch'
        }),
        popoverClassName: "branch-popover",
        placement: "bottomLeft"
      }),
      tabKey: tabCodes[0],
      component: CodeManagerBranch,
      alwaysShow: true
    }), /*#__PURE__*/React.createElement(PageTab, {
      title: formatMessage({
        id: 'code-management.merge-request'
      }),
      tabKey: tabCodes[1],
      component: CodeManagerMergeRequest,
      alwaysShow: true
    }), /*#__PURE__*/React.createElement(PageTab, {
      title: formatMessage({
        id: 'code-management.ci-pipeline'
      }),
      tabKey: tabCodes[2],
      component: CodeManagerCiPipelineManage,
      alwaysShow: true
    }), /*#__PURE__*/React.createElement(PageTab, {
      title: formatMessage({
        id: 'code-management.app-tag'
      }),
      tabKey: tabCodes[3],
      component: CodeManagerAppTag,
      alwaysShow: true
    }), /*#__PURE__*/React.createElement(PageTab, {
      title: formatMessage({
        id: 'code-management.code-quality'
      }),
      tabKey: tabCodes[4],
      component: CodeQuality,
      alwaysShow: true
    })) : /*#__PURE__*/React.createElement(EmptyShown, null);
  }

  return /*#__PURE__*/React.createElement(Page, {
    service: permissions
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames({
      'c7n-code-managerment-tab-list': true,
      'c7ncd-theme4-management': AppState.getCurrentTheme === 'theme4'
    })
  }, getContent()));
}));
export default MainView;