var NESTED_ATTR_PATH_CAPTURED_REGEX = /([a-z]+)(?:\[(\d+)])?\.?/g;
var NESTED_ATTR_PATH_REGEX = /^.+((\[(\d+)])|(\.)).*$/;
export function resolveAttributeNames(attributePath, propertyMetadata) {
    var placeholder;
    // tslint:disable-next-line:no-shadowed-variable
    var attributeNames = {};
    if (NESTED_ATTR_PATH_REGEX.test(attributePath)) {
        // nested attribute with document path (map or list)
        var re = void 0;
        var namePlaceholders = [];
        // tslint:disable-next-line:no-conditional-assignment
        while ((re = NESTED_ATTR_PATH_CAPTURED_REGEX.exec(attributePath)) !== null) {
            // path part is pos 1 - full match would be 0
            var pathPart = re[1];
            var collectionIndex = re[2];
            var pathPartDb 
            // get propertyMetdata of nested attribute if available
            = void 0;
            // get propertyMetdata of nested attribute if available
            if (propertyMetadata) {
                pathPartDb = propertyMetadata.nameDb;
            }
            else {
                pathPartDb = pathPart;
            }
            attributeNames["#" + pathPartDb] = pathPart;
            if (collectionIndex !== undefined) {
                namePlaceholders.push("#" + pathPartDb + "[" + collectionIndex + "]");
            }
            else {
                namePlaceholders.push("#" + pathPartDb);
            }
        }
        placeholder = namePlaceholders.join('.');
    }
    else {
        // top level attribute
        var attrPathDb = void 0;
        if (propertyMetadata) {
            attrPathDb = propertyMetadata.nameDb;
        }
        else {
            attrPathDb = attributePath;
        }
        attributeNames["#" + attributePath] = attrPathDb;
        placeholder = "#" + attributePath;
    }
    return {
        placeholder: placeholder,
        attributeNames: attributeNames,
    };
}
//# sourceMappingURL=attribute-names.function.js.map