"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AnalyticsCollectionOverview = void 0;
var _react = _interopRequireWildcard(require("react"));
var _kea = require("kea");
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _get_formula_by_filter = require("../../../utils/get_formula_by_filter");
var _page_template = require("../../layout/page_template");
var _analytics_collection_no_events_callout = require("../analytics_collection_no_events_callout/analytics_collection_no_events_callout");
var _analytics_collection_toolbar = require("../analytics_collection_toolbar/analytics_collection_toolbar");
var _analytics_collection_toolbar_logic = require("../analytics_collection_toolbar/analytics_collection_toolbar_logic");
var _analytics_collection_chart = require("./analytics_collection_chart");
var _analytics_collection_metric = require("./analytics_collection_metric");
var _analytics_collection_overview_table = require("./analytics_collection_overview_table");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/*
 * 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 filters = [{
  id: _get_formula_by_filter.FilterBy.Searches,
  name: _i18n.i18n.translate('xpack.enterpriseSearch.analytics.collections.collectionsView.charts.searches', {
    defaultMessage: 'Searches'
  })
}, {
  id: _get_formula_by_filter.FilterBy.NoResults,
  name: _i18n.i18n.translate('xpack.enterpriseSearch.analytics.collections.collectionsView.charts.noResults', {
    defaultMessage: 'No results'
  })
}, {
  id: _get_formula_by_filter.FilterBy.Clicks,
  name: _i18n.i18n.translate('xpack.enterpriseSearch.analytics.collections.collectionsView.charts.clicks', {
    defaultMessage: 'Click'
  })
}, {
  id: _get_formula_by_filter.FilterBy.Sessions,
  name: _i18n.i18n.translate('xpack.enterpriseSearch.analytics.collections.collectionsView.charts.sessions', {
    defaultMessage: 'Sessions'
  })
}];
const AnalyticsCollectionOverview = ({
  analyticsCollection
}) => {
  const {
    setTimeRange
  } = (0, _kea.useActions)(_analytics_collection_toolbar_logic.AnalyticsCollectionToolbarLogic);
  const {
    timeRange,
    searchSessionId
  } = (0, _kea.useValues)(_analytics_collection_toolbar_logic.AnalyticsCollectionToolbarLogic);
  const [filterBy, setFilterBy] = (0, _react.useState)(_get_formula_by_filter.FilterBy.Searches);
  return /*#__PURE__*/_react.default.createElement(_page_template.EnterpriseSearchAnalyticsPageTemplate, {
    restrictWidth: true,
    pageChrome: [analyticsCollection === null || analyticsCollection === void 0 ? void 0 : analyticsCollection.name],
    analyticsName: analyticsCollection === null || analyticsCollection === void 0 ? void 0 : analyticsCollection.name,
    pageViewTelemetry: `View Analytics Collection - Overview`,
    pageHeader: {
      bottomBorder: false,
      pageTitle: _i18n.i18n.translate('xpack.enterpriseSearch.analytics.collectionsView.title', {
        defaultMessage: 'Overview'
      }),
      rightSideItems: [/*#__PURE__*/_react.default.createElement(_analytics_collection_toolbar.AnalyticsCollectionToolbar, null)]
    }
  }, /*#__PURE__*/_react.default.createElement(_analytics_collection_no_events_callout.AnalyticsCollectionNoEventsCallout, {
    analyticsCollection: analyticsCollection
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, null), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    direction: "column"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    gutterSize: "m"
  }, filters.map(({
    name,
    id
  }) => /*#__PURE__*/_react.default.createElement(_analytics_collection_metric.AnalyticsCollectionViewMetricWithLens, {
    key: id,
    id: `analytics-collection-metric-${analyticsCollection.name}-${id}`,
    isSelected: filterBy === id,
    name: name,
    onClick: event => {
      var _event$currentTarget;
      (_event$currentTarget = event.currentTarget) === null || _event$currentTarget === void 0 ? void 0 : _event$currentTarget.blur();
      setFilterBy(id);
    },
    collection: analyticsCollection,
    timeRange: timeRange,
    searchSessionId: searchSessionId,
    getFormula: _get_formula_by_filter.getFormulaByFilter.bind(null, id)
  }))), /*#__PURE__*/_react.default.createElement(_analytics_collection_chart.AnalyticsCollectionChartWithLens, {
    id: 'analytics-collection-chart-' + analyticsCollection.name,
    collection: analyticsCollection,
    timeRange: timeRange,
    setTimeRange: setTimeRange,
    searchSessionId: searchSessionId,
    selectedChart: filterBy,
    setSelectedChart: setFilterBy
  }), /*#__PURE__*/_react.default.createElement(_analytics_collection_overview_table.AnalyticsCollectionOverviewTable, {
    filterBy: filterBy
  })));
};
exports.AnalyticsCollectionOverview = AnalyticsCollectionOverview;