import { proxyCustomElement, HTMLElement } from '@stencil/core/internal/client';

const scFormatBytesCss = ":host{display:inline-block}";

const ScFormatBytes = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    /** The number to format in bytes. */
    this.value = 0;
    /** The unit to display. */
    this.unit = 'byte';
    /** Determines how to display the result, e.g. "100 bytes", "100 b", or "100b". */
    this.display = 'short';
  }
  render() {
    if (isNaN(this.value)) {
      return '';
    }
    const bitPrefixes = ['', 'kilo', 'mega', 'giga', 'tera']; // petabit isn't a supported unit
    const bytePrefixes = ['', 'kilo', 'mega', 'giga', 'tera', 'peta'];
    const prefix = this.unit === 'bit' ? bitPrefixes : bytePrefixes;
    const index = Math.max(0, Math.min(Math.floor(Math.log10(this.value) / 3), prefix.length - 1));
    const unit = prefix[index] + this.unit;
    const valueToFormat = parseFloat((this.value / Math.pow(1000, index)).toPrecision(3));
    return new Intl.NumberFormat(this.locale, { style: 'unit', unit, unitDisplay: this.display }).format(valueToFormat);
  }
  static get style() { return scFormatBytesCss; }
}, [1, "sc-format-bytes", {
    "locale": [1],
    "value": [2],
    "unit": [1],
    "display": [1]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-format-bytes"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-format-bytes":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScFormatBytes);
      }
      break;
  } });
}
defineCustomElement();

export { ScFormatBytes as S, defineCustomElement as d };
