function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * Import dependencies
 */
import { t } from '../i18n/t';
import { titleCaseToSentenceCase } from '../utils/case.utils';

/**
 * TopologyNodePresenter
 *
 * A presenter class that formats topology node data for display.
 * Follows the presenter pattern to separate formatting logic from model logic.
 * Handles internationalization, formatting, and display-specific transformations.
 */
export class TopologyNodePresenter {
  /**
   * Creates a new TopologyNodePresenter instance
   *
   * @param model - The topology node model to present
   */
  constructor(model) {
    /** The topology node model being presented */
    _defineProperty(this, "model", void 0);
    this.model = model;
  }
  get title() {
    return this.model.name;
  }
  get subtitle() {
    if (this.model.isGroup && this.groupType) {
      return this.groupType;
    }
    if (this.model.platform) {
      return t('node.service');
    }
    return this.type;
  }

  /**
   * Gets a display-friendly version of the platform name
   * Splits platform strings on '::' and converts from title case to sentence case
   * Preserves specific terms like 'CloudWatch' from being converted
   *
   * @returns A formatted string representing the platform name
   */
  get platform() {
    var _this$model$platform;
    return (_this$model$platform = this.model.platform) === null || _this$model$platform === void 0 ? void 0 : _this$model$platform.split('::').map(word => titleCaseToSentenceCase(word, ['CloudWatch'])).join(' ');
  }

  /**
   * Formats the node type for display
   * Splits type strings on '::' and converts from title case to sentence case
   * Preserves specific terms like 'CloudWatch' from being converted
   *
   * @returns A formatted string representing the node type
   */
  get type() {
    return this.model.type.split('::').map(word => titleCaseToSentenceCase(word, ['CloudWatch'])).join(' ');
  }

  /**
   * Gets a localized string indicating the number of services
   *
   * @returns A formatted and translated string showing the service count
   */
  get numberOfServices() {
    return "".concat(this.model.numberOfServices);
  }

  /**
   * Gets a localized string indicating the number of uninstrumented services
   *
   * @returns A formatted and translated string showing the uninstrumented service count
   */
  get percentOfUninstrumentedServices() {
    if (this.model.numberOfUninstrumentedServices === 0) {
      return t("node.percentOfUninstrumentedServices", {
        value: 0
      });
    }
    return t("node.percentOfUninstrumentedServices", {
      value: Math.round(this.model.numberOfUninstrumentedServices / this.model.numberOfServices * 100).toFixed(1)
    });
  }

  /**
   * Gets a display-friendly version of the group type
   * Applies special case handling for specific group types:
   * - 'Related' is displayed as 'Application'
   * - Other types are converted from title case to sentence case
   *
   * @returns A formatted string representing the group type, or undefined if no group type
   */
  get groupType() {
    const type = this.model.groupType;
    if (!type) return undefined;
    if (type === 'Related') {
      return 'Application';
    }
    return titleCaseToSentenceCase(this.model.groupType);
  }
}