"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EditSyncRulesFlyout = void 0;
var _react = _interopRequireDefault(require("react"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _beta_callout = require("../../../../../shared/beta/beta_callout");
var _advanced_sync_rules = require("./advanced_sync_rules");
var _edit_sync_rules_tab = require("./edit_sync_rules_tab");
var _editable_basic_rules_table = require("./editable_basic_rules_table");
/*
 * 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.
 */
var FilteringTabs;
(function (FilteringTabs) {
  FilteringTabs["BASIC"] = "basic";
  FilteringTabs["ADVANCED"] = "advanced";
})(FilteringTabs || (FilteringTabs = {}));
const EditSyncRulesFlyout = ({
  errors,
  hasAdvancedFilteringFeature,
  hasBasicFilteringFeature,
  revertLocalFilteringRules,
  revertLocalAdvancedFiltering,
  setIsEditing
}) => {
  const tabs = [...(hasBasicFilteringFeature ? [{
    content: /*#__PURE__*/_react.default.createElement(_edit_sync_rules_tab.EditSyncRulesTab, {
      revertAction: revertLocalFilteringRules
    }, /*#__PURE__*/_react.default.createElement(_editable_basic_rules_table.SyncRulesTable, null)),
    id: FilteringTabs.BASIC,
    name: _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.basicTabTitle', {
      defaultMessage: 'Basic rules'
    })
  }] : []), ...(hasAdvancedFilteringFeature ? [{
    content: /*#__PURE__*/_react.default.createElement(_edit_sync_rules_tab.EditSyncRulesTab, {
      revertAction: revertLocalAdvancedFiltering
    }, /*#__PURE__*/_react.default.createElement(_advanced_sync_rules.AdvancedSyncRules, null)),
    id: FilteringTabs.ADVANCED,
    name: _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.advancedTabTitle', {
      defaultMessage: 'Advanced rules'
    })
  }] : [])];
  return /*#__PURE__*/_react.default.createElement(_eui.EuiFlyout, {
    ownFocus: true,
    onClose: () => setIsEditing(false),
    "aria-labelledby": "rulesFlyout",
    size: "l"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlyoutHeader, null, /*#__PURE__*/_react.default.createElement(_eui.EuiTitle, {
    size: "m"
  }, /*#__PURE__*/_react.default.createElement("h2", {
    id: "rulesFlyout"
  }, _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.flyout.title', {
    defaultMessage: 'Draft rules'
  }))), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, null), /*#__PURE__*/_react.default.createElement(_beta_callout.BetaCallOut, {
    description: _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.flyout.betaDescription', {
      defaultMessage: 'Sync rules is a beta feature. Beta features are subject to change and are not covered by the support SLA of general release (GA) features. Elastic plans to promote this feature to GA in a future release.'
    })
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, null), /*#__PURE__*/_react.default.createElement(_eui.EuiText, {
    size: "s"
  }, _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.flyout.description', {
    defaultMessage: 'Plan and edit rules here before applying them to the next sync.'
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, null), !!(errors !== null && errors !== void 0 && errors.length) && /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    direction: "column"
  }, errors.map((error, index) => /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, {
    id: `${index}`,
    grow: false
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiCallOut, {
    color: "danger",
    title: _i18n.i18n.translate('xpack.enterpriseSearch.content.index.connector.syncRules.flyout.errorTitle', {
      defaultMessage: 'Sync {idsLength, plural, one {rule} other {rules}} {ids} {idsLength, plural, one {is} other {are}} invalid.',
      values: {
        ids: error.ids.join(', '),
        idsLength: error.ids.length
      }
    })
  }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, error.messages.map(message => /*#__PURE__*/_react.default.createElement("p", {
    id: message
  }, message)))))))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlyoutBody, null, /*#__PURE__*/_react.default.createElement(_eui.EuiTabbedContent, {
    tabs: tabs
  })));
};
exports.EditSyncRulesFlyout = EditSyncRulesFlyout;