"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Configurations = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactRouterDom = require("react-router-dom");
var _sharedUxRouter = require("@kbn/shared-ux-router");
var _public = require("@kbn/usage-collection-plugin/public");
var _constants = require("../../../common/constants");
var _use_setup_status_api = require("../../common/api/use_setup_status_api");
var _no_findings_states = require("../../components/no_findings_states");
var _cloud_posture_page = require("../../components/cloud_posture_page");
var _use_latest_findings_data_view = require("../../common/api/use_latest_findings_data_view");
var _constants2 = require("../../common/navigation/constants");
var _findings_by_resource_container = require("./latest_findings_by_resource/findings_by_resource_container");
var _latest_findings_container = require("./latest_findings/latest_findings_container");
/*
 * 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.
 */

const Configurations = () => {
  const location = (0, _reactRouterDom.useLocation)();
  const dataViewQuery = (0, _use_latest_findings_data_view.useLatestFindingsDataView)(_constants.LATEST_FINDINGS_INDEX_PATTERN);
  const {
    data: getSetupStatus
  } = (0, _use_setup_status_api.useCspSetupStatusApi)();
  const hasConfigurationFindings = (getSetupStatus === null || getSetupStatus === void 0 ? void 0 : getSetupStatus.kspm.status) === 'indexed' || (getSetupStatus === null || getSetupStatus === void 0 ? void 0 : getSetupStatus.cspm.status) === 'indexed';

  // For now, when there are no findings we prompt first to install cspm, if it is already installed we will prompt to
  // install kspm
  const noFindingsForPostureType = (getSetupStatus === null || getSetupStatus === void 0 ? void 0 : getSetupStatus.cspm.status) !== 'not-installed' ? 'cspm' : 'kspm';
  if (!hasConfigurationFindings) return /*#__PURE__*/_react.default.createElement(_no_findings_states.NoFindingsStates, {
    posturetype: noFindingsForPostureType
  });
  return /*#__PURE__*/_react.default.createElement(_cloud_posture_page.CloudPosturePage, {
    query: dataViewQuery
  }, /*#__PURE__*/_react.default.createElement(_sharedUxRouter.Routes, null, /*#__PURE__*/_react.default.createElement(_sharedUxRouter.Route, {
    exact: true,
    path: _constants2.cloudPosturePages.findings.path,
    render: () => /*#__PURE__*/_react.default.createElement(_reactRouterDom.Redirect, {
      to: {
        pathname: _constants2.findingsNavigation.findings_default.path,
        search: location.search
      }
    })
  }), /*#__PURE__*/_react.default.createElement(_sharedUxRouter.Route, {
    path: _constants2.findingsNavigation.findings_default.path,
    render: () => /*#__PURE__*/_react.default.createElement(_public.TrackApplicationView, {
      viewId: _constants2.findingsNavigation.findings_default.id
    }, /*#__PURE__*/_react.default.createElement(_latest_findings_container.LatestFindingsContainer, {
      dataView: dataViewQuery.data
    }))
  }), /*#__PURE__*/_react.default.createElement(_sharedUxRouter.Route, {
    path: _constants2.findingsNavigation.findings_by_resource.path,
    render: () => /*#__PURE__*/_react.default.createElement(_findings_by_resource_container.FindingsByResourceContainer, {
      dataView: dataViewQuery.data
    })
  }), /*#__PURE__*/_react.default.createElement(_sharedUxRouter.Route, {
    path: "*",
    render: () => /*#__PURE__*/_react.default.createElement(_reactRouterDom.Redirect, {
      to: _constants2.findingsNavigation.findings_default.path
    })
  })));
};
exports.Configurations = Configurations;