Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenClearButton = exports.ClearButton = exports.NoResultsLabel = exports.Token = exports.RadAutoCompleteTextView = exports.SuggestionView = exports.TokenModel = exports.knownTemplates = void 0;
var core_1 = require("@nativescript/core");
function getSdkApiLevel() {
    return android.os.Build.VERSION.SDK_INT;
}
var commonModule = require("./ui-autocomplete.common");
__exportStar(require("./ui-autocomplete.common"), exports);
var knownTemplates;
(function (knownTemplates) {
    knownTemplates.suggestionItemTemplate = "suggestionItemTemplate";
})(knownTemplates = exports.knownTemplates || (exports.knownTemplates = {}));
var TokenModel = /** @class */ (function (_super) {
    __extends(TokenModel, _super);
    function TokenModel(text, imageName) {
        var _this = _super.call(this, text, imageName) || this;
        if (imageName !== null && imageName !== undefined) {
            var drawable = RadAutoCompleteTextView.resolveDrawableFromResource(imageName);
            _this._android = new com.telerik.widget.autocomplete.TokenModel(text, drawable);
            _this._android.setNsImageName(imageName);
        }
        else {
            _this._android = new com.telerik.widget.autocomplete.TokenModel(text, null);
        }
        return _this;
    }
    Object.defineProperty(TokenModel.prototype, "android", {
        get: function () {
            return this._android;
        },
        enumerable: false,
        configurable: true
    });
    return TokenModel;
}(commonModule.TokenModel));
exports.TokenModel = TokenModel;
function nativeModelToNSModel(nativeItem, items) {
    if (!items) {
        return null;
    }
    for (var i = 0; i < items.length; i++) {
        var tokenModel = void 0;
        if (items instanceof core_1.ObservableArray) {
            tokenModel = items.getItem(i);
        }
        else {
            tokenModel = items[i];
        }
        if (+tokenModel.android.tokenId() === +nativeItem.tokenId()) {
            return tokenModel;
        }
    }
    return null;
}
var SuggestionView = /** @class */ (function (_super) {
    __extends(SuggestionView, _super);
    function SuggestionView() {
        return _super.call(this) || this;
    }
    Object.defineProperty(SuggestionView.prototype, "android", {
        get: function () {
            return this._android;
        },
        set: function (value) {
            this._android = value;
            this.setNativeView(this.getNativeBackgroundView());
        },
        enumerable: false,
        configurable: true
    });
    SuggestionView.prototype.createNativeView = function () {
        return this.owner ? this.getNativeBackgroundView() : _super.prototype.createNativeView.call(this);
    };
    SuggestionView.prototype.getNativeBackgroundView = function () {
        return this.owner.android.getPopUp().getContentView();
    };
    SuggestionView.prototype[core_1.heightProperty.getDefault] = function () {
        return this.suggestionViewHeight;
    };
    SuggestionView.prototype[core_1.heightProperty.setNative] = function (value) {
        this.suggestionViewHeight = value;
    };
    SuggestionView.prototype.onSuggestionViewHeightChanged = function (oldValue, newValue) {
        this.updateHeight();
    };
    SuggestionView.prototype.updateHeight = function () {
        if (this.owner && this.owner.nativeView && this.suggestionViewHeight) {
            var heightInPixels = core_1.Utils.layout.toDevicePixels(this.suggestionViewHeight);
            this.owner.nativeView.setSuggestionViewHeight(heightInPixels);
        }
    };
    return SuggestionView;
}(commonModule.SuggestionView));
exports.SuggestionView = SuggestionView;
var AutoCompleteAdapterClass;
function ensureAutoCompleteAdapter() {
    if (AutoCompleteAdapterClass) {
        return AutoCompleteAdapterClass;
    }
    var AutoCompleteAdapter = /** @class */ (function (_super) {
        __extends(AutoCompleteAdapter, _super);
        function AutoCompleteAdapter(owner, items, isRemote) {
            var _this = _super.call(this, core_1.Utils.android.getApplicationContext(), items, null) || this;
            _this.suggestionsMap = {};
            _this.owner = owner;
            _this.isRemote = isRemote;
            return global.__native(_this);
        }
        AutoCompleteAdapter.prototype.onCreateViewHolder = function (parent, viewType) {
            var view = this.owner.getViewForViewType(commonModule.AutoCompleteViewType.ItemView);
            var parentView = new core_1.StackLayout();
            parentView.orientation = "vertical";
            commonModule.setupCssScope(this.owner, view);
            parentView.addChild(view);
            this.owner.suggestionView._addView(parentView);
            var layoutParams = new org.nativescript.widgets.CommonLayoutParams();
            layoutParams.width = org.nativescript.widgets.CommonLayoutParams.MATCH_PARENT;
            layoutParams.height = org.nativescript.widgets.CommonLayoutParams.WRAP_CONTENT;
            var holder = new com.telerik.widget.autocomplete.SuggestionItemViewHolder(parentView.android);
            parentView.android.setLayoutParams(layoutParams);
            holder['nsView'] = parentView;
            return holder;
        };
        AutoCompleteAdapter.prototype.onBindViewHolder = function (holder, position) {
            var nativeItem = this.getFilteredList().get(position);
            var model = nativeModelToNSModel(nativeItem, this.owner.filteredItems);
            if (holder.nsView !== undefined) {
                holder.nsView.bindingContext = model;
                this.attachOnClickListener(holder.itemView);
                var args = {
                    eventName: commonModule.RadAutoCompleteTextView.itemLoadingEvent,
                    index: position,
                    view: holder.nsView._subViews[0],
                    android: holder,
                    data: model
                };
                this.owner.notify(args);
            }
        };
        AutoCompleteAdapter.prototype.filter = function (charText) {
            if (!this.isRemote) {
                _super.prototype.filter.call(this, charText);
                var nsResult = new Array();
                for (var i = 0; i < this.getFilteredList().size(); i++) {
                    var nativeItem = this.getFilteredList().get(i);
                    var model = nativeModelToNSModel(nativeItem, this.owner.items);
                    nsResult.push(model);
                }
                this.owner._filteredItems = nsResult;
                return;
            }
            this.owner.android.getAdapter().getFilteredList().clear();
            charText = charText.toLowerCase();
            var self = this;
            if (charText.length !== 0) {
                this.owner.asyncCall(charText).then(function (items) {
                    var result = new java.util.ArrayList();
                    var nsResult = new Array();
                    if (self.owner.completionMode === commonModule.AutoCompleteCompletionMode.StartsWith) {
                        for (var i = 0; i < items.length; i++) {
                            var current = items[i];
                            var upperCase = current.android.getText().toLowerCase();
                            if (upperCase.startsWith(charText)) {
                                result.add(current.android);
                                nsResult.push(current);
                            }
                        }
                    }
                    else {
                        for (var i = 0; i < items.length; i++) {
                            var current = items[i];
                            var upperCase = current.android.getText().toLowerCase();
                            if (upperCase.indexOf(charText !== -1)) {
                                result.add(current.android);
                                nsResult.push(current);
                            }
                        }
                    }
                    if (self.owner.isLoaded) {
                        self.setItems(result);
                        self.owner.android.getAdapter().setFilteredList(result);
                        self.owner.android.resolveAfterFilter(self.owner.android.getTextField().getText().toString(), true);
                        self.owner._filteredItems = nsResult;
                    }
                });
            }
        };
        return AutoCompleteAdapter;
    }(com.telerik.widget.autocomplete.AutoCompleteAdapter));
    AutoCompleteAdapterClass = AutoCompleteAdapter;
}
var AutoCompleteShowSuggestionListener;
var AutoCompleteOnFocusChangeListener;
var AutoCompleteTextChangedListener;
var AutoCompleteTokenAddedAtIndexListener;
var AutoCompleteTokenSelectedListener;
var AutoCompleteTokenDeselectedListener;
var AutoCompleteTokenRemovedListener;
var AutoCompleteDidAutoCompleteTokenListener;
function initListeners() {
    if (!AutoCompleteShowSuggestionListener) {
        var AutoCompleteShowSuggestionListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteShowSuggestionListenerImpl, _super);
            function AutoCompleteShowSuggestionListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteShowSuggestionListenerImpl.prototype.onShowSuggestionList = function (autoComplete, suggestions) {
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.suggestionViewBecameVisibleEvent, undefined, undefined);
                this.owner.notify(args);
            };
            AutoCompleteShowSuggestionListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.ShowSuggestionListListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteShowSuggestionListenerImpl);
            return AutoCompleteShowSuggestionListenerImpl;
        }(java.lang.Object));
        AutoCompleteShowSuggestionListener = AutoCompleteShowSuggestionListenerImpl;
    }
    if (!AutoCompleteOnFocusChangeListener) {
        var AutoCompleteOnFocusChangeListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteOnFocusChangeListenerImpl, _super);
            function AutoCompleteOnFocusChangeListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteOnFocusChangeListenerImpl.prototype.onFocusChange = function (view, hasFocus) {
                if (hasFocus) {
                    this.owner.notify({ eventName: core_1.EditableTextBase.focusEvent, object: this.owner });
                }
                else {
                    this.owner.notify({ eventName: core_1.EditableTextBase.blurEvent, object: this.owner });
                }
            };
            AutoCompleteOnFocusChangeListenerImpl = __decorate([
                Interfaces([android.view.View.OnFocusChangeListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteOnFocusChangeListenerImpl);
            return AutoCompleteOnFocusChangeListenerImpl;
        }(java.lang.Object));
        AutoCompleteOnFocusChangeListener = AutoCompleteOnFocusChangeListenerImpl;
    }
    if (!AutoCompleteTextChangedListener) {
        var AutoCompleteTextChangedListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteTextChangedListenerImpl, _super);
            function AutoCompleteTextChangedListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteTextChangedListenerImpl.prototype.onTextChanged = function (autoComplete, text) {
                if (this.owner.text !== text) {
                    var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.textChangedEvent, text, undefined);
                    this.owner.text = text;
                    this.owner.notify(args);
                }
            };
            AutoCompleteTextChangedListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.TextChangedListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteTextChangedListenerImpl);
            return AutoCompleteTextChangedListenerImpl;
        }(java.lang.Object));
        AutoCompleteTextChangedListener = AutoCompleteTextChangedListenerImpl;
    }
    if (!AutoCompleteTokenAddedAtIndexListener) {
        var AutoCompleteTokenAddedAtIndexListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteTokenAddedAtIndexListenerImpl, _super);
            function AutoCompleteTokenAddedAtIndexListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteTokenAddedAtIndexListenerImpl.prototype.onTokenAddedAtIndex = function (autoComplete, token, index) {
                var tokenModel = nativeModelToNSModel(token, this.owner.filteredItems);
                var nativeTokenView = this.owner.android.getTokenAt(index);
                var tokenView = new Token(nativeTokenView);
                this.owner._tokens.push(tokenView);
                commonModule.setupCssScope(this.owner, tokenView);
                commonModule.setupCssScope(this.owner, tokenView.clearButton);
                this.owner._addView(tokenView);
                this.owner._onCssStateChange();
                this.owner._selectedTokens.push(tokenModel);
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.tokenAddedEvent, token.getText(), tokenModel);
                this.owner.notify(args);
            };
            AutoCompleteTokenAddedAtIndexListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.TokenAddedAtIndexListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteTokenAddedAtIndexListenerImpl);
            return AutoCompleteTokenAddedAtIndexListenerImpl;
        }(java.lang.Object));
        AutoCompleteTokenAddedAtIndexListener = AutoCompleteTokenAddedAtIndexListenerImpl;
    }
    if (!AutoCompleteTokenSelectedListener) {
        var AutoCompleteTokenSelectedListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteTokenSelectedListenerImpl, _super);
            function AutoCompleteTokenSelectedListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteTokenSelectedListenerImpl.prototype.onTokenSelected = function (autoComplete, token, tokenView) {
                var tokenModel = nativeModelToNSModel(token, this.owner._selectedTokens);
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.tokenSelectedEvent, token.getText(), tokenModel);
                this.owner.notify(args);
                for (var i = 0; i < this.owner._tokens.length; i++) {
                    if (this.owner._tokens[i].android === tokenView) {
                        this.owner._tokens[i]._goToVisualState("selected");
                    }
                }
            };
            AutoCompleteTokenSelectedListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.TokenSelectedListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteTokenSelectedListenerImpl);
            return AutoCompleteTokenSelectedListenerImpl;
        }(java.lang.Object));
        AutoCompleteTokenSelectedListener = AutoCompleteTokenSelectedListenerImpl;
    }
    if (!AutoCompleteTokenDeselectedListener) {
        var AutoCompleteTokenDeselectedListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteTokenDeselectedListenerImpl, _super);
            function AutoCompleteTokenDeselectedListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteTokenDeselectedListenerImpl.prototype.onTokenDeselected = function (autoComplete, token, tokenView) {
                var tokenModel = nativeModelToNSModel(token, this.owner._selectedTokens);
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.tokenDeselectedEvent, token.getText(), tokenModel);
                this.owner.notify(args);
                for (var i = 0; i < this.owner._tokens.length; i++) {
                    if (this.owner._tokens[i].android === tokenView) {
                        this.owner._tokens[i]._goToVisualState("normal");
                    }
                }
            };
            AutoCompleteTokenDeselectedListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.TokenDeselectedListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteTokenDeselectedListenerImpl);
            return AutoCompleteTokenDeselectedListenerImpl;
        }(java.lang.Object));
        AutoCompleteTokenDeselectedListener = AutoCompleteTokenDeselectedListenerImpl;
    }
    if (!AutoCompleteTokenRemovedListener) {
        var AutoCompleteTokenRemovedListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteTokenRemovedListenerImpl, _super);
            function AutoCompleteTokenRemovedListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteTokenRemovedListenerImpl.prototype.onTokenRemoved = function (autoComplete, token) {
                var tokenModel = nativeModelToNSModel(token, this.owner._selectedTokens);
                var indexToRemove = this.owner._selectedTokens.indexOf(tokenModel);
                if (indexToRemove >= 0) {
                    this.owner._selectedTokens.splice(indexToRemove, 1);
                }
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.tokenRemovedEvent, token.getText(), tokenModel);
                this.owner.notify(args);
            };
            AutoCompleteTokenRemovedListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.TokenRemovedListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteTokenRemovedListenerImpl);
            return AutoCompleteTokenRemovedListenerImpl;
        }(java.lang.Object));
        AutoCompleteTokenRemovedListener = AutoCompleteTokenRemovedListenerImpl;
    }
    if (!AutoCompleteDidAutoCompleteTokenListener) {
        var AutoCompleteDidAutoCompleteTokenListenerImpl = /** @class */ (function (_super) {
            __extends(AutoCompleteDidAutoCompleteTokenListenerImpl, _super);
            function AutoCompleteDidAutoCompleteTokenListenerImpl(owner) {
                var _this = _super.call(this) || this;
                _this.owner = owner;
                return global.__native(_this);
            }
            AutoCompleteDidAutoCompleteTokenListenerImpl.prototype.onDidAutoComplete = function (autoComplete, token) {
                var tokenModel = nativeModelToNSModel(token, this.owner.filteredItems);
                var args = new commonModule.AutoCompleteEventData(this.owner, commonModule.RadAutoCompleteTextView.didAutoCompleteEvent, token.getText(), tokenModel);
                this.owner.notify(args);
            };
            AutoCompleteDidAutoCompleteTokenListenerImpl = __decorate([
                Interfaces([com.telerik.widget.autocomplete.DidAutoCompleteTokenListener]),
                __metadata("design:paramtypes", [RadAutoCompleteTextView])
            ], AutoCompleteDidAutoCompleteTokenListenerImpl);
            return AutoCompleteDidAutoCompleteTokenListenerImpl;
        }(java.lang.Object));
        AutoCompleteDidAutoCompleteTokenListener = AutoCompleteDidAutoCompleteTokenListenerImpl;
    }
}
var RadAutoCompleteTextView = /** @class */ (function (_super) {
    __extends(RadAutoCompleteTextView, _super);
    function RadAutoCompleteTextView() {
        var _this = _super.call(this) || this;
        _this._selectedTokens = new Array();
        _this._androidViewId = -1;
        return _this;
    }
    Object.defineProperty(RadAutoCompleteTextView.prototype, "clearButton", {
        get: function () {
            return this._clearButton;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RadAutoCompleteTextView.prototype, "noResultsLabel", {
        get: function () {
            return this._noResultsLabel;
        },
        enumerable: false,
        configurable: true
    });
    RadAutoCompleteTextView.prototype.createNativeView = function () {
        this._android = new com.telerik.widget.autocomplete.RadAutoCompleteTextView(this._context);
        initListeners();
        this._android._showSuggestionListener = new AutoCompleteShowSuggestionListener(this);
        this._android._onFocusChangeListener = new AutoCompleteOnFocusChangeListener(this);
        this._android._textChangedListener = new AutoCompleteTextChangedListener(this);
        this._android._tokenAddedAtIndexListener = new AutoCompleteTokenAddedAtIndexListener(this);
        this._android._tokenSelectedListener = new AutoCompleteTokenSelectedListener(this);
        this._android._tokenDeselectedListener = new AutoCompleteTokenDeselectedListener(this);
        this._android._tokenRemovedListener = new AutoCompleteTokenRemovedListener(this);
        this._android._didAutoCompleteTokenListener = new AutoCompleteDidAutoCompleteTokenListener(this);
        this._android.addShowSuggestionListListener(this._android._showSuggestionListener);
        this._android.addOnFocusChangeListener(this._android._onFocusChangeListener);
        this._android.addTextChangedListener(this._android._textChangedListener);
        this._android.addTokenAddedAtIndexListener(this._android._tokenAddedAtIndexListener);
        this._android.addTokenSelectedListener(this._android._tokenSelectedListener);
        this._android.addTokenDeselectedListener(this._android._tokenDeselectedListener);
        this._android.addTokenRemovedListener(this._android._tokenRemovedListener);
        this._android.addDidAutoCompleteTokenListener(this._android._didAutoCompleteTokenListener);
        this._ngKey = Object.keys(this).find(function (key) { return key.startsWith('_ngcontent'); });
        this._vueKey = Object.keys(this).find(function (key) { return key.startsWith('data-v'); });
        if (this.displayMode) {
            this.adjustDisplayMode(this.displayMode);
        }
        if (this.suggestMode) {
            this.adjustSuggestMode(this.suggestMode);
        }
        if (this.layoutMode) {
            this.adjustLayoutMode(this.layoutMode);
        }
        if (this.completionMode) {
            this.adjustCompletionMode(this.completionMode);
        }
        if (this.suggestionView) {
            this.adjustSuggestionView(this.suggestionView);
        }
        else {
            this.suggestionView = new SuggestionView();
        }
        if (this.hint) {
            this.adjustHint(this.hint);
        }
        if (this.text) {
            this.adjustText(this.text);
        }
        if (this.minimumCharactersToSearch) {
            this.adjustMinimumCharactersToSearch(this.minimumCharactersToSearch);
        }
        if (this.tokenItemSpacing) {
            this.adjustTokenItemSpacing(this.tokenItemSpacing);
        }
        if (this.noResultsText) {
            this.adjustNoResultsText(this.noResultsText);
        }
        if (this.closeButtonImageSrc) {
            this.adjustCloseButtonImage(this.closeButtonImageSrc);
        }
        this.adjustShowCloseButton(this.showCloseButton);
        if (this.readOnly !== undefined) {
            this.adjustIsReadOnly(this.readOnly);
        }
        if (this.asyncCall) {
            this.adjustAsyncCall(true);
        }
        else {
            this.loadData(false);
        }
        this._clearButton = new ClearButton(this._android);
        commonModule.setupCssScope(this, this._clearButton);
        this._addView(this._clearButton);
        this._noResultsLabel = new NoResultsLabel(this._android.noResultsLabel());
        commonModule.setupCssScope(this, this._noResultsLabel);
        this._addView(this._noResultsLabel);
        return this._nativeView;
    };
    RadAutoCompleteTextView.prototype.initNativeView = function () {
        _super.prototype.initNativeView.call(this);
        if (this._androidViewId < 0) {
            this._androidViewId = android.view.View.generateViewId();
        }
        this._nativeView.setId(this._androidViewId);
    };
    RadAutoCompleteTextView.prototype.disposeNativeView = function () {
        this._android.resetAutocomplete();
        if (this.clearButton) {
            this._removeView(this.clearButton);
        }
        if (this._android._showSuggestionListener) {
            this._android._showSuggestionListener.owner = null;
        }
        if (this._android._onFocusChangeListener) {
            this._android._onFocusChangeListener.owner = null;
        }
        if (this._android._textChangedListener) {
            this._android._textChangedListener.owner = null;
        }
        if (this._android._tokenAddedAtIndexListener) {
            this._android._tokenAddedAtIndexListener.owner = null;
        }
        if (this._android._tokenSelectedListener) {
            this._android._tokenSelectedListener.owner = null;
        }
        if (this._android._tokenDeselectedListener) {
            this._android._tokenDeselectedListener.owner = null;
        }
        if (this._android._tokenRemovedListener) {
            this._android._tokenRemovedListener.owner = null;
        }
        if (this._android._didAutoCompleteTokenListener) {
            this._android._didAutoCompleteTokenListener.owner = null;
        }
        _super.prototype.disposeNativeView.call(this);
    };
    Object.defineProperty(RadAutoCompleteTextView.prototype, "_nativeView", {
        get: function () {
            return this._android;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RadAutoCompleteTextView.prototype, "android", {
        get: function () {
            return this._android;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RadAutoCompleteTextView.prototype, "filteredItems", {
        get: function () {
            if (this._filteredItems === undefined) {
                this._filteredItems = new Array();
            }
            return this._filteredItems;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RadAutoCompleteTextView.prototype, "selectedTokens", {
        get: function () {
            return this._selectedTokens;
        },
        enumerable: false,
        configurable: true
    });
    RadAutoCompleteTextView.prototype.resetAutoComplete = function () {
        this._android.resetAutocomplete();
    };
    RadAutoCompleteTextView.prototype.addToken = function (token) {
        if (!token) {
            return;
        }
        this.filteredItems.push(token);
        this._android.addTokenView(token.android);
        if (this._android.getDisplayMode() === com.telerik.widget.autocomplete.DisplayMode.PLAIN) {
            // HACK: to unify behavior in iOS and Android
            this._android.setText(token.text);
        }
    };
    RadAutoCompleteTextView.prototype.insertTokenAtIndex = function (token, index) {
        if (!token) {
            return;
        }
        this.filteredItems.push(token);
        this._android.addTokenModelAt(token.android, index);
    };
    RadAutoCompleteTextView.prototype.removeToken = function (token) {
        if (!token) {
            return;
        }
        this._android.removeTokenModel(token.android);
    };
    RadAutoCompleteTextView.prototype.removeTokenAtIndex = function (index) {
        this._android.removeTokenAt(index);
    };
    RadAutoCompleteTextView.prototype.removeAllTokens = function () {
        this._android.removeAllTokens();
    };
    RadAutoCompleteTextView.prototype.tokens = function () {
        return this._android.getTokens();
    };
    RadAutoCompleteTextView.prototype.tokenAtIndex = function (index) {
        return this._android.getTokenAt(index);
    };
    RadAutoCompleteTextView.prototype.findSuggestions = function () {
        return this._android.findSuggestions();
    };
    RadAutoCompleteTextView.prototype.onDisplayModeChanged = function (oldValue, newValue) {
        this.adjustDisplayMode(newValue);
    };
    RadAutoCompleteTextView.prototype.onLayoutModeChanged = function (oldValue, newValue) {
        this.adjustLayoutMode(newValue);
    };
    RadAutoCompleteTextView.prototype.onSuggestModeChanged = function (oldValue, newValue) {
        this.adjustSuggestMode(newValue);
    };
    RadAutoCompleteTextView.prototype.onCompletionModeChanged = function (oldValue, newValue) {
        this.adjustCompletionMode(newValue);
    };
    RadAutoCompleteTextView.prototype.onItemsChanged = function (oldValue, newValue) {
        this.loadData(false);
    };
    RadAutoCompleteTextView.prototype.onSuggestionViewChanged = function (oldValue, newValue) {
        if (oldValue && oldValue.parent === this) {
            this._removeView(oldValue);
        }
        this.adjustSuggestionView(newValue);
    };
    RadAutoCompleteTextView.prototype.onHintChanged = function (oldValue, newValue) {
        this.adjustHint(newValue);
    };
    RadAutoCompleteTextView.prototype.onTextChanged = function (oldValue, newValue) {
        this.adjustText(newValue);
    };
    RadAutoCompleteTextView.prototype.onMinimumCharactersToSearchChanged = function (oldValue, newValue) {
        this.adjustMinimumCharactersToSearch(newValue);
    };
    RadAutoCompleteTextView.prototype.onTokenItemSpacingChanged = function (oldValue, newValue) {
        this.adjustTokenItemSpacing(newValue);
    };
    RadAutoCompleteTextView.prototype.onNoResultsTextChanged = function (oldValue, newValue) {
        this.adjustNoResultsText(newValue);
    };
    RadAutoCompleteTextView.prototype.onLoadSuggestionsAsyncChanged = function (oldValue, newValue) {
        this.asyncCall = newValue;
        this.adjustAsyncCall(true);
    };
    RadAutoCompleteTextView.prototype.onShowCloseButtonChanged = function (oldValue, newValue) {
        this.adjustShowCloseButton(newValue);
    };
    RadAutoCompleteTextView.prototype.onCloseButtonImageSrcChanged = function (oldValue, newValue) {
        this.adjustCloseButtonImage(newValue);
    };
    RadAutoCompleteTextView.prototype.onReadOnlyChanged = function (oldValue, newValue) {
        this.adjustIsReadOnly(newValue);
    };
    RadAutoCompleteTextView.prototype.adjustAsyncCall = function (value) {
        if (this._android && value) {
            this._android.setUsingAsyncData(value);
            this.loadData(true);
        }
    };
    RadAutoCompleteTextView.prototype.adjustHint = function (value) {
        if (this._android && value) {
            this._android.setAutocompleteHint(value);
        }
    };
    RadAutoCompleteTextView.prototype.adjustText = function (value) {
        if (this._android && this._android.getText().toString() !== value) {
            this._android.setText(value);
            var args = new commonModule.AutoCompleteEventData(this, commonModule.RadAutoCompleteTextView.textChangedEvent, value, undefined);
            this.notify(args);
        }
    };
    RadAutoCompleteTextView.prototype.adjustMinimumCharactersToSearch = function (value) {
        if (this._android && value) {
            this._android.setMinimumCharactersToSearch(value);
        }
    };
    RadAutoCompleteTextView.prototype.adjustTokenItemSpacing = function (value) {
        if (this._android && value) {
            var spacingInPixels = core_1.Utils.layout.toDevicePixels(value);
            this._android.setTokenItemSpacing(spacingInPixels);
        }
    };
    RadAutoCompleteTextView.prototype.adjustNoResultsText = function (value) {
        if (this._android && value) {
            this._android.setNoResultsText(value);
        }
    };
    RadAutoCompleteTextView.prototype.adjustSuggestionView = function (value) {
        if (this._android && value) {
            var suggestionView = value;
            suggestionView.owner = this;
            suggestionView.android = this._android.getSuggestionView();
            if (suggestionView.suggestionViewHeight) {
                var heightInPixels = core_1.Utils.layout.toDevicePixels(suggestionView.suggestionViewHeight);
                this._android.setSuggestionViewHeight(heightInPixels);
            }
            commonModule.setupCssScope(this, suggestionView);
            this._addView(suggestionView);
        }
    };
    RadAutoCompleteTextView.prototype.adjustCompletionMode = function (value) {
        if (this._android && value) {
            if (value === commonModule.AutoCompleteCompletionMode.Contains) {
                this._android.getAdapter().setCompletionMode(com.telerik.widget.autocomplete.CompletionMode.CONTAINS);
            }
            else {
                this._android.getAdapter().setCompletionMode(com.telerik.widget.autocomplete.CompletionMode.STARTS_WITH);
            }
        }
    };
    RadAutoCompleteTextView.prototype.adjustDisplayMode = function (value) {
        if (this._android && value) {
            this._android.setDisplayMode((value === commonModule.AutoCompleteDisplayMode.Plain) ?
                com.telerik.widget.autocomplete.DisplayMode.PLAIN :
                com.telerik.widget.autocomplete.DisplayMode.TOKENS);
        }
    };
    RadAutoCompleteTextView.prototype.adjustSuggestMode = function (value) {
        if (this._android && value) {
            if (value === commonModule.AutoCompleteSuggestMode.Suggest) {
                this._android.setSuggestMode(com.telerik.widget.autocomplete.SuggestMode.SUGGEST);
            }
            else if (value === commonModule.AutoCompleteSuggestMode.Append) {
                this._android.setSuggestMode(com.telerik.widget.autocomplete.SuggestMode.APPEND);
            }
            else {
                this._android.setSuggestMode(com.telerik.widget.autocomplete.SuggestMode.SUGGEST_APPEND);
            }
        }
    };
    RadAutoCompleteTextView.prototype.adjustLayoutMode = function (value) {
        if (value && this._android) {
            this._android.setTokensLayoutMode((value === commonModule.AutoCompleteLayoutMode.Horizontal) ?
                com.telerik.widget.autocomplete.LayoutMode.HORIZONTAL :
                com.telerik.widget.autocomplete.LayoutMode.WRAP);
        }
    };
    RadAutoCompleteTextView.prototype.adjustShowCloseButton = function (value) {
        if (this._android) {
            this._android.setShowCloseButton(value);
        }
    };
    RadAutoCompleteTextView.prototype.adjustCloseButtonImage = function (value) {
        if (this._android) {
            if (value !== null && value !== undefined) {
                var drawable = RadAutoCompleteTextView.resolveDrawableFromResource(value);
                if (drawable) {
                    this._android.getCloseButtonView().setBackgroundDrawable(drawable);
                }
            }
        }
    };
    RadAutoCompleteTextView.prototype.adjustIsReadOnly = function (value) {
        if (this._android) {
            this._android.setReadOnly(value);
        }
    };
    RadAutoCompleteTextView.prototype.loadData = function (isRemote) {
        if (this._nativeView !== undefined) {
            if ((this.items === undefined && isRemote === true) || this.items !== undefined) {
                var nativeSource = new java.util.ArrayList();
                if (this.items !== undefined) {
                    for (var i = 0; i < this.items.length; i++) {
                        var a = this.items.getItem(i);
                        nativeSource.add(a.android);
                    }
                }
                ensureAutoCompleteAdapter();
                var adapter = new AutoCompleteAdapterClass(this, nativeSource, isRemote);
                this._android.setAdapter(adapter);
                this.adjustCompletionMode(this.completionMode);
            }
        }
    };
    RadAutoCompleteTextView.resolveDrawableFromResource = function (imageName) {
        var nativeValue = imageName;
        var drawable;
        if (imageName.startsWith("res://")) {
            nativeValue = imageName.substring(6, imageName.length);
        }
        var appResources = core_1.Utils.android.getApplicationContext().getResources();
        var packageName = core_1.Utils.android.getApplication().getPackageName();
        if (appResources) {
            var identifier = appResources.getIdentifier(nativeValue, 'drawable', packageName);
            if (identifier > 0) {
                drawable = appResources.getDrawable(identifier);
            }
            else {
                console.log("WARNING: Can't find drawable with name: " + nativeValue);
            }
        }
        return drawable;
    };
    RadAutoCompleteTextView.prototype[core_1.colorProperty.getDefault] = function () {
        return this._android.getTextField().getCurrentTextColor();
    };
    RadAutoCompleteTextView.prototype[core_1.colorProperty.setNative] = function (value) {
        var nativeColor = value instanceof core_1.Color ? value.android : value;
        if (!nativeColor) {
            this._android.getTextField().setTextColor(android.graphics.Color.BLACK);
            this._android.setAppendTextColor(android.graphics.Color.GRAY);
        }
        else {
            this._android.getTextField().setTextColor(nativeColor);
            this._android.setAppendTextColor(androidColorWithAlpha(nativeColor, 0.5));
        }
    };
    RadAutoCompleteTextView.prototype[core_1.fontSizeProperty.getDefault] = function () {
        return this._android.getTextField().getTextSize();
    };
    RadAutoCompleteTextView.prototype[core_1.fontSizeProperty.setNative] = function (value) {
        if (!value) {
            this._android.getTextField().setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, 14);
        }
        if (typeof value === "number") {
            this._android.getTextField().setTextSize(value);
        }
        else {
            this._android.getTextField().setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
        }
    };
    RadAutoCompleteTextView.prototype[core_1.fontInternalProperty.getDefault] = function () {
        return this._android.getTextField().getTypeface();
    };
    RadAutoCompleteTextView.prototype[core_1.fontInternalProperty.setNative] = function (value) {
        this._android.getTextField().setTypeface(value instanceof core_1.Font ? value.getAndroidTypeface() : value);
    };
    RadAutoCompleteTextView.prototype[core_1.paddingLeftProperty.getDefault] = function () {
        return this._android.getTextField().getPaddingLeft();
    };
    // RadAutoCompleteTextView has default paddingBottom and its
    // EditText has default paddingTop and paddingBottom. When the
    // padding is changed through NativeScript, we reset any default values,
    // so the value that is set is the only padding that is applied.
    RadAutoCompleteTextView.prototype[core_1.paddingLeftProperty.setNative] = function (value) {
        var paddingLeft = core_1.Utils.layout.toDevicePixels(value) + this.effectiveBorderLeftWidth;
        this._android.setCustomPaddingLeft(paddingLeft);
        var textTop = this._android.getTextField().getPaddingTop();
        var textRight = this._android.getTextField().getPaddingRight();
        var textBottom = this._android.getTextField().getPaddingBottom();
        this._android.getTextField().setPadding(0, textTop, textRight, textBottom);
    };
    RadAutoCompleteTextView.prototype[core_1.borderLeftWidthProperty.getDefault] = function () {
        return 0;
    };
    RadAutoCompleteTextView.prototype[core_1.borderLeftWidthProperty.setNative] = function (value) {
        var paddingLeft = core_1.Utils.layout.toDevicePixels(value) + this.effectivePaddingLeft;
        this._android.setCustomPaddingLeft(paddingLeft);
    };
    RadAutoCompleteTextView.prototype[core_1.paddingTopProperty.getDefault] = function () {
        return this._android.getTextField().getPaddingTop();
    };
    RadAutoCompleteTextView.prototype[core_1.paddingTopProperty.setNative] = function (value) {
        var paddingTop = core_1.Utils.layout.toDevicePixels(value) + this.effectiveBorderTopWidth;
        this._android.setCustomPaddingTop(paddingTop);
        var textLeft = this._android.getTextField().getPaddingLeft();
        var textRight = this._android.getTextField().getPaddingRight();
        var textBottom = this._android.getTextField().getPaddingBottom();
        this._android.getTextField().setPadding(textLeft, 0, textRight, textBottom);
    };
    RadAutoCompleteTextView.prototype[core_1.borderTopWidthProperty.getDefault] = function () {
        return 0;
    };
    RadAutoCompleteTextView.prototype[core_1.borderTopWidthProperty.setNative] = function (value) {
        var paddingTop = core_1.Utils.layout.toDevicePixels(value) + this.effectivePaddingTop;
        this._android.setCustomPaddingTop(paddingTop);
    };
    RadAutoCompleteTextView.prototype[core_1.paddingRightProperty.getDefault] = function () {
        return this._android.getTextField().getPaddingRight();
    };
    RadAutoCompleteTextView.prototype[core_1.paddingRightProperty.setNative] = function (value) {
        var paddingRight = core_1.Utils.layout.toDevicePixels(value) + this.effectiveBorderRightWidth;
        this._android.setCustomPaddingRight(paddingRight);
        var textLeft = this._android.getTextField().getPaddingLeft();
        var textTop = this._android.getTextField().getPaddingTop();
        var textBottom = this._android.getTextField().getPaddingBottom();
        this._android.getTextField().setPadding(textLeft, textTop, 0, textBottom);
    };
    RadAutoCompleteTextView.prototype[core_1.borderRightWidthProperty.getDefault] = function () {
        return 0;
    };
    RadAutoCompleteTextView.prototype[core_1.borderRightWidthProperty.setNative] = function (value) {
        var paddingRight = core_1.Utils.layout.toDevicePixels(value) + this.effectivePaddingRight;
        this._android.setCustomPaddingRight(paddingRight);
    };
    RadAutoCompleteTextView.prototype[core_1.paddingBottomProperty.getDefault] = function () {
        return this._android.getPaddingBottom();
    };
    RadAutoCompleteTextView.prototype[core_1.paddingBottomProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = core_1.Utils.layout.toDevicePixels(value) + this.effectiveBorderBottomWidth;
        this._android.setPadding(paddingLeft, paddingTop, paddingRight, 0);
        this._android.setCustomPaddingBottom(paddingBottom);
        var textLeft = this._android.getTextField().getPaddingLeft();
        var textTop = this._android.getTextField().getPaddingTop();
        var textRight = this._android.getTextField().getPaddingRight();
        this._android.getTextField().setPadding(textLeft, textTop, textRight, 0);
    };
    RadAutoCompleteTextView.prototype[core_1.borderBottomWidthProperty.getDefault] = function () {
        return 0;
    };
    RadAutoCompleteTextView.prototype[core_1.borderBottomWidthProperty.setNative] = function (value) {
        var paddingBottom = core_1.Utils.layout.toDevicePixels(value) + this.effectivePaddingBottom;
        this._android.setCustomPaddingBottom(paddingBottom);
    };
    return RadAutoCompleteTextView;
}(commonModule.RadAutoCompleteTextView));
exports.RadAutoCompleteTextView = RadAutoCompleteTextView;
function androidColorWithAlpha(androidColor, alpha) {
    var colorRed = android.graphics.Color.red(androidColor);
    var colorGreen = android.graphics.Color.green(androidColor);
    var colorBlue = android.graphics.Color.blue(androidColor);
    return android.graphics.Color.argb(alpha * 256.0, colorRed, colorGreen, colorBlue);
}
var Token = /** @class */ (function (_super) {
    __extends(Token, _super);
    function Token(nativeView) {
        var _this = _super.call(this) || this;
        _this._android = nativeView;
        _this._clearButton = new TokenClearButton(_this._android);
        _this._addView(_this._clearButton);
        return _this;
    }
    Token.prototype.createNativeView = function () {
        return this._android;
    };
    Token.prototype.disposeNativeView = function () {
        if (this._clearButton) {
            this._removeView(this._clearButton);
        }
        this._android = null;
    };
    Object.defineProperty(Token.prototype, "clearButton", {
        get: function () {
            return this._clearButton;
        },
        enumerable: false,
        configurable: true
    });
    Token.prototype.eachChild = function (callback) {
        if (this.clearButton) {
            callback(this.clearButton);
        }
    };
    Token.prototype[core_1.colorProperty.getDefault] = function () {
        return this._android.textView().getCurrentTextColor();
    };
    Token.prototype[core_1.colorProperty.setNative] = function (value) {
        var nsColor = value instanceof core_1.Color ? value.android : value;
        if (nsColor) {
            this._android.textView().setTextColor(nsColor);
        }
        else {
            this._android.textView().setTextColor(android.graphics.Color.BLACK);
        }
    };
    Token.prototype[core_1.fontSizeProperty.getDefault] = function () {
        return this._android.textView().getTextSize();
    };
    Token.prototype[core_1.fontSizeProperty.setNative] = function (value) {
        if (!value) {
            this._android.textView().setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, 14);
        }
        if (typeof value === "number") {
            this._android.textView().setTextSize(value);
        }
        else {
            this._android.textView().setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
        }
    };
    Token.prototype[core_1.fontInternalProperty.getDefault] = function () {
        return this._android.textView().getTypeface();
    };
    Token.prototype[core_1.fontInternalProperty.setNative] = function (value) {
        this._android.textView().setTypeface(value instanceof core_1.Font ? value.getAndroidTypeface() : value);
    };
    Token.prototype[core_1.paddingLeftProperty.getDefault] = function () {
        return this._android.getPaddingLeft();
    };
    Token.prototype[core_1.paddingLeftProperty.setNative] = function (value) {
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(value, paddingTop, paddingRight, paddingBottom);
    };
    Token.prototype[core_1.paddingTopProperty.getDefault] = function () {
        return this._android.getPaddingTop();
    };
    Token.prototype[core_1.paddingTopProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, value, paddingRight, paddingBottom);
    };
    Token.prototype[core_1.paddingRightProperty.getDefault] = function () {
        return this._android.getPaddingRight();
    };
    Token.prototype[core_1.paddingRightProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, paddingTop, value, paddingBottom);
    };
    Token.prototype[core_1.paddingBottomProperty.getDefault] = function () {
        return this._android.getPaddingBottom();
    };
    Token.prototype[core_1.paddingBottomProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        this._android.setPadding(paddingLeft, paddingTop, paddingRight, value);
    };
    return Token;
}(commonModule.Token));
exports.Token = Token;
var NoResultsLabel = /** @class */ (function (_super) {
    __extends(NoResultsLabel, _super);
    function NoResultsLabel(nativeView) {
        var _this = _super.call(this) || this;
        _this._android = nativeView;
        return _this;
    }
    NoResultsLabel.prototype.createNativeView = function () {
        return this._android;
    };
    NoResultsLabel.prototype.disposeNativeView = function () {
        this._android = null;
    };
    NoResultsLabel.prototype[core_1.colorProperty.getDefault] = function () {
        return this._android.getCurrentTextColor();
    };
    NoResultsLabel.prototype[core_1.colorProperty.setNative] = function (value) {
        var nativeColor = value instanceof core_1.Color ? value.android : value;
        if (nativeColor) {
            this._android.setTextColor(nativeColor);
        }
        else {
            this._android.setTextColor(android.graphics.Color.BLACK);
        }
    };
    NoResultsLabel.prototype[core_1.fontSizeProperty.getDefault] = function () {
        return this._android.getTextSize();
    };
    NoResultsLabel.prototype[core_1.fontSizeProperty.setNative] = function (value) {
        if (!value) {
            this._android.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP, 14);
        }
        if (typeof value === "number") {
            this._android.setTextSize(value);
        }
        else {
            this._android.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, value.nativeSize);
        }
    };
    NoResultsLabel.prototype[core_1.fontInternalProperty.getDefault] = function () {
        return this._android.getTypeface();
    };
    NoResultsLabel.prototype[core_1.fontInternalProperty.setNative] = function (value) {
        this._android.setTypeface(value instanceof core_1.Font ? value.getAndroidTypeface() : value);
    };
    return NoResultsLabel;
}(commonModule.NoResultsLabel));
exports.NoResultsLabel = NoResultsLabel;
var ClearButton = /** @class */ (function (_super) {
    __extends(ClearButton, _super);
    function ClearButton(nativeView) {
        var _this = _super.call(this) || this;
        _this._owner = nativeView;
        _this._android = nativeView.getCloseButtonView();
        _this.resetStateListAnimator(_this._android);
        return _this;
    }
    ClearButton.prototype.resetStateListAnimator = function (view) {
        if (getSdkApiLevel() && getSdkApiLevel() < 21) {
            // Method was introduced with API21, so skip, if earlier.
            return;
        }
        view.setStateListAnimator(null);
    };
    ClearButton.prototype.createNativeView = function () {
        return this._android;
    };
    ClearButton.prototype.disposeNativeView = function () {
        this._android = null;
    };
    ClearButton.prototype[core_1.colorProperty.getDefault] = function () {
        return null;
    };
    ClearButton.prototype[core_1.colorProperty.setNative] = function (value) {
        var nativeColor = value instanceof core_1.Color ? value.android : value;
        if (nativeColor !== null) {
            var tintList = android.content.res.ColorStateList.valueOf(nativeColor);
            this._owner.makeCloseButtonWhite(true);
            androidx.core.view.ViewCompat.setBackgroundTintList(this._android, tintList);
        }
        else {
            this._owner.makeCloseButtonWhite(false);
            androidx.core.view.ViewCompat.setBackgroundTintList(this._android, null);
        }
    };
    ClearButton.prototype[core_1.widthProperty.getDefault] = function () {
        var widthInPixels = this._owner.getCloseButtonWidth();
        return core_1.Utils.layout.toDeviceIndependentPixels(widthInPixels);
    };
    ClearButton.prototype[core_1.widthProperty.setNative] = function (value) {
        var widthInPixels = core_1.Utils.layout.toDevicePixels(value);
        this._owner.setCloseButtonWidth(widthInPixels);
    };
    ClearButton.prototype[core_1.heightProperty.getDefault] = function () {
        var heightInPixels = this._owner.getCloseButtonHeight();
        return core_1.Utils.layout.toDeviceIndependentPixels(heightInPixels);
    };
    ClearButton.prototype[core_1.heightProperty.setNative] = function (value) {
        var heightInPixels = core_1.Utils.layout.toDevicePixels(value);
        this._owner.setCloseButtonHeight(heightInPixels);
    };
    ClearButton.prototype[core_1.paddingLeftProperty.getDefault] = function () {
        return this._android.getPaddingLeft();
    };
    ClearButton.prototype[core_1.paddingLeftProperty.setNative] = function (value) {
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(value, paddingTop, paddingRight, paddingBottom);
    };
    ClearButton.prototype[core_1.paddingTopProperty.getDefault] = function () {
        return this._android.getPaddingTop();
    };
    ClearButton.prototype[core_1.paddingTopProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, value, paddingRight, paddingBottom);
    };
    ClearButton.prototype[core_1.paddingRightProperty.getDefault] = function () {
        return this._android.getPaddingRight();
    };
    ClearButton.prototype[core_1.paddingRightProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, paddingTop, value, paddingBottom);
    };
    ClearButton.prototype[core_1.paddingBottomProperty.getDefault] = function () {
        return this._android.getPaddingBottom();
    };
    ClearButton.prototype[core_1.paddingBottomProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        this._android.setPadding(paddingLeft, paddingTop, paddingRight, value);
    };
    return ClearButton;
}(commonModule.ClearButton));
exports.ClearButton = ClearButton;
var TokenClearButton = /** @class */ (function (_super) {
    __extends(TokenClearButton, _super);
    function TokenClearButton(token) {
        var _this = _super.call(this) || this;
        _this._token = token;
        _this._android = token.deleteImage();
        return _this;
    }
    TokenClearButton.prototype.createNativeView = function () {
        return this._android;
    };
    TokenClearButton.prototype.disposeNativeView = function () {
        this._android = null;
    };
    TokenClearButton.prototype[core_1.colorProperty.getDefault] = function () {
        return null;
    };
    TokenClearButton.prototype[core_1.colorProperty.setNative] = function (value) {
        var nativeColor = value instanceof core_1.Color ? value.android : value;
        if (nativeColor !== null) {
            var tintList = android.content.res.ColorStateList.valueOf(nativeColor);
            this._token.makeDeleteImageWhite(true);
            androidx.core.widget.ImageViewCompat.setImageTintList(this._android, tintList);
        }
        else {
            this._token.makeDeleteImageWhite(false);
            androidx.core.widget.ImageViewCompat.setImageTintList(this._android, null);
        }
    };
    TokenClearButton.prototype[core_1.backgroundImageProperty.getDefault] = function () {
        return null;
    };
    TokenClearButton.prototype[core_1.backgroundImageProperty.setNative] = function (value) {
        this._token.setUseDefaultImage(value === null);
    };
    TokenClearButton.prototype[core_1.paddingLeftProperty.getDefault] = function () {
        return this._android.getPaddingLeft();
    };
    TokenClearButton.prototype[core_1.paddingLeftProperty.setNative] = function (value) {
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(value, paddingTop, paddingRight, paddingBottom);
    };
    TokenClearButton.prototype[core_1.paddingTopProperty.getDefault] = function () {
        return this._android.getPaddingTop();
    };
    TokenClearButton.prototype[core_1.paddingTopProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingRight = this._android.getPaddingRight();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, value, paddingRight, paddingBottom);
    };
    TokenClearButton.prototype[core_1.paddingRightProperty.getDefault] = function () {
        return this._android.getPaddingRight();
    };
    TokenClearButton.prototype[core_1.paddingRightProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingBottom = this._android.getPaddingBottom();
        this._android.setPadding(paddingLeft, paddingTop, value, paddingBottom);
    };
    TokenClearButton.prototype[core_1.paddingBottomProperty.getDefault] = function () {
        return this._android.getPaddingBottom();
    };
    TokenClearButton.prototype[core_1.paddingBottomProperty.setNative] = function (value) {
        var paddingLeft = this._android.getPaddingLeft();
        var paddingTop = this._android.getPaddingTop();
        var paddingRight = this._android.getPaddingRight();
        this._android.setPadding(paddingLeft, paddingTop, paddingRight, value);
    };
    return TokenClearButton;
}(commonModule.TokenClearButton));
exports.TokenClearButton = TokenClearButton;
