import { View, Property, EventData, ObservableArray } from "@nativescript/core";

/**
* Defines the possible values for the {@link displayMode} property
* applied to the {@link RadAutoCompleteTextView}.
*/
export enum AutoCompleteDisplayMode {
    /**
    * Selected items are shown as tokens. Multiple selection is allowed.
    */
    Tokens = "Tokens",
    /**
    * Only one item can be selected. The selected item is shown as plain text.
    */
    Plain = "Plain"
}

/**
* Defines the possible values for the {@link suggestMode} property
* applied to the {@link RadAutoCompleteTextView}.
*/
export enum AutoCompleteSuggestMode {
    /**
    * Shows suggestions as a drop down below the RadAutoCompleteTextView.
    */
    Suggest = "Suggest",
    /**
    * Shows only one suggestion as text appended directly to the input.
    */
    Append = "Append",

    /**
    * Applies both suggest and append mode.
    */
    SuggestAppend = "SuggestAppend"
}

/**
* Defines the possible values for the {@link layoutMode} property
* applied to the {@link RadAutoCompleteTextView}.
*/
export enum AutoCompleteLayoutMode {
    /**
    * Horizontal layout.
    */
    Horizontal = "Horizontal",
    /**
    * Wrap layout.
    */
    Wrap = "Wrap"
}

/**
* Defines the possible values for the {@link completionMode} property
* applied to the {@link RadAutoCompleteTextView}.
*/
export enum AutoCompleteCompletionMode {
    /**
    * Suggestions are filtered by matching the first letters with the typed text.
    */
    StartsWith = "StartsWith",
    /**
    * Suggestions are filtered by matching the containing letters with the typed text.
    */
    Contains = "Contains"
}

/**
 * Defines the different view types that {@link RadAutoCompleteTextView} can display in various scenarios.
 */
export enum AutoCompleteViewType {
    ItemView = "ItemView"
}

/**
 * The view holder in which suggestions are displayed in Suggest mode.
 */
export class SuggestionView {
    /**
     * The native android object.
     */
    android: any;
    /**
     * The native ios object.
     */
    ios: any;
    /**
     * The height of the suggestion view.
     */
    suggestionViewHeight: number;
    /**
     * Suggestion template used to display each suggestion in the drop dow.
     */
    suggestionItemTemplate: string;
}

/**
 * Data model describing the object which represents a single suggestion item.
 */
export class TokenModel {

    /**
     * Default constructor.
     */
    constructor(text: string, image: string);

    /**
     * Item image.
     */
    image: string;
    /**
     * Item text.
     */
    text: string;
    /**
     * Native ios object.
     */
    ios: any;
    /**
     * Native android object.
     */
    android: any;
}

/**
 * Generic scheme for event arguments provided to handlers of events exposed
 * by a {@link RadListView}.
 */
export class CollectionViewEventData implements EventData {

    /**
    *Returns the name of the event that has been fired.
    */
    eventName: string;

    /**
    * The object that fires the event.
    */
    object: any;

    /**
    * Gets the index of the item in the source to which the event relates.
    */
    index: number;

    /**
    * Gets the index of the data group (if present) to which the event relates.
    * Returns -1 if there is no group.
    */
    groupIndex: number;

    /**
    * Might point to an object related to a specific event.
    */
    data: any;

    /**
    * Returns a boolean value which is interpreted in the context with the event.
    */
    returnValue: any;

    /**
    * The NativeScript object that raised the event.
    */
    view: View;

    /**
    * The native object that raised the event.
    */
    android: any;

    /**
    * The native object that raised the event
    */
    ios: any;
}

/**
* Instances of this class are exposed by the data property of the
* {@link AutoCompleteEventData} coming when the events are
* fired.
*/
export class AutoCompleteEventData implements EventData {
    /**
     * The name of the event.
     */
    eventName: string;
    /**
    * The object that fires the event.
    */
    object: any;
    /**
    * The token associated with this event.
    */
    token: TokenModel;
    /**
    * The text associated with this event.
    */
    text: string;
}

