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; }

/* eslint-disable max-len */
import React, { createContext, useMemo, useContext } from 'react';
import { inject } from 'mobx-react';
import { injectIntl } from 'react-intl';
import { observer } from 'mobx-react-lite';
import useStore from "./useStore";
import { itemTypeMappings } from "./mappings";
import TreeDataSet from "./TreeDataSet";
import useHostClusterStore from "./useHostClusterStore";
import NodeDataSet from "./NodeDataSet";
import FormDataSet from "./createClusterByHostsFormDataSet";
import publicNodeDataSet from "./publicNodeDataSet";
var Store = /*#__PURE__*/createContext();
export function useClusterStore() {
  return useContext(Store);
}
export var StoreProvider = injectIntl(inject('AppState')(observer(function (props) {
  var projectId = props.AppState.currentMenuType.id,
      children = props.children,
      formatMessage = props.intl.formatMessage;
  var clusterStore = useStore();
  var itemType = useMemo(function () {
    return itemTypeMappings;
  }, []);
  var treeDs = useMemo(function () {
    return new _DataSet(TreeDataSet(clusterStore, projectId));
  }, [projectId]);
  var intlPrefix = 'c7ncd.cluster';
  var createHostClusterStore = useHostClusterStore();
  var accountDs = useMemo(function () {
    return new _DataSet({
      data: [{
        text: formatMessage({
          id: "".concat(intlPrefix, ".nodesCreate.account.password")
        }),
        value: 'accountPassword'
      }, {
        text: formatMessage({
          id: "".concat(intlPrefix, ".nodesCreate.account.token")
        }),
        value: 'publickey'
      }],
      selection: 'single'
    });
  }, []);
  var nodesTypeDs = useMemo(function () {
    return new _DataSet({
      data: [{
        text: 'master',
        value: 'master'
      }, {
        text: 'etcd',
        value: 'etcd'
      }, {
        text: 'worker',
        value: 'worker'
      }],
      selection: 'multiple'
    });
  }, []);
  var nodesDs = useMemo(function () {
    return new _DataSet(NodeDataSet(_objectSpread(_objectSpread({}, props), {}, {
      accountDs: accountDs,
      formatMessage: formatMessage,
      intlPrefix: intlPrefix,
      projectId: projectId
    })), [projectId]);
  });
  var addNodesDs = useMemo(function () {
    return new _DataSet(NodeDataSet(_objectSpread(_objectSpread({}, props), {}, {
      accountDs: accountDs,
      formatMessage: formatMessage,
      intlPrefix: intlPrefix,
      createHostClusterStore: createHostClusterStore,
      isModal: true,
      clusterId: clusterStore.getSelectedMenu.id,
      projectId: projectId
    })), [projectId, clusterStore.getSelectedMenu.id]);
  });
  var publicNodeDs = useMemo(function () {
    return new _DataSet(publicNodeDataSet(_objectSpread(_objectSpread({}, props), {}, {
      accountDs: accountDs,
      formatMessage: formatMessage,
      intlPrefix: intlPrefix,
      createHostClusterStore: createHostClusterStore,
      projectId: projectId
    })));
  }, [projectId]);
  var formDs = useMemo(function () {
    return new _DataSet(FormDataSet({
      createHostClusterStore: createHostClusterStore,
      projectId: projectId,
      formatMessage: formatMessage,
      intlPrefix: intlPrefix,
      nodesDs: nodesDs,
      publicNodeDs: publicNodeDs
    }));
  }, [createHostClusterStore, nodesDs, projectId, publicNodeDs]);

  var value = _objectSpread(_objectSpread({}, props), {}, {
    prefixCls: 'c7ncd-cluster',
    intlPrefix: intlPrefix,
    permissions: [],
    clusterStore: clusterStore,
    itemType: itemType,
    treeDs: treeDs,
    formatMessage: formatMessage,
    nodesTypeDs: nodesTypeDs,
    addNodesDs: addNodesDs,
    formDs: formDs,
    nodesDs: nodesDs,
    projectId: projectId,
    createHostClusterStore: createHostClusterStore,
    publicNodeDs: publicNodeDs
  });

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