import { View, Property, CssProperty, ViewBase, booleanConverter, PseudoClassHandler, CSSType, Enums, Utils, Color, Style, Builder } from '@nativescript/core';
import { AutoCompleteDisplayMode } from 'nativescript-ui-autocomplete';
// Support custom templates
Builder.knownCollections
    .add('properties')
    .add('groups')
    .add('validators');
/*
 * Lists the possible commit modes.
 */
export var DataFormCommitMode;
(function (DataFormCommitMode) {
    DataFormCommitMode["Immediate"] = "Immediate";
    DataFormCommitMode["OnLostFocus"] = "OnLostFocus";
    DataFormCommitMode["Manual"] = "Manual";
})(DataFormCommitMode || (DataFormCommitMode = {}));
/*
 * Lists the possible validation modes.
 */
export var DataFormValidationMode;
(function (DataFormValidationMode) {
    DataFormValidationMode["Immediate"] = "Immediate";
    DataFormValidationMode["OnLostFocus"] = "OnLostFocus";
    DataFormValidationMode["Manual"] = "Manual";
})(DataFormValidationMode || (DataFormValidationMode = {}));
/*
 * Lists the possible data form label position modes.
 */
export var DataFormLabelPosition;
(function (DataFormLabelPosition) {
    DataFormLabelPosition["Left"] = "Left";
    DataFormLabelPosition["Top"] = "Top";
})(DataFormLabelPosition || (DataFormLabelPosition = {}));
/*
 * Lists the possible editors.
 */
export var DataFormEditorType;
(function (DataFormEditorType) {
    DataFormEditorType["Text"] = "Text";
    DataFormEditorType["MultilineText"] = "MultilineText";
    DataFormEditorType["Email"] = "Email";
    DataFormEditorType["Password"] = "Password";
    DataFormEditorType["Phone"] = "Phone";
    DataFormEditorType["Decimal"] = "Decimal";
    DataFormEditorType["Number"] = "Number";
    DataFormEditorType["Switch"] = "Switch";
    DataFormEditorType["Stepper"] = "Stepper";
    DataFormEditorType["Slider"] = "Slider";
    DataFormEditorType["SegmentedEditor"] = "SegmentedEditor";
    DataFormEditorType["DatePicker"] = "DatePicker";
    DataFormEditorType["TimePicker"] = "TimePicker";
    DataFormEditorType["Picker"] = "Picker";
    DataFormEditorType["List"] = "List";
    DataFormEditorType["AutoCompleteInline"] = "AutoCompleteInline";
    DataFormEditorType["Label"] = "Label";
})(DataFormEditorType || (DataFormEditorType = {}));
/**
 * Font styles
 */
export var DataFormFontStyle;
(function (DataFormFontStyle) {
    DataFormFontStyle["Normal"] = "Normal";
    DataFormFontStyle["Bold"] = "Bold";
    DataFormFontStyle["Italic"] = "Italic";
    DataFormFontStyle["BoldItalic"] = "BoldItalic";
})(DataFormFontStyle || (DataFormFontStyle = {}));
/**
 * A class that provides common arguments of {@link RadDataForm} events.
 */
export class DataFormEventData {
}
/**
 * A class that provides common arguments of {@link CustomPropertyEditor} events.
 */
