import { h, f as forceUpdate, r as registerInstance, H as Host, g as getElement } from './index-090d31ca.js';
import { s as sanitizeVegaComponent } from './component-7d906393.js';
import { c as MapToComponentField, V as VegaSlimmer, M as MapToComponentMethod, L as LogUtility, I as InjectVegaSlimmer } from './global-slimmer-registry-17c4efd4.js';
import { V as VegaComponentUsageRuntimeMetricsSlimmer, I as InjectVegaGlobalSlimmer } from './component-usage-runtime-metrics-46020a03.js';
import { V as VegaInternalIconManager } from './internal-icon-manager-bd80b3bb.js';
import { V as VegaIconManager } from './icon-manager-539d7cf7.js';
import { f as formatAndValidResponsiveToken } from './design-token-57de4f4f.js';
import { f as FLAG_ICON_LOADED } from './static-subject-title-52f93124.js';
import { O as Observer } from './observer-3959f9dd.js';
import { C as ChangeManager } from './change-manager-6a7eb88c.js';
import './create-public-api-runtime-metrics-slimmer-aaadaa08.js';
import './dynamic-slimmer-90b8af32.js';
import './misc-9fdbcfbb.js';
import './type-guard-adc244fd.js';
import './breakpoints-d9faf11c.js';
import './ui-93922c59.js';
import './typography-396de03f.js';
import './internal-translation-controller-d7dee4a0.js';
import './responsive-format-facade-456a9f16.js';
import './breakpoints-332702ed.js';
import './number-4398f2e1.js';
import './pixel-f32c07ce.js';
import './array-7888f339.js';
import './feature-flag-controller-30f7b625.js';
import './index-bfc6dfa2.js';
import './state-border-formatter-afac8d33.js';

var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
class VegaFlagIconRenderer extends VegaSlimmer {
  render() {
    const icon = VegaInternalIconManager.getIconKey(this.country);
    const hasIcon = VegaIconManager.hasIcon(icon);
    const height = formatAndValidResponsiveToken(this.size, 'widthAndHeight');
    const width = `calc(${height} * 4 / 3)`;
    if (!hasIcon)
      return (h("vega-skeleton", { type: "image", corners: "rounded-2", height: height, width: width }));
    return h("vega-icon", { icon: icon, size: this.size, style: { '--vega-icon-width': width } });
  }
}
__decorate$2([
  MapToComponentField()
], VegaFlagIconRenderer.prototype, "size", void 0);
__decorate$2([
  MapToComponentField()
], VegaFlagIconRenderer.prototype, "country", void 0);

var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
/**
 * The function `dynamicLoadTheCountryFlags` will dynamic import and register flags of all countries at once
 */
async function dynamicLoadTheCountryFlags() {
  try {
    const countryFlags = (await import('./country-flags-39dbfa43.js')).CountryFlags;
    VegaInternalIconManager.register(countryFlags);
    ChangeManager.notify(FLAG_ICON_LOADED, {});
  }
  catch (err) {
    /* istanbul ignore next */
    LogUtility.error(`Error loading flag module:`, err);
  }
}
/**
 * The `VegaFlagIconController` class in TypeScript manage country flag and
 * country codes, dynamic import the flags of all countries and get the country icon by specific code.
 */
class VegaFlagIconController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * Determines whether the observer should accept changes.
     *
     * @returns {boolean} Always returns true in the current implementation.
     */
    this.isAcceptObserver = () => {
      return true;
    };
    /**
     * This function listens whether the logo icon is imported asynchronously.
     */
    this.listenerCallback = () => {
      forceUpdate(this.host);
    };
  }
  /**
   * componentWillLoad
   */
  componentWillLoad() {
    if (!this.country)
      return;
    const hasIcon = this.isFlagForCountryCodeLoaded(this.country);
    if (!hasIcon)
      this.registerObserver();
  }
  /**
   * disconnectedCallback
   */
  unRegisterObserver() {
    if (this.observer) {
      ChangeManager.unregister(FLAG_ICON_LOADED, this.observer);
      this.observer = null;
    }
  }
  /**
   * The function creates an observer to observe the subject of FLAG_ICON_LOADED.
   */
  registerObserver() {
    this.observer = new Observer(this.isAcceptObserver.bind(this), this.listenerCallback.bind(this));
    ChangeManager.register(FLAG_ICON_LOADED, this.observer);
  }
  /**
   * Checks if the country icon exists by country code.
   *
   * @param {VegaCountryCode} countryCode - The `country` parameter is of type `VegaCountryCode`, which is likely a
   * custom data type representing a country code.
   * @returns {boolean} return the icon is exist or not.
   */
  isFlagForCountryCodeLoaded(countryCode) {
    const icon = VegaInternalIconManager.getIconKey(countryCode);
    return VegaInternalIconManager.hasIcon(icon);
  }
}
(() => {
  void dynamicLoadTheCountryFlags();
})();
__decorate$1([
  MapToComponentField()
], VegaFlagIconController.prototype, "host", void 0);
__decorate$1([
  MapToComponentField()
], VegaFlagIconController.prototype, "country", void 0);
__decorate$1([
  MapToComponentMethod('componentWillLoad')
], VegaFlagIconController.prototype, "componentWillLoad", null);
__decorate$1([
  MapToComponentMethod('disconnectedCallback')
], VegaFlagIconController.prototype, "unRegisterObserver", null);

const vegaFlagIconCss = ":host{display:inline-block}:host vega-icon,:host vega-skeleton,:host svg{display:block;border-radius:2px}:host vega-icon{width:var(--vega-icon-width, 24px)}";

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
    r = Reflect.decorate(decorators, target, key, desc);
  else
    for (var i = decorators.length - 1; i >= 0; i--)
      if (d = decorators[i])
        r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const VegaFlagIcon = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.globalSlimmers = {};
    this.renderer = new VegaFlagIconRenderer();
    this.vegaFlagIconController = new VegaFlagIconController();
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer();
    /**
     * Specifies the width and height of the icon.
     *
     * @vegaVersion 2.46.0
     */
    this.size = 'size-16';
  }
  render() {
    return sanitizeVegaComponent(h(Host, null, this.renderer.render()), this.host);
  }
  get host() { return getElement(this); }
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaFlagIcon.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaFlagIcon.prototype, "renderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaFlagIcon.prototype, "vegaFlagIconController", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaFlagIcon.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
VegaFlagIcon.style = vegaFlagIconCss;

export { VegaFlagIcon as vega_flag_icon };
