import type CSVLayer from "../../layers/CSVLayer.js";
import type FeatureLayer from "../../layers/FeatureLayer.js";
import type GeoJSONLayer from "../../layers/GeoJSONLayer.js";
import type ImageryLayer from "../../layers/ImageryLayer.js";
import type SceneLayer from "../../layers/SceneLayer.js";
import type WFSLayer from "../../layers/WFSLayer.js";
import type CatalogFootprintLayer from "../../layers/catalog/CatalogFootprintLayer.js";
import type KnowledgeGraphSublayer from "../../layers/knowledgeGraph/KnowledgeGraphSublayer.js";
import type Field from "../../layers/support/Field.js";
import type EditorColumn from "./Grid/EditorColumn.js";
import type FieldColumnTemplate from "./support/FieldColumnTemplate.js";
import type { MapViewOrSceneView } from "../../views/MapViewOrSceneView.js";
import type { EditorColumnProperties } from "./Grid/EditorColumn.js";
import type { FieldValueFormatFunction } from "./support/types.js";
import type { FieldProperties } from "../../layers/support/Field.js";

export interface FieldColumnProperties extends EditorColumnProperties, Partial<Pick<FieldColumn, "editable" | "layer" | "required" | "template" | "view">> {
  /** The [Field](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html) associated with this column. */
  field?: FieldProperties;
  /**
   * Indicates whether the column is sortable.
   *
   * @default true
   */
  sortable?: boolean;
}

/**
 * The [FieldColumn](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-FieldColumn.html) class works
 * with the [FeatureTable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable.html) and provides the underlying
 * logic for column behavior.
 *
 * > [!WARNING]
 * >
 * > This class should be used for observing potential changes. Any configuration and changes to the field columns should be done handled via the [TableTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-TableTemplate.html) and the [FieldColumnTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html) class.
 *
 * @since 4.16
 * @see [FeatureTable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable.html)
 * @see [FeatureTableViewModel](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-FeatureTableViewModel.html)
 * @see [FieldColumnTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html)
 * @see [Field](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html)
 */
export default class FieldColumn extends EditorColumn {
  constructor(properties?: FieldColumnProperties);
  /** The display name for the field. */
  get alias(): string | null | undefined;
  /** The default value set for the field. */
  get defaultValue(): number | string | null | undefined;
  /**
   * Indicates whether the field is editable. Editing permissions can be broken down
   * with the following levels of priority:
   *
   * 1. [Field](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html) - This is derived
   * from the [FeatureLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html) or [SceneLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-SceneLayer.html). It takes what is set in the
   * [Field.editable](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html#editable) property. This
   * must always be `true` for editing to be enabled. This can be overridden using a
   * [field column template](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html).
   * 2. [Template](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html) - The editable
   * permissions on a field can be configured by setting the
   * [FieldColumnTemplate.editable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html#editable) property
   * of the [FieldColumnTemplate](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html).
   * 3. [FeatureTable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable.html) - The [FeatureTable.editingEnabled](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable.html#editingEnabled)
   * property must be set on the table in order for any type of editing to be enabled.
   *
   * For example, if table editing is disabled in the widget, i.e. `enableEditing` is not set,
   * it is still possible to enable editing for a specific column by setting the
   * [FieldColumnTemplate.editable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html#editable) property. Vice versa
   * is also true, if table editing is enabled, a field template can be used to disable editing for a specific column.
   *
   * > [!WARNING]
   * >
   * > Ultimately, if the service's field is not editable, it is not possible to override its permissions
   * > using one of the options above.
   *
   * @see [FieldColumnTemplate.editable](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-FieldColumnTemplate.html#editable)
   */
  editable: boolean;
  /**
   * The sanitized [description](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-FieldColumn.html#description), describing the purpose of each column. This takes into account the optional values of both [the columns's template description](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-ColumnTemplateBase.html#description) and the value of the [field's description](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html#description). The template description takes precedence over the field's description as to allow for customizing the column's description.
   *
   * @since 4.31
   * @see [ColumnTemplateBase.description](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-support-ColumnTemplateBase.html#description)
   * @see [Field.description](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html#description)
   */
  get effectiveDescription(): string | null | undefined;
  /** The [Field](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Field.html) associated with this column. */
  get field(): Field;
  set field(value: FieldProperties);
  /**
   * Custom function for rendering cell content that is called when the column is rendered in the table. The function should return the formatted content to display within a table's cell. This can be a string, number, an HTML element, or equivalent node type (e.g. a [Calcite component](https://developers.arcgis.com/calcite-design-system/components/)). If the content is an HTML element, it is appended to the root element. If the content is a string or number, it is set as the innerHTML of the root element. If the content is `null`, the root element is cleared. If the content is `undefined`, the root element is not modified. This property is useful when you want to customize the cell content. For example, you can use this property to create a custom cell renderer that displays a progress bar in the cell. The progress bar can be used to show the progress of a task.
   *
   * @example
   * // The following example demonstrates how to use the formatFunction property to create a custom cell renderer that displays a progress bar in the cell. The progress bar can be used to show the progress of a task.
   * column.formatFunction = ({ column, feature, index, value })=> {
   *   const progress = document.createElement("progress");
   *   progress.max = 100;
   *   progress.value = value;
   *   return progress;
   * };
   */
  get formatFunction(): FieldValueFormatFunction | null | undefined;
  /**
   * The associated [CatalogFootprintLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-catalog-CatalogFootprintLayer.html), [CSVLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-CSVLayer.html), [FeatureLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html), [GeoJSONLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GeoJSONLayer.html), [ImageryLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-ImageryLayer.html),
   * [KnowledgeGraphSublayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-knowledgeGraph-KnowledgeGraphSublayer.html), [SceneLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-SceneLayer.html), or [WFSLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WFSLayer.html) containing the fields and attributes to display within the widget.
   */
  accessor layer: CatalogFootprintLayer | CSVLayer | FeatureLayer | GeoJSONLayer | ImageryLayer | KnowledgeGraphSublayer | SceneLayer | WFSLayer;
  /** Restricts the input length for the column. */
  get maxLength(): number;
  /** Restricts the input length for the column. */
  get minLength(): number | null | undefined;
  /**
   * The name of the field.
   *
   * @deprecated since version 4.30, use [fieldName](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-FieldColumn.html#fieldName) instead.
   */
  get name(): string | null | undefined;
  /** Indicates if the field can accept `null` values. */
  get nullable(): boolean;
  /** Indicates whether a value is required when editing feature attributes within the table's cell. */
  required: boolean;
  /**
   * Indicates whether the column is sortable.
   *
   * @default true
   */
  accessor sortable: boolean;
  /**
   * A configurable template for the table column. The template allows for customizing the appearance of the column. Once the template is set, it will override the default appearance and will remain as such once the table is created. Any information regarding the column's current state can be accessed using the [Column](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-FeatureTable-Grid-Column.html) class.
   *
   * > [!WARNING]
   * >
   * > Templates should be used primarily for initial column configuration and should not be used for observing changes.
   *
   * @since 4.28
   */
  accessor template: FieldColumnTemplate | null | undefined;
  /** A reference to the [MapView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html) or [SceneView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html). */
  accessor view: MapViewOrSceneView | null | undefined;
}