export class DataFormCustomPropertyEditorEventData {
}
///////////////////////////////////////////////////////////////////////////////
let RadDataForm = class RadDataForm extends View {
    constructor() {
        super();
        this.on('bindingContextChange', this.bindingContextChanged, this);
    }
    eachChild(callback) {
        let properties = this.properties;
        if (properties) {
            properties.forEach((item, i) => {
                callback(item);
            });
        }
        const groups = this.groups;
        if (groups) {
            groups.forEach((group, i) => {
                properties = group && group.properties;
                if (properties) {
                    properties.forEach((item, i) => {
                        callback(item);
                    });
                }
            });
        }
    }
    disposeNativeView() {
        this.entityPropertyChangedHandler = undefined;
        this.groupPropertyChangedHandler = undefined;
        this.groupTitleStylePropertyChangedHandler = undefined;
        this.groupLayoutPropertyChangedHandler = undefined;
    }
    notifyValidated(propertyName, result) { }
    onIsReadOnlyPropertyChanged(oldValue, newValue) {
        this._onIsReadOnlyPropertyChanged(oldValue, newValue);
    }
    onValidationModePropertyChanged(oldValue, newValue) {
        this._onValidationModePropertyChanged(oldValue, newValue);
    }
    onCommitModePropertyChanged(oldValue, newValue) {
        this._onCommitModePropertyChanged(oldValue, newValue);
    }
    onSourcePropertyChanged(oldValue, newValue) {
        this._onSourcePropertyChanged(oldValue, newValue);
    }
    onMetadataPropertyChanged(oldValue, newValue) {
        this._onMetadataPropertyChanged(oldValue, newValue);
    }
    onGroupsPropertyChanged(oldValue, newValue) {
        this._onGroupsPropertyChanged(oldValue, newValue);
    }
    onPropertiesPropertyChanged(oldValue, newValue) {
        this._onPropertiesPropertyChanged(oldValue, newValue);
    }
    bindingContextChanged(data) {
        if (this.groups) {
            for (let i = 0; i < this.groups.length; i++) {
                this.groups[i].bindingContext = data.value;
                if (this.groups[i].properties) {
                    for (let j = 0; j < this.groups[i].properties.length; j++) {
                        let entityProperty = this.groups[i].properties[j];
                        entityProperty.bindingContext = data.value;
                    }
                }
            }
        }
        if (this.properties) {
            for (let i = 0; i < this.properties.length; i++) {
                let entityProperty = this.properties[i];
                entityProperty.bindingContext = data.value;
            }
        }
    }
    _attachEntityPropertyPropertyChangeListener(property) {
        property.off('indexChange', this.entityPropertyChangedHandler);
        property.off('hiddenChange', this.entityPropertyChangedHandler);
        property.off('editorChange', this.entityPropertyChangedHandler);
        property.off('readOnlyChange', this.entityPropertyChangedHandler);
        property.off('hintTextChange', this.entityPropertyChangedHandler);
        property.off('displayNameChange', this.entityPropertyChangedHandler);
        property.off('valuesProviderChange', this.entityPropertyChangedHandler);
        property.on('indexChange', this.entityPropertyChangedHandler);
        property.on('hiddenChange', this.entityPropertyChangedHandler);
        property.on('editorChange', this.entityPropertyChangedHandler);
        property.on('readOnlyChange', this.entityPropertyChangedHandler);
        property.on('hintTextChange', this.entityPropertyChangedHandler);
        property.on('displayNameChange', this.entityPropertyChangedHandler);
        property.on('valuesProviderChange', this.entityPropertyChangedHandler);
    }
    _attachGroupLayoutChangeListener(oldValue, newValue) {
        if (oldValue) {
            oldValue.off('orientationChange', this.groupLayoutPropertyChangedHandler);
        }
        if (newValue) {
            newValue.on('orientationChange', this.groupLayoutPropertyChangedHandler);
        }
    }
    _attachGroupTitleStyleChangeListener(oldValue, newValue) {
        if (oldValue) {
            oldValue.off('strokeColorChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('strokeWidthChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('fillColorChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('separatorColorChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('labelTextColorChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('labelTextSizeChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('labelFontNameChange', this.groupTitleStylePropertyChangedHandler);
            oldValue.off('labelFontStyleChange', this.groupTitleStylePropertyChangedHandler);
        }
        if (newValue) {
            newValue.on('strokeColorChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('strokeWidthChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('fillColorChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('separatorColorChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('labelTextColorChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('labelTextSizeChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('labelFontNameChange', this.groupTitleStylePropertyChangedHandler);
            newValue.on('labelFontStyleChange', this.groupTitleStylePropertyChangedHandler);
        }
    }
    _attachGroupChangeListener(group) {
        group.off('layoutChange', this.groupPropertyChangedHandler);
        group.off('titleStyleChange', this.groupPropertyChangedHandler);
        group.off('hiddenChange', this.groupPropertyChangedHandler);
        group.off('nameChange', this.groupPropertyChangedHandler);
        group.off('collapsibleChange', this.groupPropertyChangedHandler);
        group.off('collapsedChange', this.groupPropertyChangedHandler);
        group.off('titleHiddenChange', this.groupPropertyChangedHandler);
        group.on('layoutChange', this.groupPropertyChangedHandler);
        group.on('titleStyleChange', this.groupPropertyChangedHandler);
        group.on('hiddenChange', this.groupPropertyChangedHandler);
        group.on('nameChange', this.groupPropertyChangedHandler);
        group.on('collapsibleChange', this.groupPropertyChangedHandler);
        group.on('collapsedChange', this.groupPropertyChangedHandler);
        group.on('titleHiddenChange', this.groupPropertyChangedHandler);
        this._attachGroupLayoutChangeListener(undefined, group.layout);
        this._attachGroupTitleStyleChangeListener(undefined, group.titleStyle);
    }
    _onIsReadOnlyPropertyChanged(oldValue, newValue) { }
    _onCommitModePropertyChanged(oldValue, newValue) { }
    _onValidationModePropertyChanged(oldValue, newValue) { }
    _onSourcePropertyChanged(oldValue, newValue) { }
    _onMetadataPropertyChanged(oldValue, newValue) { }
    _onGroupsPropertyChanged(oldValue, newValue) { }
    _onPropertiesPropertyChanged(oldValue, newValue) { }
    get editedObject() {
        return undefined;
    }
    _addArrayFromBuilder(name, value) {
        if (name === 'groups') {
            this.groups = value;
        }
        if (name === 'properties') {
            this.properties = value;
        }
    }
    getPropertyByName(propertyName) {
        if (this.groups) {
            for (let i = 0; i < this.groups.length; i++) {
                if (this.groups[i].properties) {
                    for (let j = 0; j < this.groups[i].properties.length; j++) {
                        let entityProperty = this.groups[i].properties[j];
                        if (entityProperty.name === propertyName) {
                            return entityProperty;
                        }
                    }
                }
            }
        }
        if (this.properties) {
            for (let i = 0; i < this.properties.length; i++) {
                let entityProperty = this.properties[i];
                if (entityProperty.name === propertyName) {
                    return entityProperty;
                }
            }
        }
        return null;
    }
    getGroupByName(groupName) {
        if (this.groups) {
            for (let i = 0; i < this.groups.length; i++) {
                if (groupName === this.groups[i].name) {
                    return this.groups[i];
                }
            }
        }
        return null;
    }
    reload() { }
    validateAll() {
        return null;
    }
    validateAndCommitAll() {
        return null;
    }
    commitAll() { }
};
RadDataForm.editorSelectedEvent = 'editorSelected';
RadDataForm.editorDeselectedEvent = 'editorDeselected';
RadDataForm.propertyEditedEvent = 'propertyEdited';
RadDataForm.propertyValidateEvent = 'propertyValidate';
RadDataForm.propertyValidatedEvent = 'propertyValidated';
RadDataForm.editorSetupEvent = 'editorSetup';
RadDataForm.editorUpdateEvent = 'editorUpdate';
RadDataForm.groupUpdateEvent = 'groupUpdate';
RadDataForm.propertyCommitEvent = 'propertyCommit';
RadDataForm.propertyCommittedEvent = 'propertyCommitted';
RadDataForm.groupExpandedEvent = 'groupExpanded';
RadDataForm.groupCollapsedEvent = 'groupCollapsed';
RadDataForm.isReadOnlyProperty = new Property({
    name: 'isReadOnly',
    defaultValue: undefined,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onIsReadOnlyPropertyChanged(oldValue, newValue);
    }
});
RadDataForm.commitModeProperty = new Property({
    name: 'commitMode',
    defaultValue: DataFormCommitMode.Immediate,
    valueConverter: value => DataFormCommitMode[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onCommitModePropertyChanged(oldValue, newValue);
    }
});
RadDataForm.validationModeProperty = new Property({
    name: 'validationMode',
    defaultValue: DataFormValidationMode.Immediate,
    valueConverter: value => DataFormValidationMode[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onValidationModePropertyChanged(oldValue, newValue);
    }
});
RadDataForm.sourceProperty = new Property({
    name: 'source',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onSourcePropertyChanged(oldValue, newValue);
    }
});
RadDataForm.metadataProperty = new Property({
    name: 'metadata',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onMetadataPropertyChanged(oldValue, newValue);
    }
});
RadDataForm.groupsProperty = new Property({
    name: 'groups',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onGroupsPropertyChanged(oldValue, newValue);
    }
});
RadDataForm.propertiesProperty = new Property({
    name: 'properties',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onPropertiesPropertyChanged(oldValue, newValue);
    }
});
RadDataForm = __decorate([
    CSSType('RadDataForm'),
    __metadata("design:paramtypes", [])
], RadDataForm);
export { RadDataForm };
RadDataForm.isReadOnlyProperty.register(RadDataForm);
RadDataForm.commitModeProperty.register(RadDataForm);
RadDataForm.validationModeProperty.register(RadDataForm);
RadDataForm.sourceProperty.register(RadDataForm);
RadDataForm.metadataProperty.register(RadDataForm);
RadDataForm.groupsProperty.register(RadDataForm);
RadDataForm.propertiesProperty.register(RadDataForm);
///////////////////////////////////////////////////////////////////////////////
export class PropertyGroup extends ViewBase {
    _addArrayFromBuilder(name, value) {
        if (name === 'properties') {
            this.properties = value;
        }
    }
    onNamePropertyChanged(oldValue, newValue) {
        this.onNameChanged(oldValue, newValue);
    }
    onHiddenPropertyChanged(oldValue, newValue) {
        this.onHiddenChanged(oldValue, newValue);
    }
    onTitleHiddenPropertyChanged(oldValue, newValue) {
        this.onTitleHiddenChanged(oldValue, newValue);
    }
    onCollapsiblePropertyChanged(oldValue, newValue) {
        this.onCollapsibleChanged(oldValue, newValue);
    }
    onCollapsedPropertyChanged(oldValue, newValue) {
        this.onCollapsedChanged(oldValue, newValue);
    }
    onTitleStylePropertyChanged(oldValue, newValue) {
        this.onTitleStyleChanged(oldValue, newValue);
    }
    onPropertiesPropertyChanged(oldValue, newValue) {
        this.onPropertiesChanged(oldValue, newValue);
    }
    onLayoutPropertyChanged(oldValue, newValue) {
        this.onLayoutChanged(oldValue, newValue);
    }
    onNameChanged(oldValue, newValue) { }
    onHiddenChanged(oldValue, newValue) { }
    onTitleHiddenChanged(oldValue, newValue) { }
    onCollapsibleChanged(oldValue, newValue) { }
    onCollapsedChanged(oldValue, newValue) { }
    onTitleStyleChanged(oldValue, newValue) { }
    onPropertiesChanged(oldValue, newValue) { }
    onLayoutChanged(oldValue, newValue) { }
}
PropertyGroup.nameProperty = new Property({
    name: 'name',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onNamePropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.hiddenProperty = new Property({
    name: 'hidden',
    defaultValue: false,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onHiddenPropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.titleHiddenProperty = new Property({
    name: 'titleHidden',
    defaultValue: false,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onTitleHiddenPropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.collapsibleProperty = new Property({
    name: 'collapsible',
    defaultValue: false,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onCollapsiblePropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.collapsedProperty = new Property({
    name: 'collapsed',
    defaultValue: false,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onCollapsedPropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.titleStyleProperty = new Property({
    name: 'titleStyle',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onTitleStylePropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.propertiesProperty = new Property({
    name: 'properties',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onPropertiesPropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.layoutProperty = new Property({
    name: 'layout',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onLayoutPropertyChanged(oldValue, newValue);
    }
});
PropertyGroup.nameProperty.register(PropertyGroup);
PropertyGroup.hiddenProperty.register(PropertyGroup);
PropertyGroup.titleHiddenProperty.register(PropertyGroup);
PropertyGroup.collapsibleProperty.register(PropertyGroup);
PropertyGroup.collapsedProperty.register(PropertyGroup);
PropertyGroup.titleStyleProperty.register(PropertyGroup);
PropertyGroup.propertiesProperty.register(PropertyGroup);
PropertyGroup.layoutProperty.register(PropertyGroup);
///////////////////////////////////////////////////////////////////////////////
export class PropertyEditorParams extends ViewBase {
    onMinimumPropertyChanged(oldValue, newValue) {
        this.onMinimumChanged(oldValue, newValue);
    }
    onMaximumPropertyChanged(oldValue, newValue) {
        this.onMaximumChanged(oldValue, newValue);
    }
    onStepPropertyChanged(oldValue, newValue) {
        this.onStepChanged(oldValue, newValue);
    }
    onMinimumChanged(oldValue, newValue) { }
    onMaximumChanged(oldValue, newValue) { }
    onStepChanged(oldValue, newValue) { }
}
PropertyEditorParams.minimumProperty = new Property({
    name: 'minimum',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onMinimumPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorParams.maximumProperty = new Property({
    name: 'maximum',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onMaximumPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorParams.stepProperty = new Property({
    name: 'step',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onStepPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorParams.minimumProperty.register(PropertyEditorParams);
PropertyEditorParams.maximumProperty.register(PropertyEditorParams);
PropertyEditorParams.stepProperty.register(PropertyEditorParams);
///////////////////////////////////////////////////////////////////////////////
export class DataFormStyleBase extends ViewBase {
    onStrokeColorPropertyChanged(oldValue, newValue) {
        this.onStrokeColorChanged(oldValue, newValue);
    }
    onStrokeColorChanged(oldValue, newValue) { }
    onStrokeWidthPropertyChanged(oldValue, newValue) {
        this.onStrokeWidthChanged(oldValue, newValue);
    }
    onStrokeWidthChanged(oldValue, newValue) { }
    onFillColorPropertyChanged(oldValue, newValue) {
        this.onFillColorChanged(oldValue, newValue);
    }
    onFillColorChanged(oldValue, newValue) { }
    onSeparatorColorPropertyChanged(oldValue, newValue) {
        this.onSeparatorColorChanged(oldValue, newValue);
    }
    onSeparatorColorChanged(oldValue, newValue) { }
    onLabelTextColorPropertyChanged(oldValue, newValue) {
        this.onLabelTextColorChanged(oldValue, newValue);
    }
    onLabelTextColorChanged(oldValue, newValue) { }
    onLabelTextSizePropertyChanged(oldValue, newValue) {
        this.onLabelTextSizeChanged(oldValue, newValue);
    }
    onLabelTextSizeChanged(oldValue, newValue) { }
    onLabelFontNamePropertyChanged(oldValue, newValue) {
        this.onLabelFontNameChanged(oldValue, newValue);
    }
    onLabelFontNameChanged(oldValue, newValue) { }
    onLabelFontStylePropertyChanged(oldValue, newValue) {
        this.onLabelFontStyleChanged(oldValue, newValue);
    }
    onLabelFontStyleChanged(oldValue, newValue) { }
}
DataFormStyleBase.strokeColorProperty = new Property({
    name: 'strokeColor',
    defaultValue: undefined,
    equalityComparer: Color.equals,
    valueConverter: v => new Color(v),
    valueChanged: (target, oldValue, newValue) => {
        target.onStrokeColorPropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.strokeWidthProperty = new Property({
    name: 'strokeWidth',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onStrokeWidthPropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.fillColorProperty = new Property({
    name: 'fillColor',
    defaultValue: undefined,
    equalityComparer: Color.equals,
    valueConverter: v => new Color(v),
    valueChanged: (target, oldValue, newValue) => {
        target.onFillColorPropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.separatorColorProperty = new Property({
    name: 'separatorColor',
    defaultValue: undefined,
    equalityComparer: Color.equals,
    valueConverter: v => new Color(v),
    valueChanged: (target, oldValue, newValue) => {
        target.onSeparatorColorPropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.labelTextColorProperty = new Property({
    name: 'labelTextColor',
    defaultValue: undefined,
    equalityComparer: Color.equals,
    valueConverter: v => new Color(v),
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelTextColorPropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.labelTextSizeProperty = new Property({
    name: 'labelTextSize',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelTextSizePropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.labelFontNameProperty = new Property({
    name: 'labelFontName',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelFontNamePropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.labelFontStyleProperty = new Property({
    name: 'labelFontStyle',
    defaultValue: undefined,
    valueConverter: value => DataFormFontStyle[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelFontStylePropertyChanged(oldValue, newValue);
    }
});
DataFormStyleBase.strokeColorProperty.register(DataFormStyleBase);
DataFormStyleBase.strokeWidthProperty.register(DataFormStyleBase);
DataFormStyleBase.fillColorProperty.register(DataFormStyleBase);
DataFormStyleBase.separatorColorProperty.register(DataFormStyleBase);
DataFormStyleBase.labelTextColorProperty.register(DataFormStyleBase);
DataFormStyleBase.labelTextSizeProperty.register(DataFormStyleBase);
DataFormStyleBase.labelFontNameProperty.register(DataFormStyleBase);
DataFormStyleBase.labelFontStyleProperty.register(DataFormStyleBase);
// todo: add properties for separator Leading/Trailing Space , insets
export class GroupTitleStyle extends DataFormStyleBase {
}
// declare class TKDataFormEditorStyle extends NSObject {
// from base class:
// 	stroke: TKStroke;
// 	fill: TKFill;
// 	separatorColor: TKFill;
// implemented
// 	editorOffset: UIOffset;
// 	textLabelOffset: UIOffset;
// 	textLabelDisplayMode: TKDataFormEditorTextLabelDisplayMode;
// todo: add required properties
// 	accessoryArrowSize: CGSize; //ios specific
// 	accessoryArrowStroke: TKStroke; //ios specific
// 	feedbackImageViewOffset: UIOffset;
// 	feedbackLabelOffset: UIOffset;
// 	imageViewOffset: UIOffset; //add when image view is added as feature
// 	insets: UIEdgeInsets;
// 	separatorLeadingSpace: number; //iOS specific
// 	separatorTrailingSpace: number; //iOS specific
// }
export class PropertyEditorStyle extends DataFormStyleBase {
    onEditorHorizontalOffsetPropertyChanged(oldValue, newValue) {
        this.onEditorHorizontalOffsetChanged(oldValue, newValue);
    }
    onEditorHorizontalOffsetChanged(oldValue, newValue) { }
    onEditorVerticalOffsetPropertyChanged(oldValue, newValue) {
        this.onEditorVerticalOffsetChanged(oldValue, newValue);
    }
    onEditorVerticalOffsetChanged(oldValue, newValue) { }
    onLabelHorizontalOffsetPropertyChanged(oldValue, newValue) {
        this.onLabelHorizontalOffsetChanged(oldValue, newValue);
    }
    onLabelHorizontalOffsetChanged(oldValue, newValue) { }
    onLabelVerticalOffsetPropertyChanged(oldValue, newValue) {
        this.onLabelVerticalOffsetChanged(oldValue, newValue);
    }
    onLabelVerticalOffsetChanged(oldValue, newValue) { }
    onLabelHiddenPropertyChanged(oldValue, newValue) {
        this.onLabelHiddenChanged(oldValue, newValue);
    }
    onLabelHiddenChanged(oldValue, newValue) { }
    onLabelPositionPropertyChanged(oldValue, newValue) {
        this.onLabelPositionChanged(oldValue, newValue);
    }
    onLabelPositionChanged(oldValue, newValue) { }
    onLabelWidthPropertyChanged(oldValue, newValue) {
        this.onLabelWidthChanged(oldValue, newValue);
    }
    onLabelWidthChanged(oldValue, newValue) { }
}
PropertyEditorStyle.editorHorizontalOffsetProperty = new Property({
    name: 'editorHorizontalOffset',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onEditorHorizontalOffsetPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.editorVerticalOffsetProperty = new Property({
    name: 'editorVerticalOffset',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onEditorVerticalOffsetPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.labelHorizontalOffsetProperty = new Property({
    name: 'labelHorizontalOffset',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelHorizontalOffsetPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.labelVerticalOffsetProperty = new Property({
    name: 'labelVerticalOffset',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelVerticalOffsetPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.labelHiddenProperty = new Property({
    name: 'labelHidden',
    defaultValue: undefined,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelHiddenPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.labelPositionProperty = new Property({
    name: 'labelPosition',
    defaultValue: undefined,
    valueConverter: value => DataFormLabelPosition[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelPositionPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.labelWidthProperty = new Property({
    name: 'labelWidth',
    defaultValue: -1,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onLabelWidthPropertyChanged(oldValue, newValue);
    }
});
PropertyEditorStyle.editorHorizontalOffsetProperty.register(PropertyEditorStyle);
PropertyEditorStyle.editorVerticalOffsetProperty.register(PropertyEditorStyle);
PropertyEditorStyle.labelHorizontalOffsetProperty.register(PropertyEditorStyle);
PropertyEditorStyle.labelVerticalOffsetProperty.register(PropertyEditorStyle);
PropertyEditorStyle.labelHiddenProperty.register(PropertyEditorStyle);
PropertyEditorStyle.labelPositionProperty.register(PropertyEditorStyle);
PropertyEditorStyle.labelWidthProperty.register(PropertyEditorStyle);
////////////////////////////////////////////////////////////////////
// name : the name of bound entity property
// displayName  : the label to be shown for editor
// index : the index in group
// hidden : boolean for show/hide of editor
// readOnly : boolean , read only state
// required : boolean , if the value is required. Note: consider to move this to validator
// hintText : string, the gray text shown as hint in empty editor
// editor : PropertyEditor derived instance with specific properties for editors
// valuesProvider : an array or comma separated string with values used by some editors
// converter : PropertyConverter derived instance with specific properties for data conversion
// validator : PropertyValidator
///////////////////////////////////////////////////////////////////////////////
let EntityProperty = class EntityProperty extends View {
    constructor() {
        super(...arguments);
        this.namePropertySilentUpdate = false;
        this.errorMessage = 'This is not valid.';
    }
    get isValid() {
        return true;
    }
    get value() {
        return undefined;
    }
    get valueCandidate() {
        return undefined;
    }
    // @ts-ignore
    get android() {
        return undefined;
    }
    // @ts-ignore
    get ios() {
        return undefined;
    }
    onEditorPropertyChanged(oldValue, newValue) {
        if (oldValue) {
            oldValue.off('typeChange');
        }
        if (newValue) {
            const typeChangeFunction = function (propertyChangeData) {
                if (this) {
                    this.onEditorTypeChanged();
                }
            };
            newValue.on('typeChange', typeChangeFunction.bind(this));
        }
        this.onEditorChanged(oldValue, newValue);
    }
    eachChild(callback) {
        if (this.editor) {
            callback(this.editor);
        }
    }
    onEditorTypeChanged() {
        this.updateNativeEditor(this.editor);
    }
    onValidatorsPropertyChanged(oldValue, newValue) {
        this.onValidatorsChanged(oldValue, newValue);
    }
    onConverterPropertyChanged(oldValue, newValue) {
        this.onConverterChanged(oldValue, newValue);
    }
    onValuesProviderPropertyChanged(oldValue, newValue) {
        this.onValuesProviderChanged(oldValue, newValue);
    }
    onAutoCompleteDisplayModePropertyChanged(oldValue, newValue) {
        this.onAutoCompleteDisplayModeChanged(oldValue, newValue);
    }
    onNamePropertyChanged(oldValue, newValue) {
        if (this.namePropertySilentUpdate) {
            this.namePropertySilentUpdate = false;
            return;
        }
        if (oldValue == null) {
            this.onNameChanged(oldValue, newValue);
        }
        else {
            this.namePropertySilentUpdate = true;
            this.name = oldValue;
            console.log("Warring: EntityProperty's name is already set and can't be changed.");
        }
    }
    onDisplayNamePropertyChanged(oldValue, newValue) {
        this.onDisplayNameChanged(oldValue, newValue);
    }
    onIndexPropertyChanged(oldValue, newValue) {
        this.onIndexChanged(oldValue, newValue);
    }
    onColumnIndexPropertyChanged(oldValue, newValue) {
        this.onColumnIndexChanged(oldValue, newValue);
    }
    onHiddenPropertyChanged(oldValue, newValue) {
        this.onHiddenChanged(oldValue, newValue);
    }
    onReadOnlyPropertyChanged(oldValue, newValue) {
        this.onReadOnlyChanged(oldValue, newValue);
    }
    onRequiredPropertyChanged(oldValue, newValue) {
        this.onRequiredChanged(oldValue, newValue);
    }
    onHintTextPropertyChanged(oldValue, newValue) {
        this.onHintTextChanged(oldValue, newValue);
    }
    onImageResourcePropertyChanged(oldValue, newValue) {
        this.onImageResourceChanged(oldValue, newValue);
    }
    _addArrayFromBuilder(name, value) {
        if (name === 'validators') {
            this.validators = value;
        }
    }
    onEditorChanged(oldValue, newValue) {
        if (newValue instanceof PropertyEditor) {
            this.updateNativeEditor(newValue);
        }
    }
    onValidatorsChanged(oldValue, newValue) {
        if (newValue && newValue instanceof Array) {
            this.updateNativeValidators(newValue);
        }
    }
    onConverterChanged(oldValue, newValue) {
        if (newValue) {
            this.updateNativeConverter(newValue);
        }
    }
    onValuesProviderChanged(oldValue, newValue) {
        if (newValue) {
            let simplifiedArray;
            if (newValue instanceof Map) {
                simplifiedArray = Array.from(newValue.values());
                this._setupConverterWith(null, null, newValue);
            }
            else if (this._containsItemsArray(newValue)) {
                let keyProperty = this._getKeyProperty(this.valuesProvider);
                let labelProperty = this._getLabelProperty(this.valuesProvider);
                simplifiedArray = newValue.items.map(item => item[labelProperty]);
                this._setupConverterWith(keyProperty, labelProperty, newValue.items);
            }
            else if (this._isKeyLabelsArray(newValue)) {
                simplifiedArray = newValue.map(item => item['label']);
                this._setupConverterWith('key', 'label', newValue);
            }
            else if (typeof newValue === 'string') {
                simplifiedArray = newValue.split(',');
            }
            else {
                simplifiedArray = newValue;
            }
            this.valuesProviderArray = simplifiedArray;
            this.updateNativeValuesProvider(simplifiedArray);
        }
    }
    _setupConverterWith(key, label, items) {
        let converter;
        if (items instanceof Map) {
            converter = new ValuesProviderMapConverter(items);
        }
        else {
            converter = new ValuesProviderArrayConverter(key, label, items);
        }
        this.converter = converter;
    }
    _containsItemsArray(value) {
        if (value.hasOwnProperty('items')) {
            if (value['items'] instanceof Array) {
                return true;
            }
        }
        return false;
    }
    _isKeyLabelsArray(value) {
        if (value instanceof Array) {
            if (value.length > 0) {
                let item = value[0];
                if (item.hasOwnProperty('key') && item.hasOwnProperty('label')) {
                    return true;
                }
            }
        }
        return false;
    }
    _getKeyProperty(value) {
        if (value.hasOwnProperty('key')) {
            return value['key'];
        }
        if (value.hasOwnProperty('keyProperty')) {
            return value['keyProperty'];
        }
        return 'key';
    }
    _getLabelProperty(value) {
        if (value.hasOwnProperty('label')) {
            return value['label'];
        }
        if (value.hasOwnProperty('labelProperty')) {
            return value['labelProperty'];
        }
        return 'label';
    }
    onAutoCompleteDisplayModeChanged(oldValue, newValue) {
        if (newValue) {
            this.updateNativeAutoCompleteDisplayMode(newValue);
        }
    }
    onNameChanged(oldValue, newValue) { }
    onDisplayNameChanged(oldValue, newValue) {
        if (newValue) {
            this.updateNativeDisplayName(newValue);
        }
    }
    onIndexChanged(oldValue, newValue) {
        if (!isNaN(newValue)) {
            this.updateNativeIndex(newValue);
        }
    }
    onColumnIndexChanged(oldValue, newValue) {
        if (!isNaN(newValue)) {
            this.updateNativeColumnIndex(newValue);
        }
    }
    onHiddenChanged(oldValue, newValue) {
        this.updateNativeHidden(newValue);
    }
    onReadOnlyChanged(oldValue, newValue) {
        this.updateNativeReadOnly(newValue);
    }
    onRequiredChanged(oldValue, newValue) {
        this.updateNativeRequired(newValue);
    }
    onHintTextChanged(oldValue, newValue) {
        this.updateNativeHintText(newValue);
    }
    onImageResourceChanged(oldValue, newValue) {
        if (this.imageResource != null) {
            if (this.imageResource.indexOf(Utils.RESOURCE_PREFIX) === 0) {
                this.imageResource = this.imageResource.substr(Utils.RESOURCE_PREFIX.length);
                return;
            }
        }
        this.updateNativeImageResource(this.imageResource);
    }
    updateNativeEditor(value) { }
    updateNativeValidators(value) { }
    updateNativeConverter(value) { }
    updateNativeValuesProvider(value) { }
    updateNativeAutoCompleteDisplayMode(value) { }
    updateNativeDisplayName(value) { }
    updateNativeIndex(value) { }
    updateNativeColumnIndex(value) { }
    updateNativeHidden(value) { }
    updateNativeReadOnly(value) { }
    updateNativeRequired(value) { }
    updateNativeHintText(value) { }
    updateNativeImageResource(value) { }
};
EntityProperty.editorProperty = new Property({
    name: 'editor',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onEditorPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.validatorsProperty = new Property({
    name: 'validators',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onValidatorsPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.converterProperty = new Property({
    name: 'converter',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onConverterPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.valuesProviderProperty = new Property({
    name: 'valuesProvider',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onValuesProviderPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.autoCompleteDisplayModeProperty = new Property({
    name: 'autoCompleteDisplayMode',
    defaultValue: undefined,
    valueConverter: value => AutoCompleteDisplayMode[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onAutoCompleteDisplayModePropertyChanged(oldValue, newValue);
    }
});
EntityProperty.nameProperty = new Property({
    name: 'name',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onNamePropertyChanged(oldValue, newValue);
    }
});
EntityProperty.displayNameProperty = new Property({
    name: 'displayName',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onDisplayNamePropertyChanged(oldValue, newValue);
    }
});
EntityProperty.indexProperty = new Property({
    name: 'index',
    defaultValue: undefined,
    valueConverter: parseInt,
    valueChanged: (target, oldValue, newValue) => {
        target.onIndexPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.columnIndexProperty = new Property({
    name: 'columnIndex',
    defaultValue: undefined,
    valueConverter: parseInt,
    valueChanged: (target, oldValue, newValue) => {
        target.onColumnIndexPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.hiddenProperty = new Property({
    name: 'hidden',
    defaultValue: undefined,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onHiddenPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.readOnlyProperty = new Property({
    name: 'readOnly',
    defaultValue: undefined,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onReadOnlyPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.requiredProperty = new Property({
    name: 'required',
    defaultValue: undefined,
    valueConverter: booleanConverter,
    valueChanged: (target, oldValue, newValue) => {
        target.onRequiredPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.hintTextProperty = new Property({
    name: 'hintText',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onHintTextPropertyChanged(oldValue, newValue);
    }
});
EntityProperty.imageResourceProperty = new Property({
    name: 'imageResource',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onImageResourcePropertyChanged(oldValue, newValue);
    }
});
EntityProperty = __decorate([
    CSSType('EntityProperty')
], EntityProperty);
export { EntityProperty };
EntityProperty.editorProperty.register(EntityProperty);
EntityProperty.validatorsProperty.register(EntityProperty);
EntityProperty.converterProperty.register(EntityProperty);
EntityProperty.valuesProviderProperty.register(EntityProperty);
EntityProperty.autoCompleteDisplayModeProperty.register(EntityProperty);
EntityProperty.nameProperty.register(EntityProperty);
EntityProperty.displayNameProperty.register(EntityProperty);
EntityProperty.indexProperty.register(EntityProperty);
EntityProperty.columnIndexProperty.register(EntityProperty);
EntityProperty.hiddenProperty.register(EntityProperty);
EntityProperty.readOnlyProperty.register(EntityProperty);
EntityProperty.requiredProperty.register(EntityProperty);
EntityProperty.hintTextProperty.register(EntityProperty);
EntityProperty.imageResourceProperty.register(EntityProperty);
let DataFormEditorLabel = class DataFormEditorLabel extends View {
    // @ts-ignore
    get android() {
        return undefined;
    }
    // @ts-ignore
    get ios() {
        return undefined;
    }
};
DataFormEditorLabel = __decorate([
    CSSType('DataFormEditorLabel')
], DataFormEditorLabel);
export { DataFormEditorLabel };
let DataFormEditorCore = class DataFormEditorCore extends View {
    // @ts-ignore
    get android() {
        return undefined;
    }
    // @ts-ignore
    get ios() {
        return undefined;
    }
};
DataFormEditorCore = __decorate([
    CSSType('DataFormEditorCore')
], DataFormEditorCore);
export { DataFormEditorCore };
//////////////////////////////////////////////////////
// type : tye type of the editor to be used for this property
// style : EditorStyle instance
// todo: extend with common editor properties
let PropertyEditor = class PropertyEditor extends View {
    constructor() {
        super(...arguments);
        this._propertyEditorFocusHandler = () => this._goToVisualState('focus');
        this._propertyEditorBlurHandler = () => this._goToVisualState('blur');
    }
    get editorCore() {
        return undefined;
    }
    get label() {
        return undefined;
    }
    // @ts-ignore
    get android() {
        return undefined;
    }
    // @ts-ignore
    get ios() {
        return undefined;
    }
    eachChild(callback) {
        if (this.label && this.editorCore) {
            callback(this.label);
            callback(this.editorCore);
        }
    }
    onTypePropertyChanged(oldValue, newValue) {
        this.onTypeChanged(oldValue, newValue);
    }
    onPropertyEditorStylePropertyChanged(oldValue, newValue) {
        if (oldValue) {
            oldValue.off('editorHorizontalOffsetChange');
            oldValue.off('editorVerticalOffsetChange');
            oldValue.off('labelHorizontalOffsetChange');
            oldValue.off('labelVerticalOffsetChange');
            oldValue.off('labelHiddenChange');
            oldValue.off('labelPositionChange');
            oldValue.off('labelWidthChange');
            oldValue.off('strokeColorChange');
            oldValue.off('strokeWidthChange');
            oldValue.off('fillColorChange');
            oldValue.off('separatorColorChange');
            oldValue.off('labelTextColorChange');
            oldValue.off('labelTextSizeChange');
            oldValue.off('labelFontNameChange');
            oldValue.off('labelFontStyleChange');
        }
        if (newValue) {
            const changeHandler = function (propertyChangeData) {
                if (this) {
                    this.onStylePropertyChanged(propertyChangeData.propertyName);
                }
            }.bind(this);
            newValue.on('editorHorizontalOffsetChange', changeHandler);
            newValue.on('editorVerticalOffsetChange', changeHandler);
            newValue.on('labelHorizontalOffsetChange', changeHandler);
            newValue.on('labelVerticalOffsetChange', changeHandler);
            newValue.on('labelHiddenChange', changeHandler);
            newValue.on('labelPositionChange', changeHandler);
            newValue.on('labelWidthChange', changeHandler);
            newValue.on('strokeColorChange', changeHandler);
            newValue.on('strokeWidthChange', changeHandler);
            newValue.on('fillColorChange', changeHandler);
            newValue.on('separatorColorChange', changeHandler);
            newValue.on('labelTextColorChange', changeHandler);
            newValue.on('labelTextSizeChange', changeHandler);
            newValue.on('labelFontNameChange', changeHandler);
            newValue.on('labelFontStyleChange', changeHandler);
        }
        this.onPropertyEditorStyleChanged(oldValue, newValue);
    }
    onParamsPropertyInternalChanged(oldValue, newValue) {
        if (oldValue) {
            oldValue.off('minimumChange');
            oldValue.off('maximumChange');
            oldValue.off('stepChange');
        }
        if (newValue) {
            let changeHandler = function (propertyChangeData) {
                if (this) {
                    this.onParamsPropertyChanged(propertyChangeData.propertyName);
                }
            }.bind(this);
            newValue.on('minimumChange', changeHandler);
            newValue.on('maximumChange', changeHandler);
            newValue.on('stepChange', changeHandler);
        }
        this.onParamsChanged(oldValue, newValue);
    }
    onStylePropertyChanged(propertyName) { }
    onParamsPropertyChanged(propertyName) { }
    onTypeChanged(oldValue, newValue) { }
    onPropertyEditorStyleChanged(oldValue, newValue) { }
    onParamsChanged(oldValue, newValue) { }
    _updatePropertyEditorFocusBlurHandlers(subscribe) {
        const method = subscribe ? 'on' : 'off';
        this[method]('focus', this._propertyEditorFocusHandler);
        this[method]('blur', this._propertyEditorBlurHandler);
    }
};
PropertyEditor.typeProperty = new Property({
    name: 'type',
    defaultValue: undefined,
    valueConverter: value => DataFormEditorType[value],
    valueChanged: (target, oldValue, newValue) => {
        target.onTypePropertyChanged(oldValue, newValue);
    }
});
PropertyEditor.propertyEditorStyleProperty = new Property({
    name: 'propertyEditorStyle',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onPropertyEditorStylePropertyChanged(oldValue, newValue);
    }
});
PropertyEditor.paramsProperty = new Property({
    name: 'params',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onParamsPropertyInternalChanged(oldValue, newValue);
    }
});
PropertyEditor.positionProperty = new CssProperty({ name: 'position', cssName: 'position' });
PropertyEditor.separatorColorProperty = new CssProperty({ name: 'separatorColor', cssName: 'separator-color' });
__decorate([
    PseudoClassHandler('focus', 'blur'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean]),
    __metadata("design:returntype", void 0)
], PropertyEditor.prototype, "_updatePropertyEditorFocusBlurHandlers", null);
PropertyEditor = __decorate([
    CSSType('PropertyEditor')
], PropertyEditor);
export { PropertyEditor };
PropertyEditor.typeProperty.register(PropertyEditor);
PropertyEditor.propertyEditorStyleProperty.register(PropertyEditor);
PropertyEditor.paramsProperty.register(PropertyEditor);
PropertyEditor.positionProperty.register(Style);
PropertyEditor.separatorColorProperty.register(Style);
export class CustomPropertyEditor extends PropertyEditor {
    get android() {
        return undefined;
    }
    get ios() {
        return undefined;
    }
    notifyValueChanged() { }
}
CustomPropertyEditor.editorNeedsViewEvent = 'editorNeedsView';
CustomPropertyEditor.editorHasToApplyValueEvent = 'editorHasToApplyValue';
CustomPropertyEditor.editorNeedsValueEvent = 'editorNeedsValue';
//////////////////////////////////////////////////////
// errorMessage : message on error
// successMessage : message on success
export class PropertyValidator extends ViewBase {
    // @ts-ignore
    get android() {
        return undefined;
    }
    // @ts-ignore
    get ios() {
        return undefined;
    }
    onErrorMessagePropertyChanged(oldValue, newValue) {
        this.onErrorMessageChanged(oldValue, newValue);
    }
    onSuccessMessagePropertyChanged(oldValue, newValue) {
        this.onSuccessMessageChanged(oldValue, newValue);
    }
    onErrorMessageChanged(oldValue, newValue) {
        if (newValue) {
            // note: not wise but don't want to overwrite this method in all subclasses
            if (this.ios) {
                this.ios.errorMessage = newValue;
            }
            else {
                this.android.setNegativeMessage(newValue);
            }
        }
    }
    onSuccessMessageChanged(oldValue, newValue) {
        if (newValue) {
            // note: not wise but don't want to overwrite this method in all subclasses
            if (this.ios) {
                this.ios.positiveMessage = newValue;
            }
            else {
                this.android.setPositiveMessage(newValue);
            }
        }
    }
    validate(value, propertyName) {
        return true;
    }
}
PropertyValidator.errorMessageProperty = new Property({
    name: 'errorMessage',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onErrorMessagePropertyChanged(oldValue, newValue);
    }
});
PropertyValidator.successMessageProperty = new Property({
    name: 'successMessage',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onSuccessMessagePropertyChanged(oldValue, newValue);
    }
});
PropertyValidator.errorMessageProperty.register(PropertyValidator);
PropertyValidator.successMessageProperty.register(PropertyValidator);
export class LengthValidator extends PropertyValidator {
    onLengthPropertyChanged(oldValue, newValue) {
        this.onLengthChanged(oldValue, newValue);
    }
    onLengthChanged(oldValue, newValue) {
        console.log('Minimum/maximum setter in parent');
    }
}
LengthValidator.lengthProperty = new Property({
    name: 'length',
    defaultValue: undefined,
    valueConverter: parseInt,
    valueChanged: (target, oldValue, newValue) => {
        target.onLengthPropertyChanged(oldValue, newValue);
    }
});
LengthValidator.lengthProperty.register(LengthValidator);
export class MinimumLengthValidator extends LengthValidator {
}
export class MaximumLengthValidator extends LengthValidator {
}
export class EmailValidator extends PropertyValidator {
}
export class NonEmptyValidator extends PropertyValidator {
}
export class RangeValidator extends PropertyValidator {
    onMinimumPropertyChanged(oldValue, newValue) {
        this.onMinimumChanged(oldValue, newValue);
    }
    onMaximumPropertyChanged(oldValue, newValue) {
        this.onMaximumChanged(oldValue, newValue);
    }
    onMinimumChanged(oldValue, newValue) { }
    onMaximumChanged(oldValue, newValue) { }
}
RangeValidator.minimumProperty = new Property({
    name: 'minimum',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onMinimumPropertyChanged(oldValue, newValue);
    }
});
RangeValidator.maximumProperty = new Property({
    name: 'maximum',
    defaultValue: undefined,
    valueConverter: parseFloat,
    valueChanged: (target, oldValue, newValue) => {
        target.onMaximumPropertyChanged(oldValue, newValue);
    }
});
RangeValidator.minimumProperty.register(RangeValidator);
RangeValidator.maximumProperty.register(RangeValidator);
export class PhoneValidator extends PropertyValidator {
}
export class RegExValidator extends PropertyValidator {
    onRegExPropertyChanged(oldValue, newValue) {
        this.onRegExChanged(oldValue, newValue);
    }
    onRegExChanged(oldValue, newValue) { }
}
RegExValidator.regExProperty = new Property({
    name: 'regEx',
    defaultValue: undefined,
    valueChanged: (target, oldValue, newValue) => {
        target.onRegExPropertyChanged(oldValue, newValue);
    }
});
RegExValidator.regExProperty.register(RegExValidator);
export class IsTrueValidator extends PropertyValidator {
}
export class StringToDateConverter {
    convertFrom(value) { }
    convertTo(value) { }
}
export class StringToTimeConverter {
    convertFrom(value) { }
    convertTo(value) { }
}
export class ValuesProviderArrayConverter {
    constructor(key, label, items) {
        this._key = key;
        this._label = label;
        this._items = items;
    }
    convertFrom(source) {
        let key = this._key;
        let label = this._label;
        let returnValue = undefined;
        this._items.forEach(function (item) {
            if (item[key] === source) {
                returnValue = item[label];
            }
        });
        return returnValue;
    }
    convertTo(source) {
        let key = this._key;
        let label = this._label;
        let returnValue = -1;
        this._items.forEach(function (item) {
            if (item[label] === source) {
                returnValue = item[key];
            }
        });
        return returnValue;
    }
}
export class ValuesProviderMapConverter {
    constructor(items) {
        this._items = items;
    }
    convertFrom(source) {
        let returnValue = undefined;
        this._items.forEach(function (value, key) {
            if (key === source) {
                returnValue = value;
            }
        });
        return returnValue;
    }
    convertTo(source) {
        let returnValue = -1;
        this._items.forEach(function (value, key) {
            if (value === source) {
                returnValue = key;
            }
        });
        return returnValue;
    }
}
///////////////////////////////////////////////////////////////////////////////
export class DataFormLayout extends ViewBase {
}
export class DataFormStackLayout extends DataFormLayout {
    onOrientationPropertyChanged(oldValue, newValue) {
        this.onOrientationChanged(oldValue, newValue);
    }
    onOrientationChanged(oldValue, newValue) { }
}
DataFormStackLayout.orientationProperty = new Property({
    name: 'orientation',
    defaultValue: Enums.Orientation.vertical,
    valueChanged: (target, oldValue, newValue) => {
        target.onOrientationPropertyChanged(oldValue, newValue);
    }
});
export class DataFormGridLayout extends DataFormLayout {
}
//# sourceMappingURL=common.js.map