"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StartCrawlContextMenu = void 0;
var _react = _interopRequireWildcard(require("react"));
var _kea = require("kea");
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _crawl_custom_settings_flyout_logic = require("../../search_index/crawler/crawl_custom_settings_flyout/crawl_custom_settings_flyout_logic");
var _crawler_logic = require("../../search_index/crawler/crawler_logic");
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 StartCrawlContextMenu = () => {
  const {
    reApplyCrawlRules,
    startCrawl
  } = (0, _kea.useActions)(_crawler_logic.CrawlerLogic);
  const {
    showFlyout: showCrawlCustomSettingsFlyout
  } = (0, _kea.useActions)(_crawl_custom_settings_flyout_logic.CrawlCustomSettingsFlyoutLogic);
  const [isPopoverOpen, setPopover] = (0, _react.useState)(false);
  const togglePopover = () => setPopover(!isPopoverOpen);
  const closePopover = () => setPopover(false);
  return /*#__PURE__*/_react.default.createElement(_eui.EuiPopover, {
    button: /*#__PURE__*/_react.default.createElement(_eui.EuiButton, {
      iconType: "arrowDown",
      iconSide: "right",
      onClick: togglePopover,
      fill: true,
      "data-test-subj": "entSearchContent-crawler-startCrawlMenu-menuButton"
    }, _i18n.i18n.translate('xpack.enterpriseSearch.crawler.crawlerStatusIndicator.retryCrawlButtonLabel', {
      defaultMessage: 'Crawl'
    })),
    isOpen: isPopoverOpen,
    closePopover: closePopover,
    panelPaddingSize: "none",
    anchorPosition: "downLeft"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiContextMenuPanel, {
    items: [/*#__PURE__*/_react.default.createElement(_eui.EuiContextMenuItem, {
      key: "crawl all domains",
      onClick: () => {
        closePopover();
        startCrawl();
      },
      icon: "play",
      "data-test-subj": "entSearchContent-crawler-startCrawlMenu-crawlAllDomains"
    }, _i18n.i18n.translate('xpack.enterpriseSearch.crawler.startCrawlContextMenu.crawlAllDomainsMenuLabel', {
      defaultMessage: 'Crawl all domains on this index'
    })), /*#__PURE__*/_react.default.createElement(_eui.EuiContextMenuItem, {
      key: "crawl with custom settings",
      onClick: () => {
        closePopover();
        showCrawlCustomSettingsFlyout();
      },
      icon: "gear"
    }, _i18n.i18n.translate('xpack.enterpriseSearch.crawler.startCrawlContextMenu.crawlCustomSettingsMenuLabel', {
      defaultMessage: 'Crawl with custom settings'
    })), /*#__PURE__*/_react.default.createElement(_eui.EuiContextMenuItem, {
      key: "reaply crawl rules",
      onClick: () => {
        closePopover();
        reApplyCrawlRules();
      },
      icon: "refresh"
    }, _i18n.i18n.translate('xpack.enterpriseSearch.crawler.startCrawlContextMenu.reapplyCrawlRulesMenuLabel', {
      defaultMessage: 'Reapply crawl rules'
    }))]
  }));
};
exports.StartCrawlContextMenu = StartCrawlContextMenu;