import axios from 'axios';

/**
 * 获取 i18n token
 *
 * @export
 * @param {string} appId appId
 * @param {string} appKey appKey
 * @returns {Promise<string>} token
 * @example
 * ```ts
 * getI18nToken('appId', 'appKey').then(token => {
 *   console.log('token', token)
 * })
 * ```
 */
function getI18nToken(appId, appKey) {
  return new Promise(function (resolve, reject) {
    axios({
      url: '/api/openapi/token',
      params: {
        app_id: appId,
        app_key: appKey
      }
    }).then(function (res) {
      var _a, _b;
      var token = ((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.access_token) || '';
      console.log("[i18n] token is ".concat(token));
      resolve(token);
    })["catch"](function (err) {
      reject(err);
    });
  });
}
function importI18nDict(_ref) {
  var projectId = _ref.projectId,
    _ref$moduleCode = _ref.moduleCode,
    moduleCode = _ref$moduleCode === void 0 ? 'default' : _ref$moduleCode,
    _ref$versionCode = _ref.versionCode,
    versionCode = _ref$versionCode === void 0 ? 'v1.0' : _ref$versionCode,
    accessToken = _ref.accessToken,
    data = _ref.data;
  return new Promise(function (resolve, reject) {
    axios({
      url: '/api/openapi/dict/imports',
      data: {
        project_id: projectId,
        module_code: moduleCode,
        version_code: versionCode,
        access_token: accessToken,
        data: data
      },
      method: 'POST'
    }).then(function (res) {
      resolve(res);
    })["catch"](function (err) {
      reject(err);
    });
  });
}

export { getI18nToken, importI18nDict };
