"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ForcemergeField = void 0;
var _react = _interopRequireWildcard(require("react"));
var _i18nReact = require("@kbn/i18n-react");
var _uuid = require("uuid");
var _eui = require("@elastic/eui");
var _shared_imports = require("../../../../../../shared_imports");
var _i18n_texts = require("../../../i18n_texts");
var _edit_policy_context = require("../../../edit_policy_context");
var _form = require("../../../form");
var _ = require("../..");
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 ForcemergeField = ({
  phase
}) => {
  const {
    policy
  } = (0, _edit_policy_context.useEditPolicyContext)();
  const initialToggleValue = (0, _react.useMemo)(() => {
    var _policy$phases$phase, _policy$phases$phase$;
    return ((_policy$phases$phase = policy.phases[phase]) === null || _policy$phases$phase === void 0 ? void 0 : (_policy$phases$phase$ = _policy$phases$phase.actions) === null || _policy$phases$phase$ === void 0 ? void 0 : _policy$phases$phase$.forcemerge) != null;
  }, [policy, phase]);
  const {
    docLinks
  } = (0, _shared_imports.useKibana)().services;
  return /*#__PURE__*/_react.default.createElement(_.DescribedFormRow, {
    title: /*#__PURE__*/_react.default.createElement("h3", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
      id: "xpack.indexLifecycleMgmt.editPolicy.forceMerge.enableText",
      defaultMessage: "Force merge"
    })),
    description: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
      id: "xpack.indexLifecycleMgmt.editPolicy.forceMerge.enableExplanationText",
      defaultMessage: "Reduce the number of segments in each index shard and clean up deleted documents."
    }), ' ', /*#__PURE__*/_react.default.createElement(_.LearnMoreLink, {
      docPath: docLinks.links.elasticsearch.ilmForceMerge
    })),
    titleSize: "xs",
    fullWidth: true,
    switchProps: {
      label: _i18n_texts.i18nTexts.editPolicy.forceMergeEnabledFieldLabel,
      'data-test-subj': `${phase}-forceMergeSwitch`,
      initialValue: initialToggleValue
    }
  }, /*#__PURE__*/_react.default.createElement(_form.UseField, {
    path: `phases.${phase}.actions.forcemerge.max_num_segments`,
    component: _shared_imports.NumericField,
    componentProps: {
      fullWidth: false,
      euiFieldProps: {
        'data-test-subj': `${phase}-selectedForceMergeSegments`,
        min: 1
      }
    }
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, null), /*#__PURE__*/_react.default.createElement(_form.UseField, {
    path: `_meta.${phase}.bestCompression`
  }, field => /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    alignItems: "center",
    gutterSize: "s"
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, {
    grow: false
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiCheckbox, {
    label: field.label,
    checked: field.value,
    onChange: field.onChange,
    "data-test-subj": `${phase}-bestCompression`,
    id: (0, _uuid.v4)()
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, {
    grow: false
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiIconTip, {
    content: _i18n_texts.i18nTexts.editPolicy.bestCompressionFieldHelpText,
    position: "right"
  })))));
};
exports.ForcemergeField = ForcemergeField;