/**
 * RadAutoCompleteTextView provides means to perform easy
 * filtering of data and completion suggestion's according to typed text by the user.
 * Provides tokens, layouts, completion modes.
 */
export class RadAutoCompleteTextView extends View {
    /**
     * The event fired when token is removed.
     */
    static tokenRemovedEvent: string;
    /**
     * The event fired when token is added.
     */
    static tokenAddedEvent: string;
    /**
     * The event fired when token is selected.
     */
    static tokenSelectedEvent: string;
    /**
     * The event fired when token is deselected.
     */
    static tokenDeselectedEvent: string;
    /**
     * The event fired when an item is chosen from the suggestions list.
     */
    static didAutoCompleteEvent: string;
    /**
     * The event fired when the text of {@link RadAutoCompleteTextView} is changed.
     */
    static textChangedEvent: string;
    /**
     * The event fired when suggestion view has become visible.
     */
    static suggestionViewBecameVisibleEvent: string;

    /**
     * The event fired when the suggestion view is being populated.
     */
    static itemLoadingEvent: string;

    /**
    * Identifies the {@link itemTemplate} dependency property.
    */
    static loadSuggestionsAsyncProperty: Property<RadAutoCompleteTextView, any>;

    /**
     * Items used to provide suggestions.
     */
    items: ObservableArray<TokenModel>;
    /**
     * The suggestion view holding suggestion items in Suggest mode.
     */
    suggestionView: any;
    /**
     * Defines how selected items are shown. Default value is Plain.
     */
    displayMode: AutoCompleteDisplayMode;
    /**
     * Defines the criteria on which suggestions are being filtered.
     */
    completionMode: AutoCompleteCompletionMode;
    /**
     * Defines the layout of the tokens.
     */
    layoutMode: AutoCompleteLayoutMode;
    /**
     * Defines how suggestion are presented.
     */
    suggestMode: AutoCompleteSuggestMode;
    /**
     * Sets a hint for the {@link RadAutoCompleteTextView}. That is the text that is displayed when no text is typed.
     */
    hint: string;
    /**
     * Gets/sets the current text for the {@link RadAutoCompleteTextView}.
     */
    text: string;
    /**
     * Sets the minimal count of typed characters for the  {@link RadAutoCompleteTextView} to start filtering.
     */
    minimumCharactersToSearch: number;

    /**
     * Sets the text displayed when there are no matches for the current input.
     */
    noResultsText: string;

    /**
     * Sets if the 'close' button in the text area of the {@link RadAutoCompleteTextView} is shown.
     */
    showCloseButton: boolean;

    /**
     * Sets the source of the Image for the 'close' button in the text area of the {@link RadAutoCompleteTextView}.
     */
    closeButtonImageSrc: string;

    /**
     * Sets or gets a function that is used by the {@link RadAutoCompleteTextView} to retrieve its items.
     */
    loadSuggestionsAsync: any;

    /**
     * Sets or gets if the {@link RadAutoCompleteTextView} will be enabled or disabled.
     */
    readOnly: boolean;

    /**
     * Gets a list of the items filtered by the {@link RadAutoCompleteTextView}'s current input.
     */
    filteredItems: Array<TokenModel>;

    /**
     * Gets a list of all currently selected tokens.
     */
    selectedTokens: Array<TokenModel>;

    /**
     * Adds  token.
     */
    addToken(token: TokenModel);
    /**
     * Inserts token at specified index.
     */
    insertTokenAtIndex(token: TokenModel, index: number);
    /**
     * Removes specified token.
     */
    removeToken(token: TokenModel);
    /**
     * Removes token at specified index.
     */
    removeTokenAtIndex(index: number);
    /**
     * Removes all tokens.
     */
    removeAllTokens();
    /**
     * Returns all tokens.
     */
    tokens();
    /**
     * Returns token at specified index.
     */
    tokenAtIndex(index: number);

    /**
     * Resets the RadAutoCompleteTextView component.
     */
    resetAutoComplete();

    /**
     * Gets or sets the item view loaded used by the @link RadListView} when creating its item views.
     */
    itemViewLoader: (viewType) => View;
}