import type Graphic from "../Graphic.js";
import type Content from "./content/Content.js";
import type Widget from "../widgets/Widget.js";

/**
 * The event that contains the [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
 *
 * @since 5.0
 */
export interface PopupTemplateCreatorEvent {
  /**
   * The [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
   *
   * @since 5.0
   */
  graphic: Graphic;
}

/**
 * Custom element content.
 *
 * @since 5.0
 */
export type PopupTemplateContentCreated = string | HTMLElement | Widget | null | undefined;

/** @since 5.0 */
export type PopupTemplateContentCreatorPromise = Promise<PopupTemplateContentCreated>;

/**
 * The function that is called to create the custom content element.
 *
 * @param event - The event that contains the [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
 * @returns The created custom content element.
 * @since 5.0
 */
export type PopupTemplateContentCreatorFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateContentCreated | PopupTemplateContentCreatorPromise;

/** @since 5.0 */
export type PopupTemplateContentCreator = PopupTemplateContentCreatorFunction | PopupTemplateContentCreatorPromise | PopupTemplateContentCreated;

/** @since 5.0 */
export type PopupTemplateContentResolved = PopupTemplateContentCreated | Content[];

/** @since 5.0 */
export type PopupTemplateContentPromise = Promise<PopupTemplateContentResolved>;

/**
 * @param event - The event that contains the [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
 * @since 5.0
 */
export type PopupTemplateContentFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateContentResolved | PopupTemplateContentPromise;

/** @since 5.0 */
export type PopupTemplateContent = PopupTemplateContentResolved | PopupTemplateContentPromise | PopupTemplateContentFunction;

/** @since 5.0 */
export type PopupTemplateTitleResolved = string;

/** @since 5.0 */
export type PopupTemplateTitlePromise = Promise<PopupTemplateTitleResolved>;

/**
 * @param event - The event that contains the [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
 * @since 5.0
 */
export type PopupTemplateTitleFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateTitleResolved | PopupTemplateTitlePromise;

/** @since 5.0 */
export type PopupTemplateTitle = PopupTemplateTitleResolved | PopupTemplateTitlePromise | PopupTemplateTitleFunction;

/**
 * The function that is called to destroy the custom content element.
 *
 * @param event - The event that contains the [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature.
 * @since 5.0
 */
export type PopupTemplateContentDestroyer = (event: PopupTemplateCreatorEvent) => void;