"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FieldMappingStatus = FieldMappingStatus;
exports.getIsIndicesTabOk = getIsIndicesTabOk;
var _react = _interopRequireDefault(require("react"));
var _eui = require("@elastic/eui");
var _lodash = require("lodash");
var _use_apm_params = require("../../../../hooks/use_apm_params");
var _use_fetcher = require("../../../../hooks/use_fetcher");
var _use_apm_router = require("../../../../hooks/use_apm_router");
var _use_diagnostics = require("../context/use_diagnostics");
var _tab_status = require("./tab_status");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

function FieldMappingStatus() {
  const router = (0, _use_apm_router.useApmRouter)();
  const {
    query
  } = (0, _use_apm_params.useApmParams)('/diagnostics/*');
  const {
    diagnosticsBundle,
    status
  } = (0, _use_diagnostics.useDiagnosticsContext)();
  const isLoading = status === _use_fetcher.FETCH_STATUS.LOADING;
  const isOk = getIsIndicesTabOk(diagnosticsBundle);
  return /*#__PURE__*/_react.default.createElement(_tab_status.TabStatus, {
    isLoading: isLoading,
    isOk: isOk,
    "data-test-subj": "fieldMappingStatus"
  }, "Indices", /*#__PURE__*/_react.default.createElement(_eui.EuiLink, {
    "data-test-subj": "apmFieldMappingStatusSeeDetailsLink",
    href: router.link('/diagnostics/indices', {
      query
    })
  }, "See details"));
}
function getIsIndicesTabOk(diagnosticsBundle) {
  if (!diagnosticsBundle) {
    return true;
  }
  return (0, _lodash.isEmpty)(diagnosticsBundle.invalidIndices);
}