"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.confirmUpdate = confirmUpdate;
var _react = _interopRequireDefault(require("react"));
var _i18nReact = require("@kbn/i18n-react");
var _get_count = require("./services/get_count");
/*
 * 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 ConfirmDescription = ({
  downloadSource,
  agentCount,
  agentPolicyCount
}) => /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
  id: "xpack.fleet.settings.updateDownloadSourceModal.confirmModalText",
  "data-test-subj": "editDownloadSourcesConfirmModal.confirmModalText",
  defaultMessage: "This action will update {downloadSourceName} agent binary source. It will update {policies} and {agents}. This action can not be undone. Are you sure you wish to continue?",
  values: {
    downloadSourceName: /*#__PURE__*/_react.default.createElement("strong", null, downloadSource.name),
    agents: /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
      id: "xpack.fleet.settings.updateDownloadSourceModal.agentsCount",
      defaultMessage: "{agentCount, plural, one {# agent} other {# agents}}",
      values: {
        agentCount
      }
    })),
    policies: /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
      id: "xpack.fleet.settings.updateDownloadSourceModal.agentPolicyCount",
      defaultMessage: "{agentPolicyCount, plural, one {# agent policy} other {# agent policies}}",
      values: {
        agentPolicyCount
      }
    }))
  }
});
async function confirmUpdate(downloadSource, confirm) {
  const {
    agentCount,
    agentPolicyCount
  } = await (0, _get_count.getCountsForDownloadSource)(downloadSource);
  return confirm( /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, {
    id: "xpack.fleet.settings.updateDownloadSourceModal.confirmModalTitle",
    defaultMessage: "Save and deploy changes?"
  }), /*#__PURE__*/_react.default.createElement(ConfirmDescription, {
    agentCount: agentCount,
    agentPolicyCount: agentPolicyCount,
    downloadSource: downloadSource
  }));
}