function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

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

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

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

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, { useEffect, useState } from 'react';
import { PageWrap, PageTab, Page } from '@choerodon/boot';
import { observer } from 'mobx-react-lite';
import { CustomTabs } from '@choerodon/components';
import { useAppTopStore } from "../stores";
import { useServiceDetailStore } from "./stores";
import Version from "./Version";
import Allocation from "./Allocation";
import Share from "./Share";
import Tips from "../../../components/new-tips";
var DetailContent = observer(function () {
  var _detailDs$current;

  var _useAppTopStore = useAppTopStore(),
      intlPrefix = _useAppTopStore.intlPrefix,
      detailPermissions = _useAppTopStore.detailPermissions,
      appServiceStore = _useAppTopStore.appServiceStore,
      AppState = _useAppTopStore.AppState;

  if (AppState.getCurrentTheme === 'theme4') {
    import("./theme4.less");
  }

  var _useServiceDetailStor = useServiceDetailStore(),
      formatMessage = _useServiceDetailStor.intl.formatMessage,
      detailDs = _useServiceDetailStor.detailDs,
      _useServiceDetailStor2 = _useServiceDetailStor.access,
      accessPermission = _useServiceDetailStor2.accessPermission,
      accessShare = _useServiceDetailStor2.accessShare,
      versionDs = _useServiceDetailStor.versionDs,
      shareDs = _useServiceDetailStor.shareDs;

  var _useState = useState('Version'),
      _useState2 = _slicedToArray(_useState, 2),
      tabValue = _useState2[0],
      setTabValue = _useState2[1];

  var _useState3 = useState([{
    name: formatMessage({
      id: "".concat(intlPrefix, ".version")
    }),
    value: 'Version'
  }]),
      _useState4 = _slicedToArray(_useState3, 2),
      tabData = _useState4[0],
      setTabData = _useState4[1];

  useEffect(function () {
    var newTabData = tabData;
    var flag = false;

    if (accessShare && detailDs.current && detailDs.current.get('type') === 'normal') {
      flag = true;
      shareDs.query();

      if (!tabData.find(function (i) {
        return i.value === 'Share';
      })) {
        newTabData = [].concat(_toConsumableArray(tabData), [{
          name: formatMessage({
            id: "".concat(intlPrefix, ".share")
          }),
          value: 'Share'
        }]);
        setTabData(newTabData);
      }
    }

    if (!flag) {
      setTabData([{
        name: formatMessage({
          id: "".concat(intlPrefix, ".version")
        }),
        value: 'Version'
      }]);
    }
  }, [accessShare, detailDs.current]);
  return /*#__PURE__*/React.createElement(Page, {
    service: detailPermissions
  }, /*#__PURE__*/React.createElement("p", {
    className: "c7ncd-serviceDetail-title"
  }, (detailDs === null || detailDs === void 0 ? void 0 : (_detailDs$current = detailDs.current) === null || _detailDs$current === void 0 ? void 0 : _detailDs$current.get('name')) || ''), /*#__PURE__*/React.createElement(CustomTabs, {
    data: tabData,
    onChange: function onChange(e, name, value) {
      return setTabValue(value);
    }
  }), tabValue === 'Version' ? /*#__PURE__*/React.createElement(Version, null) : /*#__PURE__*/React.createElement(Share, null));
});
export default DetailContent;