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. */
export interface PopupTemplateCreatorEvent {
  /** The [Graphic](https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html) used to represent the feature. */
  graphic: Graphic;
}

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

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.
 */
export type PopupTemplateContentCreatorFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateContentCreated | PopupTemplateContentCreatorPromise;

export type PopupTemplateContentCreator = PopupTemplateContentCreatorFunction | PopupTemplateContentCreatorPromise | PopupTemplateContentCreated;

export type PopupTemplateContentResolved = PopupTemplateContentCreated | Content[];

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. */
export type PopupTemplateContentFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateContentResolved | PopupTemplateContentPromise;

export type PopupTemplateContent = PopupTemplateContentResolved | PopupTemplateContentPromise | PopupTemplateContentFunction;

export type PopupTemplateTitleResolved = string;

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. */
export type PopupTemplateTitleFunction = (event: PopupTemplateCreatorEvent) => PopupTemplateTitleResolved | PopupTemplateTitlePromise;

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.
 */
export type PopupTemplateContentDestroyer = (event: PopupTemplateCreatorEvent) => void;