"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getSetDeploymentModeStep = void 0;
var _react = _interopRequireWildcard(require("react"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _i18nReact = require("@kbn/i18n-react");
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 getSetDeploymentModeStep = ({
  deploymentMode,
  setDeploymentMode,
  disabled
}) => {
  return {
    title: _i18n.i18n.translate('xpack.fleet.fleetServerSetup.stepDeploymentModeTitle', {
      defaultMessage: 'Choose a deployment mode for security'
    }),
    status: disabled ? 'disabled' : undefined,
    children: disabled ? null : /*#__PURE__*/_react.default.createElement(DeploymentModeStepContent, {
      deploymentMode: deploymentMode,
      setDeploymentMode: setDeploymentMode
    })
  };
};
exports.getSetDeploymentModeStep = getSetDeploymentModeStep;
const DeploymentModeStepContent = ({
  deploymentMode,
  setDeploymentMode
}) => {
  const onChangeCallback = (0, _react.useCallback)(v => {
    const value = v.split('_')[0];
    if (value === 'production' || value === 'quickstart') {
      setDeploymentMode(value);
    }
  }, [setDeploymentMode]);

  // radio id has to be unique so that the component works even if appears twice in DOM (Agents tab, Add agent flyout)
  const radioSuffix = (0, _react.useMemo)(() => Date.now(), []);
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiText, null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
    id: "xpack.fleet.fleetServerSetup.stepDeploymentModeDescriptionText",
    defaultMessage: "Fleet uses Transport Layer Security (TLS) to encrypt traffic between Elastic Agents and other components in the Elastic Stack. Choose a deployment mode to determine how you wish to handle certificates. Your selection will affect the Fleet Server setup command shown in a later step."
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, {
    size: "m"
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiRadioGroup, {
    options: [{
      id: `quickstart_${radioSuffix}`,
      label: /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
        id: "xpack.fleet.fleetServerSetup.deploymentModeQuickStartOption",
        defaultMessage: "{quickStart} \u2013 Fleet Server will generate a self-signed certificate. Subsequent agents must be enrolled using the --insecure flag. Not recommended for production use cases.",
        values: {
          quickStart: /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
            id: "xpack.fleet.fleetServerSetup.quickStartText",
            defaultMessage: "Quick start"
          }))
        }
      })
    }, {
      id: `production_${radioSuffix}`,
      label: /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
        id: "xpack.fleet.fleetServerSetup.deploymentModeProductionOption",
        defaultMessage: "{production} \u2013 Provide your own certificates. This option will require agents to specify a cert key when enrolling with Fleet",
        values: {
          production: /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
            id: "xpack.fleet.fleetServerSetup.productionText",
            defaultMessage: "Production"
          }))
        }
      })
    }],
    idSelected: `${deploymentMode}_${radioSuffix}`,
    onChange: onChangeCallback,
    name: `radio group ${radioSuffix}`
  }));
};