import "choerodon-ui/pro/lib/data-set/style";
import _DataSet from "choerodon-ui/pro/lib/data-set";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { createContext, useContext, useMemo, useEffect } from 'react';
import { inject } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { injectIntl } from 'react-intl';
import useStore from "./useStore";
import useNetworkStore from "./useNetworkStore";
import useCustomStore from "./useCustomStore";
import useIngressStore from "./useIngressStore";
import useConfigMapStore from "./useConfigMapStore";
import useSecretStore from "./useSecretStore";
import useChildrenContextStore from "./useChildrenContextStore";
import useCertStore from "./useCertStore";
import BaseInfoDataSet from "./BaseInfoDataSet";
import { useResourceStore } from "../../stores";
var Store = /*#__PURE__*/createContext();
export function useMainStore() {
  return useContext(Store);
}
export var StoreProvider = injectIntl(inject('AppState')(observer(function (props) {
  var projectId = props.AppState.currentMenuType.projectId,
      children = props.children;

  var _useResourceStore = useResourceStore(),
      _useResourceStore$res = _useResourceStore.resourceStore.getSelectedMenu,
      parentId = _useResourceStore$res.parentId,
      key = _useResourceStore$res.key;

  var mainStore = useStore();
  var baseInfoDs = useMemo(function () {
    return new _DataSet(BaseInfoDataSet());
  }, []);
  var networkStore = useNetworkStore();
  var customStore = useCustomStore();
  var ingressStore = useIngressStore();
  var configMapStore = useConfigMapStore();
  var secretStore = useSecretStore();
  var certStore = useCertStore();
  var childrenStore = useChildrenContextStore();
  useEffect(function () {
    // 此处的key是TreeDataSet里的formatInstance中的key值
    // 这个key的规则是每一级别的节点的id属性 然后用 '-' 相连接 例如：’523-1080-21‘
    // 这里只取第一级别的key值，作为环境id
    if (key && key.indexOf('**') < 0) {
      baseInfoDs.transport.read.url = "/devops/v1/projects/".concat(projectId, "/envs/").concat(key, "/info");
      baseInfoDs.query();
    }
  }, [projectId, key]);

  var value = _objectSpread(_objectSpread({}, props), {}, {
    prefixCls: 'c7ncd-deployment',
    intlPrefix: 'c7ncd.deployment',
    podColor: {
      RUNNING_COLOR: '#0bc2a8',
      PADDING_COLOR: '#fbb100'
    },
    mainStore: mainStore,
    networkStore: networkStore,
    customStore: customStore,
    ingressStore: ingressStore,
    configMapStore: configMapStore,
    secretStore: secretStore,
    childrenStore: childrenStore,
    certStore: certStore,
    baseInfoDs: baseInfoDs
  });

  return /*#__PURE__*/React.createElement(Store.Provider, {
    value: value
  }, children);
})));